Skip to main content

aiorethink

PyPI Package latest release Documentation Status Travis CI build status coveralls status

aiorethink is a fairly comprehensive but easy-to-use asyncio-enabled Object Document Mapper for RethinkDB. It is currently in development.

Documentation: http://aiorethink.readthedocs.org (very early stages)

Source: https://github.com/lars-tiede/aiorethink

Simple example

import aiorethink as ar

class Hero(ar.Document):
    name = ar.Field(ar.StringValueType(), indexed = True)

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):

ar.configure_db_connection(db = "my_db")
await ar.init_app_db()

Let’s make a document:

spiderman = Hero(name = "Spiderma")

# declared fields can be accessed by attribute or dict interface
spiderman.name = "Spierman"
spiderman["name"] = "Spiderman" # third time's the charm

# with the dict interface, we can make and access undeclared fields
spiderman["nickname"] = "Spidey"

Validate and save to DB:

try:
    await spiderman.save() # calls spiderman.validate()
except ar.ValidationError as e:
    print("validation failed, doc not saved: {}".format(e))

# if we don't declare a primary key field, RethinkDB makes us an 'id' field
doc_id = spiderman.id

Load a document from the DB:

spidey = Hero.load(doc_id) # using primary key

spidey = Hero.from_query(  # using arbitrary query
    Hero.cq(). # "class query prefix", basically rethinkdb.table("Heros")
        get_all("Spiderman", index = "name").nth(0)
)

Iterate over a document’s RethinkDB changefeed:

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.

Planned features:

  • maybe explicit relations between document classes (think “has_many” etc.)

  • maybe schema migrations

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.

Metadata

Release files for aiorethink 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiorethink 0.2.1
File Size Uploaded Provenance Actions
aiorethink-0.2.1.tar.gz 22.1 kB Without provenance Details for aiorethink-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aiorethink 0.2.1
File Interpreter ABI Platform Actions
aiorethink-0.2.1-py3-none-any.whl Python 3 none any Details for aiorethink-0.2.1-py3-none-any.whl

Total release size: 51.8 kB

Release files / aiorethink-0.2.1.tar.gz

Download URL aiorethink-0.2.1.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b2674a7a79cad71147c753a9a8e50366f9fce64e310f6955c972535c6c5b09e0
BLAKE2b-256 checksum
How to use checksums
9894423861a29d18f5038e5a73c40f09a14accd7b5383555ce5bea5db4976beb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiorethink-0.2.1-py3-none-any.whl

Download URL aiorethink-0.2.1-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
133d8b4056d8a5e89a3a7e2b988bbfefbed5b8ca0b7f91bf8649cd4cd9ffbebf
BLAKE2b-256 checksum
How to use checksums
b2a0bd7e39d85d816b913c3610681c04ae1f6f74ce0f3b0083ab0f15293737a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for aiorethink 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page