Skip to main content

asyncio sqlalchemy support

Project description


Downloads PyPI version

asyncio sqlalchemy support,with async/await

add asyncio sqlalchemy support


pip install async-sqlalchemy

Usage examples

import asyncio
from sqlalchemy import Integer, Column, String, ForeignKey
from async_sqlalchemy.manager.async_pg import PostgresManager
from async_sqlalchemy.model.mixin import Mixin
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.sql import select

dsn = "postgres://postgres:test@localhost:2345/test"

conf = {'dsn': dsn}

Base = declarative_base()

Manager = PostgresManager(conf=conf)

class User(Mixin, Base):

    _manager = Manager

    __tablename__ = 'test'
    id = Column(Integer, autoincrement=True,  primary_key=True)
    name = Column(String(50))

    def __repr__(self):
        return "<User(name='%s', id='%s')>" % (

class Parent(Mixin, Base):
    __tablename__ = 'parent'
    _manager = Manager
    id = Column(Integer, primary_key=True)
    child = relationship("Child", lazy='joined')

class Child(Mixin, Base):
    _manager = Manager
    __tablename__ = 'child'
    id = Column(Integer, primary_key=True)
    parent_id = Column(Integer, ForeignKey(''))
    parent = relationship("Parent", back_populates="child")

if __name__ == '__main__':

    loop = asyncio.get_event_loop()

    result = loop.run_until_complete(Manager.get(

    # result = loop.run_until_complete(Child.create_table())
    # print(result)
    # u = loop.run_until_complete(User.create(name='test'))
    # print('create', u)
    # print('get', loop.run_until_complete(User.get(name='test')))
    # print('all', loop.run_until_complete(User.all()))
    # = 'aaa'
    # print('save', loop.run_until_complete(


The asyncnsq is offered under MIT license.

Project details

Download files

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

Files for async-sqlalchemy, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size async_sqlalchemy-1.0.0-py3-none-any.whl (2.1 kB) File type Wheel Python version py3 Upload date Hashes View

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