GithubHelp home page GithubHelp logo

adamchainz / aiopg Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aio-libs/aiopg

0.0 3.0 0.0 497 KB

aiopg is a library for accessing a PostgreSQL database from the asyncio

Home Page: http://aiopg.readthedocs.org

License: BSD 2-Clause "Simplified" License

Makefile 0.59% Python 99.41%

aiopg's Introduction

aiopg

image

image

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
import aiopg

dsn = 'dbname=aiopg user=aiopg password=passwd host=127.0.0.1'

async def go():
    pool = await aiopg.create_pool(dsn)
    async with pool.acquire() as conn:
        async with conn.cursor() as cur:
            await cur.execute("SELECT 1")
            ret = []
            async for row in cur:
                ret.append(row)
            assert ret == [(1,)]

loop = asyncio.get_event_loop()
loop.run_until_complete(go())

Example of SQLAlchemy optional integration

import asyncio
from aiopg.sa import create_engine
from sqlalchemy.schema import CreateTable
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)))


async def go():
    async with create_engine(user='aiopg',
                             database='aiopg',
                             host='127.0.0.1',
                             password='passwd') as engine:

    async with engine.acquire() as conn:
        await conn.execute(tbl.insert().values(val='abc'))

        async for row in conn.execute(tbl.select()):
            print(row.id, row.val)

asyncio.get_event_loop().run_until_complete(go())

For yield from based code see ./examples folder, files with old_style part in their names.

Please use:

$ make test

for executing the project's unittests. See CONTRIBUTING.rst for details on how to set up your environment to run the tests.

aiopg's People

Contributors

aeronotix avatar aplavin avatar asvetlov avatar bitdancer avatar encukou avatar fantix avatar hellysmile avatar jettify avatar lowks avatar luhn avatar popravich avatar spumer avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.