Skip to content

Latest commit

 

History

History
113 lines (90 loc) · 5.99 KB

dev-guide.rst

File metadata and controls

113 lines (90 loc) · 5.99 KB

Developer's guide

Tarantool database basic concepts

To understand, what is "space", "tuple" and what basic operations are, refer to Tarantool data model documentation.

Field types

Tarantool uses MessagePack as a format for receiving requests and sending responses. Refer to Lua versus MessagePack to see how types are encoded and decoded.

While working with Tarantool from Python with this connector, each request data is encoded to MessagePack and each response data is decoded from MessagePack with the Python MessagePack module. See its documentation to explore how basic types are encoded and decoded.

There are several cases when you may tune up the behavior. Use :class:`tarantool.Connection` parameters to set Python MessagePack module options.

Use :paramref:`~tarantool.Connection.params.encoding` to tune behavior for string encoding.

encoding='utf-8' (default):

Python -> MessagePack (Tarantool/Lua) -> Python
:obj:`str` -> mp_str (string) -> :obj:`str`
:obj:`bytes` -> mp_bin (binary/cdata) -> :obj:`bytes`

encoding=None (work with non-UTF8 strings):

Python -> MessagePack (Tarantool/Lua) -> Python
:obj:`bytes` -> mp_str (string) -> :obj:`bytes`
:obj:`str` -> mp_str (string) -> :obj:`bytes`
  -> mp_bin (binary/cdata) -> :obj:`bytes`

Use :paramref:`~tarantool.Connection.params.use_list` to tune behavior for mp_array (Lua table) decoding.

use_list='True' (default):

Python -> MessagePack (Tarantool/Lua) -> Python
:obj:`list` -> mp_array (table) -> :obj:`list`
:obj:`tuple` -> mp_array (table) -> :obj:`list`

use_list='False':

Python -> MessagePack (Tarantool/Lua) -> Python
:obj:`list` -> mp_array (table) -> :obj:`tuple`
:obj:`tuple` -> mp_array (table) -> :obj:`tuple`

Tarantool implements several extension types. In Python, they are represented with in-built and custom types:

Python -> Tarantool -> Python
:obj:`decimal.Decimal` -> DECIMAL -> :obj:`decimal.Decimal`
:obj:`uuid.UUID` -> UUID -> :obj:`uuid.UUID`
:class:`tarantool.Datetime` -> DATETIME -> :class:`tarantool.Datetime`
:class:`tarantool.Interval` -> INTERVAL -> :class:`tarantool.Interval`

Request response

Server requests (except for :meth:`~tarantool.Connection.ping`) return :class:`~tarantool.response.Response` instance in case of success.

:class:`~tarantool.response.Response` is inherited from :class:`collections.abc.Sequence`, so you can index response data and iterate through it as with any other serializable object.