Skip to main content

Postgress integration with asyncio.

Project description

aiopg is a library for accessing a PostgreSQL database from the asyncio (PEP-3156/tulip) framework. It wraps asynchronous features of the Psycopg database driver.

Example

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())

Please use:

$ python3 runtests.py

for executing project’s unittests

CHANGES

0.3.1 (2014-07-04)

  • Forward arguments to cursor constructor for pooled connections.

0.3.0 (2014-06-22)

  • Allow executing SQLAlchemy DDL statements.

  • Fix bug with race conditions on acquiring/releasing connections from pool.

0.2.3 (2014-06-12)

  • Fix bug in connection pool.

0.2.2 (2014-06-07)

  • Fix bug with passing parameters into SAConnection.execute when executing raw SQL expression.

0.2.1 (2014-05-08)

  • Close connection with invalid transaction status on returning to pool.

0.2.0 (2014-05-04)

  • Implemented optional support for sqlalchemy functional sql layer.

0.1.0 (2014-04-06)

  • Implemented plain connections: connect, Connection, Cursor.

  • Implemented database pools: create_pool and Pool.

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

aiopg-0.3.1.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

aiopg-0.3.1-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file aiopg-0.3.1.tar.gz.

File metadata

  • Download URL: aiopg-0.3.1.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiopg-0.3.1.tar.gz
Algorithm Hash digest
SHA256 5d47915f1da08f8b973ac5503920262a14c463dc3a345bf8fff84c540aea13e2
MD5 214f6c7ce2c6152aaaa044c69de0a1ed
BLAKE2b-256 bb86fd9e65788a4c69d2eefe52db782c95f5ae2d52294e07402b91f19cb1f572

See more details on using hashes here.

File details

Details for the file aiopg-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aiopg-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1cecdbf4ed2cf21af1203b0832ee528ed0290c9575ab9b175e6c069ec06bb96
MD5 2eabf9b6030c30dd2fcce5bf17d67a39
BLAKE2b-256 09df93a3569618fed8818b4cf31a70a372e61c6793f33de7c290e8bd526bb64b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page