asynctnt.api
Module Contents
Classes
Enum where members are also (and must be) ints |
|
- class asynctnt.api.Isolation[source]
Bases:
enum.IntEnum
Enum where members are also (and must be) ints
- class asynctnt.api.Api[source]
-
- _set_db(db: asynctnt.iproto.protocol.Db)[source]
- ping(*, timeout: float = -1.0) asynctnt.types.MethodRet [source]
Ping request coroutine
- Parameters:
timeout – Request timeout
- Returns:
asynctnt.Response
instance
- call16(func_name: str, args: List[Any] | None = None, *, timeout: float = -1.0, push_subscribe: bool = False) asynctnt.types.MethodRet [source]
Call16 request coroutine. It is a call with an old behaviour (return result of a Tarantool procedure is wrapped into a tuple, if needed)
- Parameters:
func_name – function name to call
args – arguments to pass to the function (list object)
timeout – Request timeout
push_subscribe – Subscribe to push notifications
- Returns:
asynctnt.Response
instance
- call(func_name: str, args: List[Any] | None = None, *, timeout: float = -1.0, push_subscribe: bool = False) asynctnt.types.MethodRet [source]
Call request coroutine. It is a call with a new behaviour (return result of a Tarantool procedure is not wrapped into an extra tuple). If you’re connecting to Tarantool with version < 1.7, then this call method acts like a call16 method
Examples:
# tarantool function: # function f(...) # return ... # end >>> await conn.call('f') <Response sync=3 rowcount=0 data=[]> >>> await conn.call('f', [20, 42]) <Response sync=3 rowcount=2 data=[20, 42]>
- Parameters:
func_name – function name to call
args – arguments to pass to the function (list object)
timeout – Request timeout
push_subscribe – Subscribe to push notifications
- Returns:
asynctnt.Response
instance
- eval(expression: str, args: List[Any] | None = None, *, timeout: float = -1.0, push_subscribe: bool = False) asynctnt.types.MethodRet [source]
Eval request coroutine.
Examples:
>>> await conn.eval('return 42') <Response sync=3 rowcount=1 data=[42]> >>> await conn.eval('return box.info.version') <Response sync=3 rowcount=1 data=['2.1.1-7-gd381a45b6']>
- Parameters:
expression – expression to execute
args – arguments to pass to the function, that will execute your expression (list object)
timeout – Request timeout
push_subscribe – Subscribe to push messages
- Returns:
asynctnt.Response
instance
- select(space: asynctnt.types.SpaceType, key: asynctnt.types.KeyType | None = None, **kwargs) asynctnt.types.MethodRet [source]
Select request coroutine.
Examples:
>>> await conn.select('tester') <Response sync=3 rowcount=2 data=[ <TarantoolTuple id=1 name='one'>, <TarantoolTuple id=2 name='two'> ]> >>> res = await conn.select('_space', ['tester'], index='name') >>> res.data [<TarantoolTuple id=512 owner=1 name='tester' engine='memtx' field_count=0 flags={} format=[ {'name': 'id', 'type': 'unsigned'}, {'name': 'name', 'type': 'string'} ]>]
- Parameters:
space – space id or space name.
key – key to select
offset – offset to use
limit – limit to use
index – index id or name
iterator –
one of the following
iterator id (int number),
asynctnt.Iterator
objectstring with an iterator name
timeout – Request timeout
- Returns:
asynctnt.Response
instance
- insert(space: asynctnt.types.SpaceType, t: asynctnt.types.TupleType, *, replace: bool = False, timeout: float = -1) asynctnt.types.MethodRet [source]
Insert request coroutine.
Examples:
# Basic usage >>> await conn.insert('tester', [0, 'hello']) <Response sync=3 rowcount=1 data=[ <TarantoolTuple id=0 name='hello'> ]> # Using dict as an argument tuple >>> await conn.insert('tester', { ... 'id': 0 ... 'text': 'hell0' ... }) <Response sync=3 rowcount=1 data=[ <TarantoolTuple id=0 name='hello'> ]>
- Parameters:
space – space id or space name.
t – tuple to insert (list object)
replace – performs replace request instead of insert
timeout – Request timeout
- Returns:
asynctnt.Response
instance
- replace(space: asynctnt.types.SpaceType, t: asynctnt.types.TupleType, *, timeout: float = -1.0) asynctnt.types.MethodRet [source]
Replace request coroutine. Same as insert, but replace.
- Parameters:
space – space id or space name.
t – tuple to insert (list object)
timeout – Request timeout
- Returns:
asynctnt.Response
instance
- delete(space: asynctnt.types.SpaceType, key: asynctnt.types.KeyType, **kwargs) asynctnt.types.MethodRet [source]
Delete request coroutine.
Examples:
# Assuming tuple [0, 'hello'] is in space tester >>> await conn.delete('tester', [0]) <Response sync=3 rowcount=1 data=[ <TarantoolTuple id=0 name='hello'> ]>
- Parameters:
space – space id or space name.
key – key to delete
index – index id or name
timeout – Request timeout
- Returns:
asynctnt.Response
instance
- update(space: asynctnt.types.SpaceType, key: asynctnt.types.KeyType, operations: List[Any], **kwargs) asynctnt.types.MethodRet [source]
Update request coroutine.
Examples:
# Assuming tuple [0, 'hello'] is in space tester >>> await conn.update('tester', [0], [ ['=', 1, 'hi!'] ]) <Response sync=3 rowcount=1 data=[ <TarantoolTuple id=0 name='hi!'> ]> # you can use fields names as well >>> res = await conn.update('tester', [0], ... [ ['=', 'text', 'hola'] ]) <Response sync=3 rowcount=1 data=[ <TarantoolTuple id=0 name='hola'> ]>
- Parameters:
space – space id or space name.
key – key to update
operations – Operations list of the following format: [ [op_type, field_no, …], … ]. Please refer to https://tarantool.org/doc/book/box/box_space.html?highlight=update#lua-function.space_object.update You can use field numbers as well as their names in space format as a field_no (if only fetch_schema is True). If field is unknown then TarantoolSchemaError is raised.
index – index id or name
timeout – Request timeout
- Returns:
asynctnt.Response
instance
- upsert(space: asynctnt.types.SpaceType, t: asynctnt.types.TupleType, operations: List[Any], **kwargs) asynctnt.types.MethodRet [source]
Update request coroutine. Performs either insert or update (depending of either tuple exists or not)
Examples:
# upsert does not return anything >>> await conn.upsert('tester', [0, 'hello'], ... [ ['=', 1, 'hi!'] ]) <Response sync=3 rowcount=0 data=[]>
- Parameters:
space – space id or space name.
t – tuple to insert if it’s not in space
operations – Operations list to use for update if tuple is already in space. It has the same format as in update requets: [ [op_type, field_no, …], … ]. Please refer to https://tarantool.org/doc/book/box/box_space.html?highlight=update#lua-function.space_object.update You can use field numbers as well as their names in space format as a field_no (if only fetch_schema is True). If field is unknown then TarantoolSchemaError is raised.
timeout – Request timeout
- Returns:
asynctnt.Response
instance
- execute(query: str | int, args: List[Dict[str, Any] | Any] | None = None, *, parse_metadata: bool = True, timeout: float = -1.0) asynctnt.types.MethodRet [source]
Executes an SQL statement (only for Tarantool > 2)
Examples:
>>> await conn.execute("select 1 as a, 2 as b") <Response sync=3 rowcount=1 data=[<TarantoolTuple A=1 B=2>]> >>> await conn.execute("select * from sql_space") <Response sync=3 rowcount=2 data=[ <TarantoolTuple ID=1 NAME='James Bond'>, <TarantoolTuple ID=2 NAME='Ethan Hunt'> ]> >>> await conn.execute("select * from sql_space", ... parse_metadata=False) <Response sync=3 rowcount=2 data=[ <TarantoolTuple 0=1 1='James Bond'>, <TarantoolTuple 0=2 1='Ethan Hunt'> ]>
- Parameters:
query – SQL query or statement_id
args – Query arguments
parse_metadata – Set to False to disable response’s metadata parsing for better performance
timeout – Request timeout
- Returns:
asynctnt.Response
instance
- prepare(query: str) asynctnt.prepared.PreparedStatement [source]
Create a
asynctnt.prepared.PreparedStatement
instance :param query: query to be prepared
- prepare_iproto(query: str, timeout: float = -1.0) asynctnt.types.MethodRet [source]
Low-level prepare() call :param query: query to be prepared :param timeout: request timeout
- unprepare_iproto(stmt_id: int, timeout: float = -1.0) asynctnt.types.MethodRet [source]
Low-level unprepare() call :param stmt_id: query to be unprepared :param timeout: request timeout
- begin(isolation: Isolation = Isolation.DEFAULT, tx_timeout: float = 0.0, timeout: float = -1.0) asynctnt.types.MethodRet [source]
Begin an interactive transaction within a stream :param isolation: isolation level :param tx_timeout: transaction timeout :param timeout: request timeout :return: