Asyncio middleware for SQLAlchemy
Project description
The aiopg and aiomysql projects allow to operate asynchronously with PostgresQL and MySQL, respectively, even thru SQLAlchemy. Their approach isn’t ideal, though, because they reimplement a considerable amount of SA low level stuff with undesirable glitches.
The Twisted based Alchimia way is much lighter and even if maybe slightly less performant it does not introduce unexpected surprises.
Usage
Basically the module wraps a minimal set of SA classes (currently just Engine, Connection, Transaction and ResultProxy) into asyncronous counterparts, and you work on them like the following example:
from asyncio import coroutine from arstecnica.sqlalchemy.async import create_engine @coroutine def do_something(db_url): engine = create_engine(db_url) with (yield from engine.connect()) as conn: with (yield from conn.begin()) as trans: yield from conn.execute(users.insert() .values(id=42, name="Async",)) res = yield from conn.execute(users.select() .where(users.c.id == 42)) rows = yield from res.fetchall() res = yield from conn.execute(users.delete() .where(users.c.id == 42)) assert res.rowcount == 1
Tests
To run the unit tests, you should:
create a Python virtual environment and install this package in development mode:
python3 -m venv env source env/bin/activate python setup.py develop
install pytest and either psycopg2 or cymysql:
pip install pytest psycopg2 cymysql
create a test database, for example with createdb testdb
execute the py.test runner with an environment variable with the SA URL of the db:
TEST_DB_URL="postgresql://localhost/testdb" py.test src TEST_DB_URL="mysql+cymysql://localhost/testdb" py.test src
Changes
0.2 (unreleased)
First (usable) distribution on PyPI
0.1 (private)
Works reasonably well!
0.0 (private)
Initial effort.
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
Hashes for arstecnica.sqlalchemy.async-0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd2d8088a531d62f0d446d71e2f3f4d8aff3c43739c6312b749db03e1c813a69 |
|
MD5 | ea0923ab11533ef0e69d571f1613abfa |
|
BLAKE2b-256 | b94e9ceae4f1bbe4846b2f19e6cb2b48738e6df9c55a1237d97d77ca30513af3 |