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

CHANGES

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.2.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

aiopg-0.2.0-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for aiopg-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fe54252eeec64cdf364dda106ecf3a9902ea39db70cbdf4c6201cfc3620e0587
MD5 e85ab7c20b275e1a00eec2c17d95b7ca
BLAKE2b-256 c125ee0aa35aa0885a59017484fe035c2c9f887ed0f1925060fefce76f5eb2ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiopg-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4ab5215f914c01d2764706e4c74965a38aaad63ad48bf1b354603b0e7ba0e80
MD5 2a7a0f235413ba5b906fb36aaca30502
BLAKE2b-256 3ab3ef5f0695aa3c4ce77446307791ee20b533a5f3be92bc342967583ec5dc65

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