This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

aioodbc is Python 3.5+ module that makes possible accessing ODBC databases with asyncio. It is rely on awesome pyodbc library, preserve same look and feel. aioodbc was written async/await syntax (PEP492) thus not compatible with Python older then 3.5. Internally aioodbc employ threads to avoid blocking the event loop, btw threads are not that bad as you think :)

Supported Databases

aioodbc should work with all databases supported by pyodbc. But for now library have been tested with: SQLite, MySQL and PostgreSQL. Feel free to add other databases to the test suite by submitting PR.

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


async def test_example():
    dsn = 'Driver=SQLite;Database=sqlite.db'
    conn = await aioodbc.connect(dsn=dsn, loop=loop)

    cur = await conn.cursor()
    await cur.execute("SELECT 42;")
    r = await cur.fetchall()
    print(r)
    await cur.close()
    await 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 pool.acquire() 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())

Context Managers

Pool, Connection and Cursor objects support context manager protocol:

import asyncio
import aioodbc


loop = asyncio.get_event_loop()


async def test_example():
    dsn = 'Driver=SQLite;Database=sqlite.db'

    async with aioodbc.create_pool(dsn=dsn, loop=loop) as pool:
        async with pool.acquire() as conn:
            async with conn.cursor() as cur:
                await cur.execute('SELECT 42;')
                val = await cur.fetchone()
                print(val)

loop.run_until_complete(test_example())

Installation

pip install aioodbc

In Linux environment pyodbc (hence aioodbc) requires unixODBC library. You can install it using package manager from your OS distribution:

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

Run tests

For testing purposes you need to install docker and development requirements:

$ pip install -r requirements-dev.txt

Then just execute:

$ make test

Or if you want to run only one particular test:

$ py.test tests/test_connection.py -k test_basic_cursor

Test will automatically pull images and build containers with required databases.

Other SQL Drivers

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

Requirements

Changes

0.0.3 (2016-07-05)

  • Dockerize tests, now we can add more DBs to tests using docker #15, #17, #19
  • Test suite executed with both default asyncio and uvloop #18

0.0.2 (2016-01-01)

  • Improved pep 492 support.
  • pool.get method removed, use acquire instead.
  • Added tests against MySQL.
  • Added bunch of doc strings.

0.0.1 (2015-10-12)

  • Initial release.
Release History

Release History

0.0.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
aioodbc-0.0.3.tar.gz (16.8 kB) Copy SHA256 Checksum SHA256 Source Jul 5, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting