All Projects → RazerM → Sqlalchemy_aio

RazerM / Sqlalchemy_aio

Licence: other
Asyncio strategy for SQLAlchemy.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Sqlalchemy aio

Aiormq
Pure python AMQP 0.9.1 asynchronous client library
Stars: ✭ 112 (-62.54%)
Mutual labels:  async, asyncio, async-await
Uvloop
Ultra fast asyncio event loop.
Stars: ✭ 8,246 (+2657.86%)
Mutual labels:  async, asyncio, async-await
Web Applications With Fastapi Course
Demo code and other handouts for students of our FastAPI Web Apps course.
Stars: ✭ 56 (-81.27%)
Mutual labels:  asyncio, async-await, sqlalchemy
Cppcoro
A library of C++ coroutine abstractions for the coroutines TS
Stars: ✭ 2,118 (+608.36%)
Mutual labels:  async, asyncio, async-await
Uvicorn Gunicorn Docker
Docker image with Uvicorn managed by Gunicorn for high-performance web applications in Python 3.6 with performance auto-tuning. Optionally with Alpine Linux.
Stars: ✭ 244 (-18.39%)
Mutual labels:  async, asyncio
Odmantic
Async ODM (Object Document Mapper) for MongoDB based on python type hints
Stars: ✭ 240 (-19.73%)
Mutual labels:  async, asyncio
Example Scalping
A working example algorithm for scalping strategy trading multiple stocks concurrently using python asyncio
Stars: ✭ 267 (-10.7%)
Mutual labels:  async, asyncio
FinanceCenter
Fetching Financial Data (US/China)
Stars: ✭ 26 (-91.3%)
Mutual labels:  sqlalchemy, asyncio
Asyncex
A helper library for async/await.
Stars: ✭ 2,794 (+834.45%)
Mutual labels:  async, async-await
aioflask
Flask running on asyncio!
Stars: ✭ 192 (-35.79%)
Mutual labels:  asyncio, async-await
nardis
A small web framework based on ASGI
Stars: ✭ 14 (-95.32%)
Mutual labels:  asyncio, async-await
Await Of
await wrapper for easier errors handling without try-catch
Stars: ✭ 240 (-19.73%)
Mutual labels:  async, async-await
Pyee
A port of Node.js's EventEmitter to python
Stars: ✭ 236 (-21.07%)
Mutual labels:  async, asyncio
tomodachi
💻 Microservice library / framework using Python's asyncio event loop with full support for HTTP + WebSockets, AWS SNS+SQS, RabbitMQ / AMQP, middleware, etc. Extendable for GraphQL, protobuf, gRPC, among other technologies.
Stars: ✭ 170 (-43.14%)
Mutual labels:  asyncio, async-await
Coerce Rs
Coerce - an asynchronous (async/await) Actor runtime and cluster framework for Rust
Stars: ✭ 231 (-22.74%)
Mutual labels:  async, async-await
fast-api-sqlalchemy-template
Dockerized web application on FastAPI, sqlalchemy1.4, PostgreSQL
Stars: ✭ 25 (-91.64%)
Mutual labels:  sqlalchemy, asyncio
fastapi-sqlalchemy-1.4-async
https://rogulski.it/blog/sqlalchemy-14-async-orm-with-fastapi/
Stars: ✭ 17 (-94.31%)
Mutual labels:  sqlalchemy, asyncio
fastapi-boilerplate
FastAPI boilerplate for real world production
Stars: ✭ 145 (-51.51%)
Mutual labels:  sqlalchemy, asyncio
kbio
Another Async IO Framework based on io_uring
Stars: ✭ 54 (-81.94%)
Mutual labels:  asyncio, async-await
Async Std
Async version of the Rust standard library
Stars: ✭ 3,090 (+933.44%)
Mutual labels:  async, async-await

sqlalchemy_aio

|PyPI Version| |Documentation| |Travis| |Coverage| |MIT License|

sqlalchemy_aio adds asyncio and Trio_ support to SQLAlchemy core, derived from alchimia_.

.. _alchimia: https://github.com/alex/alchimia .. _Trio: https://github.com/python-trio/trio

Getting started

.. code-block:: python

import asyncio

from sqlalchemy_aio import ASYNCIO_STRATEGY

from sqlalchemy import (
    Column, Integer, MetaData, Table, Text, create_engine, select)
from sqlalchemy.schema import CreateTable, DropTable


async def main():
    engine = create_engine(
        # In-memory sqlite database cannot be accessed from different
        # threads, use file.
        'sqlite:///test.db', strategy=ASYNCIO_STRATEGY
    )

    metadata = MetaData()
    users = Table(
        'users', metadata,
        Column('id', Integer, primary_key=True),
        Column('name', Text),
    )

    # Create the table
    await engine.execute(CreateTable(users))

    conn = await engine.connect()

    # Insert some users
    await conn.execute(users.insert().values(name='Jeremy Goodwin'))
    await conn.execute(users.insert().values(name='Natalie Hurley'))
    await conn.execute(users.insert().values(name='Dan Rydell'))
    await conn.execute(users.insert().values(name='Casey McCall'))
    await conn.execute(users.insert().values(name='Dana Whitaker'))

    result = await conn.execute(users.select(users.c.name.startswith('D')))
    d_users = await result.fetchall()

    await conn.close()

    # Print out the users
    for user in d_users:
        print('Username: %s' % user[users.c.name])

    # Supports context async managers
    async with engine.connect() as conn:
        async with conn.begin() as trans:
            assert await conn.scalar(select([1])) == 1

    await engine.execute(DropTable(users))


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

Getting started with Trio

To use the above example with Trio_, just change the following:

.. code-block:: python

import trio
from sqlalchemy_aio import TRIO_STRATEGY

async def main():
    engine = create_engine('sqlite:///test.db', strategy=TRIO_STRATEGY)

    ...

trio.run(main)

What is this?

It's not an asyncio implementation of SQLAlchemy or the drivers it uses. sqlalchemy_aio lets you use SQLAlchemy by running operations in a separate thread.

If you're already using run_in_executor_ to execute SQLAlchemy tasks, sqlalchemy_aio will work well with similar performance. If performance is critical, perhaps asyncpg_ can help.

.. _asyncpg: https://github.com/MagicStack/asyncpg .. _run_in_executor: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.run_in_executor

Documentation

The documentation_ has more information, including limitations of the API.

.. _The documentation: https://sqlalchemy-aio.readthedocs.io/en/latest/

.. |PyPI Version| image:: https://img.shields.io/pypi/v/sqlalchemy_aio.svg?style=flat-square :target: https://pypi.python.org/pypi/sqlalchemy_aio/ .. |Documentation| image:: https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat-square :target: https://sqlalchemy-aio.readthedocs.io/en/latest/ .. |Travis| image:: http://img.shields.io/travis/RazerM/sqlalchemy_aio/master.svg?style=flat-square&label=travis :target: https://travis-ci.org/RazerM/sqlalchemy_aio .. |Coverage| image:: https://img.shields.io/codecov/c/github/RazerM/sqlalchemy_aio/master.svg?style=flat-square :target: https://codecov.io/github/RazerM/sqlalchemy_aio?branch=master .. |MIT License| image:: http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square :target: https://raw.githubusercontent.com/RazerM/sqlalchemy_aio/master/LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].