Skip to main content

Small and partial Obejct mapper on top of sqlalchemy for async

Project description


Async OM it's a super basic Object mapper based almost all on sqlalchemy ORM layer.

We use the declarative extension for building the classes, and also, factor instances of them on querys. (*Limited support)

There is still no support for relations.

Depens on encode/databases dependency.


I don't like the asyncpgsa approach where they are just using, the core layer, to build run the sqlgenerator. I like to build, around the declarative layer of sqlachemy, and later found that I can patch some of the methods on the session.query, to use it's own sql generator, and turn async the query system.

Object persistent is minimal, and needs some love.


from sqlalchemy.ext.declarative import declarative_base
import sqlalchemy as sa
from databases import DatabaseURL

Base = declarative_base()

class OrmTest(Base):
    __tablename__ = 'orm_test'

    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String(100), index=True)
    value = sa.Column(sa.Text)

# Instead of usign Database from databases, you can use:
db = OMDatabase(DatabaseURL('postgres://root@postgres:{port}/guillotina'))

# instances of the object can be created with:
test = OrmTest(name='xx', value='yy')
await db.add(test)

print(  # pk column is correct set

# get an instance
ins = await db.query(OrmTest).get(1)

total = await db.query(OrmTest).count()
assert total == 1

# remove it
await db.delete(ins)

# filter them
res = await db.query(OrmTest).filter('xx')).all()

# Or just iterate over the results with a cursor:
async for row in db.query(OrmTest).filter('xx')):
    print(f'Row {}: {row.value}')

# There is basic support for table inheritance query OneToOne

# Look at tests



  • Fix collections import for Python 3.10


  • Support query multiple primary keys


  • Be able to provide mapper_factory to OMQuery [vangheem]


  • Fix bug with om.delete an inherited objects


  • Fix boolean expr on adding prods. Allowing to add values with 0


  • Small fix when checking none on json fields arrays


  • Added Column default and onupdate on update and add (only for scalar values and callables)
  • Added small proxy prop on OMDatabaes, to raw asyncpg connection


  • Yaml data importer


  • Support adding basic inherited models


  • query should be an async iterator


  • Load inherited models.


  • query(Object).get should return None if not found


  • Fixes and improvements. Lay out basic API

0.1.0 (2019-04-07)

  • First release on PyPI.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncom-0.3.3.tar.gz (11.5 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page