Simple example

That’s all you need to start out with your own documents. More than that,
actually: declaring and “typing” fields is entirely optional.

Obviously, you need a RethinkDB instance running, and you need a database
including the tables for your Document classes. aiorethink can’t help you with
the RethinkDB instance, but the DB setup can be done like so (assuming a
RethinkDB instance runs on localhost):

async for spidey, changed_keys, change_msg in await spidey.aiter_changes():
if "name" in changed_keys:
print("what, a typo again? {}?".format(spidey.name))
# change_msg is straight from the rethinkdb changes() query

Features

The following features are either fully or partially implemented:

optional schema: declare fields in Document classes and get serialization and
validation magic much like you know it from other ODMs / ORMs. Or don’t
declare fields and just use them with the dictionary interface. Or use a mix
of declared and undeclared fields.

schema for complex fields such as lists, dicts, or even “sub-documents” with
named and typed fields just like documents.

dict interface that works for both declared and undeclared fields.

all I/O is is asynchronous, done with async def / await style
coroutines, using asyncio.

lazy-loading and caching (i.e. “awaitable” fields), for example references
to other documents.

asynchronous changefeeds using async for, on documents and document
classes. aiorethink can also assist with Python object creation on just about
any other changefeed.

Philosophy

aiorethink aims to do the following two things very well:

make translations between database documents and Python objects easy and
convenient

help with schema and validation

Other than that, aiorethink tries not to hide RethinkDB under a too thick
abstraction layer. RethinkDB’s excellent Python driver, and certainly its
awesome query language, are never far removed and always easy to access. Custom
queries on document objects should be easy. Getting document objects out of
vanilla rethinkdb queries, including changefeeds, should also be easy.

Status

aiorethink is in development. The API is not complete and not stable yet,
although the most important features are present now.