Python
tarantool-python is the official Python connector for Tarantool. It is not supplied as part of the Tarantool repository and must be installed separately (see below for details).
Here is a complete Python program that inserts [99999,'Value','Value']
into
space examples
via the high-level Python API.
#!/usr/bin/python
from tarantool import Connection
c = Connection("127.0.0.1", 3301)
result = c.insert("examples",(99999,'Value', 'Value'))
print result
To prepare, paste the code into a file named example.py
and install
the tarantool-python
connector with either pip install tarantool>0.4
to install in /usr
(requires root privilege) or
pip install tarantool>0.4 --user
to install in ~
i.e. user’s
default directory.
Before trying to run, check that the server instance is listening at
localhost:3301
and that the space examples
exists, as
described earlier.
To run the program, say python example.py
. The program will connect
to the Tarantool server, will send the INSERT request, and will not throw any exception if
all went well. If the tuple already exists, the program will throw
tarantool.error.DatabaseError: (3, "Duplicate key exists in unique index 'primary' in space 'examples'")
.
The example program only shows one request and does not show all that’s necessary for good practice. For that, please see tarantool-python project at GitHub.
Also there are several community-driven Python connectors:
- asynctnt with asyncio support
- aiotarantool also with asyncio support, no active maintenance
- gtarantool with gevent support, no active maintenance
The table below contains a feature comparison for asynctnt and tarantool-python. aiotarantool and gtarantool are absent there because they are quite outdated and unmaintained.
Last update: September 2023
Parameter | igorcoding/asynctnt | tarantool/tarantool-python |
---|---|---|
License | Apache License 2.0 | BSD-2 |
Is maintained | Yes | Yes |
Known Issues | None | None |
Documentation | Yes (github.io) | Yes (readthedocs and tarantool.io) |
Testing / CI / CD | GitHub Actions | GitHub Actions |
GitHub Stars | 73 | 92 |
Static Analysis | Yes (Flake8) | Yes (Flake8, Pylint) |
Packaging | pip | pip, deb, rpm |
Code coverage | Yes | Yes |
Support asynchronous mode | Yes, asyncio | No |
Batching support | No | Yes (with CRUD API) |
Schema reload | Yes (automatically, see auto_refetch_schema) | Yes (automatically) |
Space / index names | Yes | Yes |
Access tuple fields by names | Yes | No |
SQL support | Yes | Yes |
Interactive transactions | Yes | No (issue #163) |
Varbinary support | Yes (in MP_BIN fields) |
Yes |
Decimal support | Yes | Yes |
UUID support | Yes | Yes |
EXT_ERROR support | Yes | Yes |
Datetime support | Yes | Yes |
Interval support | No (issue #30) | Yes |
box.session.push() responses | Yes | Yes |
Session settings | No | No |
Graceful shutdown | No | No |
IPROTO_ID (feature discovery) | Yes | Yes |
CRUD support | No | Yes |
Transparent request retrying | No | No |
Transparent reconnecting | Autoreconnect | Yes (reconnect_max_attempts, reconnect_delay), checking of connection liveness |
Connection pool | No | Yes (with master discovery) |
Support of PEP 249 – Python Database API Specification v2.0 | No | Yes |
Encrypted connection (Enterprise Edition) | No (issue #22) | Yes |