Skip to main content

ODBC driver for asyncio.

Project description

https://travis-ci.org/jettify/aioodbc.svg?branch=master https://coveralls.io/repos/jettify/aioodbc/badge.svg?branch=master&service=github

aioodbc is Python module that makes possible accessing ODBC databases with asyncio. It is rely on awesome pyodbc library, preserve same look and feel.

Basic Example

aioodbc based on pyodbc , and provides same api, you just need to use yield from conn.f() or await conn.f() instead of just call conn.f() for every method.

Properties are unchanged, so conn.prop is correct as well as conn.prop = val.

import asyncio
import aioodbc


loop = asyncio.get_event_loop()


@asyncio.coroutine
def test_example():
    dsn = 'Driver=SQLite;Database=sqlite.db'
    conn = yield from aioodbc.connect(dsn=dsn, loop=loop)

    cur = yield from conn.cursor()
    yield from cur.execute("SELECT 42;")
    r = yield from cur.fetchall()
    print(r)
    yield from cur.close()
    yield from conn.close()

loop.run_until_complete(test_example())

Connection Pool

Connection pooling ported from aiopg and rely on PEP492 features:

import asyncio
import aioodbc


loop = asyncio.get_event_loop()


async def test_pool():
    dsn = 'Driver=SQLite;Database=sqlite.db'
    pool = await aioodbc.create_pool(dsn=dsn, loop=loop)

    async with (await pool) as conn:
        cur = await conn.cursor()
        await cur.execute("SELECT 42;")
        r = await cur.fetchall()
        print(r)
        await cur.close()
        await conn.close()
    pool.close()
    await pool.wait_closed()

loop.run_until_complete(test_example())

Installation

pip3 install git+https://github.com/jettify/aioodbc.git

In Linux environment pyodbc (hence aioodbc) requires unixODBC library. You can use standard one from your distro like:

$ sudo apt-get install unixodbc
$ sudo apt-get install unixodbc-dev

Other SQL Drivers

  • aiopg - asyncio client for PostgreSQL
  • aiomysql - asyncio client form MySQL

Requirements

Changes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aioodbc, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size aioodbc-0.0.1.tar.gz (17.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page