Create connection to the server:
>>> import tarantool
>>> server = tarantool.connect("localhost", 33013)
Instance of Space is a named object to access the key space.
Create `` demo `` object which will be used to access the space `` 0 ``:
>>> demo = server.space(0)
All subsequent operations with space 0 performed using methods of the demo.
Select one single record with id 'AAAA' from the space demo using primary key (index zero):
>>> demo.select('AAAA')
Select several records using primary index:
>>> demo.select(['AAAA', 'BBBB', 'CCCC'])
[('AAAA', 'Alpha'), ('BBBB', 'Bravo'), ('CCCC', 'Charlie')]
Insert tuple ('DDDD', 'Delta') into the space demo:
>>> demo.insert(('DDDD', 'Delta'))
The first element is the primary key for the tuple.
Update the record with id 'DDDD' placing the value 'Denver' into the field 1:
>>> demo.update('DDDD', [(1, '=', 'Denver')], return_tuple=True)
[('DDDD', 'Denver')]
To find the record update() always uses the primary index. Fields numbers are starting from zero. So field 0 is the first element in the tuple. Argument return_tuple = True indicates that Tarantool should return the modified tuple.
To call stored function method Connection.call() can be used:
>>> server.call("box.select_range", (0, 0, 2, 'AAAA'))
[('AAAA', 'Alpha'), ('BBBB', 'Bravo')]
The same can be done using Space.call() method:
>>> demo = server.space(0)
>>> demo.call("box.select_range", (0, 0, 2, 'AAAA'))
[('AAAA', 'Alpha'), ('BBBB', 'Bravo')]
Method Space.call() is just an alias for Connection.call()