Postgres integration with asyncio.
import asyncio from aiopg.pool import create_pool dsn = 'dbname=jetty user=nick password=1234 host=localhost port=5432' @asyncio.coroutine def test_select(): pool = yield from create_pool(dsn) with (yield from pool) as conn: cur = yield from conn.cursor() yield from cur.execute('SELECT 1') ret = yield from cur.fetchone() assert ret == (1,), ret asyncio.get_event_loop().run_until_complete(test_select())
Example of SQLAlchemy optional integration
import asyncio from aiopg.sa import create_engine import sqlalchemy as sa metadata = sa.MetaData() tbl = sa.Table('tbl', metadata, sa.Column('id', sa.Integer, primary_key=True), sa.Column('val', sa.String(255))) @asyncio.coroutine def go(): engine = yield from create_engine(user='aiopg', database='aiopg', host='127.0.0.1', password='passwd') with (yield from engine) as conn: yield from conn.execute(tbl.insert().values(val='abc')) res = yield from conn.execute(tbl.select()) for row in res: print(row.id, row.val) asyncio.get_event_loop().run_until_complete(go())
$ python3 runtests.py
for executing project’s unittests
- Add PostgreSQL notification support #58
- Support pools with unlimited size #59
- Get rid of resource leak on connection failure.
- Report ResourceWarning on non-closed connections.
- Deprecate iteration protocol support in cursor and ResultProxy.
- Release sa connection to pool on connection.close().
- Accept dict, list, tuple, named and positional parameters in SAConnection.execute()
- Minor release, fixes a bug that leaves connection in broken state after cursor.execute() failure.
- Fix a bug for processing transactions in line.
- Add .terminate() to Pool and Engine
- Reimplement connection pool (now pool size cannot be greater than pool.maxsize)
- Add .close() and .wait_closed() to Pool and Engine
- Add minsize, maxsize, size and freesize properties to sa.Engine
- Support echo parameter for logging executed SQL commands
- Connection.close() is not a coroutine (but we keep backward compatibility).
- make cursor iterable
- update docs
- add timeouts for database operations.
- Autoregister psycopg2 support for json data type.
- Support JSON in aiopg.sa
- Support ARRAY in aiopg.sa
- Autoregister hstore support if present in connected DB
- Support HSTORE in aiopg.sa
- change signature to cursor.execute(operation, parameters=None) to follow psycopg2 convention.
- Forward arguments to cursor constructor for pooled connections.
- Allow executing SQLAlchemy DDL statements.
- Fix bug with race conditions on acquiring/releasing connections from pool.
- Fix bug in connection pool.
- Fix bug with passing parameters into SAConnection.execute when executing raw SQL expression.
- Close connection with invalid transaction status on returning to pool.
- Implemented optional support for sqlalchemy functional sql layer.
- Implemented plain connections: connect, Connection, Cursor.
- Implemented database pools: create_pool and Pool.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.