A fast Tarantool Database connector for Python/asyncio.
Project description
<img src=”https://avatars2.githubusercontent.com/u/2344919?v=2&s=250” align=”right”>
asynctnt is a high-performance Tarantool database connector library for Python/asyncio. It is highly inspired by asyncpg module.
asynctnt requires Python 3.5 or later and is supported for Tarantool versions 1.6+.
Installation
Use pip to install:
$ pip install asynctnt
Documentation
Documentation is available here.
Key features
Support for all of the basic requests that Tarantool supports. This includes: insert, select, update, upsert, eval, sql (for Tarantool 2.x), call and call16. Note: For the difference between ``call16`` and ``call`` please refer to Tarantool documentation.
Schema fetching on connection establishment, so you can use spaces and indexes names rather than their ids.
Schema auto refetching. If schema in Tarantool is changed, asynctnt refetches it.
Auto reconnect. If connection is lost for some reason - asynctnt will start automatic reconnection procedure (with authorization and schema fetching, of course).
Ability to use dicts for tuples with field names as keys in DML requests (select, insert, replace, delete, update, upsert). This is possible only if space.format is specified in Tarantool. Field names can also be used in update operations instead of field numbers. Moreover, tuples are decoded into the special structures that can act either as tuples or by dicts with the appropriate API.
All requests support specification of timeout value, so if request is executed for too long, asyncio.TimeoutError is raised. It drastically simplifies your code, as you don’t need to use asyncio.wait_for(...) stuff anymore.
Basic Usage
Tarantool config:
box.cfg {
listen = '127.0.0.1:3301'
}
box.once('v1', function()
box.schema.user.grant('guest', 'read,write,execute', 'universe')
local s = box.schema.create_space('tester')
s:create_index('primary')
s:format({
{ name = 'id', type = 'unsigned' },
{ name = 'name', type = 'string' },
})
end)
Python code:
import asyncio
import asynctnt
async def main():
conn = asynctnt.Connection(host='127.0.0.1', port=3301)
await conn.connect()
for i in range(1, 11):
await conn.insert('tester', [i, 'hello{}'.format(i)])
data = await conn.select('tester', [])
first_tuple = data[0]
print('tuple:', first_tuple)
print(f'tuple[0]: {first_tuple[0]}; tuple["id"]: {first_tuple["id"]}')
print(f'tuple[1]: {first_tuple[1]}; tuple["name"]: {first_tuple["name"]}')
await conn.disconnect()
asyncio.run(main())
Stdout:
(note that you can simultaneously access fields either by indices or by their names)
tuple: <TarantoolTuple id=1 name='hello1'> tuple[0]: 1; tuple["id"]: 1 tuple[1]: hello1; tuple["name"]: hello1
SQL
Tarantool 2 brings out an SQL interface to the database. You can easily use SQL through asynctnt
box.cfg {
listen = '127.0.0.1:3301'
}
box.once('v1', function()
box.schema.user.grant('guest', 'read,write,execute', 'universe')
box.sql.execute([[
create table users (
id int primary key,
name text
)
]])
end)
import asyncio
import asynctnt
async def main():
conn = asynctnt.Connection(host='127.0.0.1', port=3301)
await conn.connect()
await conn.sql("insert into users (id, name) values (1, 'James Bond')")
await conn.sql("insert into users (id, name) values (2, 'Ethan Hunt')")
data = await conn.sql('select * from users')
for row in data:
print(row)
await conn.disconnect()
asyncio.run(main())
Stdout:
<TarantoolTuple ID=1 NAME='James Bond'> <TarantoolTuple ID=2 NAME='Ethan Hunt'>
Performance
On all of the benchmarks below wal_mode = none
Sequential
RPS on running 40k requests (no uvloop):
Request |
aiotarantool |
asynctnt |
---|---|---|
ping |
5010.60 |
9037.07 |
call |
4575.98 |
9113.32 |
eval |
4096.32 |
8921.95 |
select |
4063.15 |
9681.12 |
insert |
4038.04 |
9332.21 |
update |
3945.12 |
10532.75 |
RPS on running 40k requests (with uvloop):
Request |
aiotarantool |
asynctnt |
---|---|---|
ping |
7204.31 |
20372.59 |
call |
6723.58 |
17279.21 |
eval |
7001.27 |
16642.67 |
select |
7028.03 |
17730.24 |
insert |
7054.06 |
17384.26 |
update |
6618.01 |
15990.12 |
Parallel coroutines
RPS on running 200k requests in 300 parallel coroutines (no uvloop):
Request |
aiotarantool |
asynctnt |
---|---|---|
ping |
32946.25 |
44090.53 |
call |
29005.93 |
41129.16 |
eval |
28792.84 |
44097.02 |
select |
26929.76 |
35853.33 |
insert |
27142.52 |
31329.85 |
update |
25330.98 |
36281.59 |
Let’s enable uvloop. This is where asynctnt shines. RPS on running 200k requests in 300 parallel coroutines (with uvloop):
Request |
aiotarantool |
asynctnt |
---|---|---|
ping |
38962.01 |
134043.41 |
call |
32799.71 |
99866.28 |
eval |
27608.09 |
91056.69 |
select |
27436.98 |
108940.41 |
insert |
33247.57 |
102971.13 |
update |
28544.68 |
98643.46 |
License
asynctnt is developed and distributed under the Apache 2.0 license.
References
Tarantool - in-memory database and application server.
aiotarantool - alternative Python/asyncio connector
asynctnt-queue - bindings on top of asynctnt for tarantool-queue
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for asynctnt-1.0b3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea2f7d4bddca6792d90628fec43294a60bc9f64b00a7a5fa85879a2dc68e2256 |
|
MD5 | b42295712c353734d2ce34c1207dedbb |
|
BLAKE2b-256 | 1eaaa1b3972b282d602bc9fc97fdc4e0f4526eb8827a3dd4704c608fb63ec378 |
Hashes for asynctnt-1.0b3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20c1e8726c3532a001fbf76cb9921ff80bfc2319ce020fae9ba39422562a53be |
|
MD5 | 7bd1502b383b1d8d3449b96af66c7282 |
|
BLAKE2b-256 | 320cfc34a0d7731dbb6742f63510481507c7627553cf15ab7eed7bac82f1db39 |
Hashes for asynctnt-1.0b3-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61b669fdd6a7b2c333cb0675e274e27bb03d1c07064a58ec8b55c3308faf7d6a |
|
MD5 | 35912f9571b64024089903c4c92d18ce |
|
BLAKE2b-256 | 1d03eda6b5332ba1861b4ddb31419a1cae07c5bf2e606adae344fc1b4943e9ed |
Hashes for asynctnt-1.0b3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afc0447754a71d070a530cb00471260cde56e5835b0fce5a4e6c932896741865 |
|
MD5 | 8c38141c629b9aa11a198dbf29b30549 |
|
BLAKE2b-256 | a324dbdd25ca0d9b045291829f05a6d395c5ddd61b4503070df1a8e3081435d5 |
Hashes for asynctnt-1.0b3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4e9925a9933fca611d9ee47972c8feb410f70c437f06795eb266e9832e98948 |
|
MD5 | e34b8f74be94edf0ffd2543dffe76dc6 |
|
BLAKE2b-256 | 8e142151ee314738df0fe55feed33f0f87ef224705d5610d0524709beeb0fab2 |
Hashes for asynctnt-1.0b3-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56543ad52ccf84a18cb3d639bc4302ed7d27c4350f66d96858ae1b364f1c0046 |
|
MD5 | 44a5c2a739bf59d58350d9fe896b2472 |
|
BLAKE2b-256 | 1a12f1bf10f6976f376b5e1d525d6da542f1f345377301c255e569998fb3b23c |
Hashes for asynctnt-1.0b3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d9be437a9e274d9b32a82f00c2d5ad1f0198165fcb375145b38c9283f11b320 |
|
MD5 | 91e1071a4e8d24e4efca5ffa79a189b2 |
|
BLAKE2b-256 | 1370dc22c4829525d444aa97bda04c05519d0dd42bed317d37c299002ef773b6 |
Hashes for asynctnt-1.0b3-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35d41a53bbb7fe00540178f2e465122d09c9e3fcee82285be40db14c52b38c19 |
|
MD5 | 1a46f747ed916ef2ff7b67f25a5b649e |
|
BLAKE2b-256 | f7319561328b4d6c60a084d397c4472995ba17fc299020adcc8103eb857224e2 |
Hashes for asynctnt-1.0b3-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 000b3955391647fb3943748cc62251eaa208883a9ff8ff9acfebf17299e28d93 |
|
MD5 | 7ac19b89d7fc7caf28ae7736410d5707 |
|
BLAKE2b-256 | 0d8c2ba54d8e2bce70cd7c63b7cb8d1b672f675399cd80512f2fb2ca3edf23c4 |