aioodbc


Nameaioodbc JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://github.com/aio-libs/aioodbc
SummaryODBC driver for asyncio.
upload_time2023-10-28 21:37:29
maintainer
docs_urlNone
authorNikolay Novik
requires_python>=3.7
licenseApache 2
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            aioodbc
=======
.. image:: https://github.com/aio-libs/aioodbc/workflows/CI/badge.svg
   :target: https://github.com/aio-libs/aioodbc/actions?query=workflow%3ACI
   :alt: GitHub Actions status for master branch
.. image:: https://codecov.io/gh/aio-libs/aioodbc/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/aio-libs/aioodbc
.. image:: https://img.shields.io/pypi/v/aioodbc.svg
    :target: https://pypi.python.org/pypi/aioodbc
.. image:: https://img.shields.io/pypi/pyversions/aioodbc.svg
    :target: https://pypi.org/project/aioodbc
.. image:: https://badges.gitter.im/Join%20Chat.svg
    :target: https://gitter.im/aio-libs/Lobby
    :alt: Chat on Gitter

**aioodbc** is a Python 3.7+ module that makes it possible to access ODBC_ databases
with asyncio_. It relies on the awesome pyodbc_ library and preserves the same look and
feel. Internally *aioodbc* employs threads to avoid blocking the event loop,
threads_ are not that as bad as you think!. Other drivers like motor_ use the
same approach.

**aioodbc** is fully compatible and tested with uvloop_. Take a look at the test
suite, all tests are executed with both the default event loop and uvloop_.


Basic Example
-------------

**aioodbc** is based on pyodbc_ and provides the same api, you just need
to use  ``yield from conn.f()`` or ``await conn.f()`` instead of ``conn.f()``

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


.. code:: python

    import asyncio

    import aioodbc


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

        cur = await conn.cursor()
        await cur.execute("SELECT 42 AS age;")
        rows = await cur.fetchall()
        print(rows)
        print(rows[0])
        print(rows[0].age)
        await cur.close()
        await conn.close()


    asyncio.run(test_example())


Connection Pool
---------------
Connection pooling is ported from aiopg_ and relies on PEP492_ features:

.. code:: python

    import asyncio

    import aioodbc


    async def test_pool():
        dsn = "Driver=SQLite3;Database=sqlite.db"
        pool = await aioodbc.create_pool(dsn=dsn)

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


    asyncio.run(test_pool())


Context Managers
----------------
`Pool`, `Connection` and `Cursor` objects support the context management
protocol:

.. code:: python

    import asyncio

    import aioodbc


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

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


    asyncio.run(test_example())


Installation
------------

In a linux environment pyodbc_ (hence *aioodbc*) requires the unixODBC_ library.
You can install it using your package manager, for example::

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

Then::

   pip install aioodbc


Run tests
---------
To run tests locally without docker, install `unixodbc` and `sqlite` driver::

      $ sudo apt-get install unixodbc
      $ sudo apt-get install libsqliteodbc

Create virtualenv and install package with requirements::

      $ pip install -r requirements-dev.txt

Run tests, lints etc::

      $ make fmt
      $ make lint
      $ make test


Other SQL Drivers
-----------------

* aiopg_ - asyncio client for PostgreSQL
* aiomysql_ - asyncio client form MySQL


Requirements
------------

* Python_ 3.7+
* pyodbc_
* uvloop_ (optional)


.. _Python: https://www.python.org
.. _asyncio: http://docs.python.org/3.4/library/asyncio.html
.. _pyodbc: https://github.com/mkleehammer/pyodbc
.. _uvloop: https://github.com/MagicStack/uvloop
.. _ODBC: https://en.wikipedia.org/wiki/Open_Database_Connectivity
.. _aiopg: https://github.com/aio-libs/aiopg
.. _aiomysql: https://github.com/aio-libs/aiomysql
.. _PEP492: https://www.python.org/dev/peps/pep-0492/
.. _unixODBC: http://www.unixodbc.org/
.. _threads: http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databases/
.. _docker: https://docs.docker.com/engine/installation/
.. _motor: https://emptysqua.re/blog/motor-0-7-beta/

Changes
-------
0.5.0 (2023-10-28)
^^^^^^^^^^^^^^^^^^
* Added support for python 3.12
* Bumped minimal supported version of pyodbc to 5.0.1
* Dropped aiodocker related testing to unlock python 3.12

0.4.1 (2023-10-28)
^^^^^^^^^^^^^^^^^^
* Implemented cursor setinputsizes.
* Implemented cursor fetchval.
* Added more type annotations.
* Added autocommit setter for cusror.


0.4.0 (2023-03-16)
^^^^^^^^^^^^^^^^^^
* Fixed compatibility with python 3.9+.
* Removed usage of explicit loop parameter.
* Added default read size parameter for cursor.
* Updated tests and CI scripts.
* Code base formatted with black.


0.3.3 (2019-07-05)
^^^^^^^^^^^^^^^^^^
* Parameter echo passed properly in cursor #185
* Close bad connections before returning back to pool #195

0.3.2 (2018-08-04)
^^^^^^^^^^^^^^^^^^
* Added basic documentation for after_created and ThreadPoolExecutor #176 (thanks @AlexHagerman)
* Cursor/connection context managers now rollback transaction on error,
  otherwise commit if autocommit=False #178 (thanks @julianit)


0.3.1 (2018-03-23)
^^^^^^^^^^^^^^^^^^
* Add after_create hook for connection configuration (thanks @lanfon72)


0.3.0 (2018-02-23)
^^^^^^^^^^^^^^^^^^
* Added optional pool connections recycling #167 (thanks @drpoggi)


0.2.0 (2017-06-24)
^^^^^^^^^^^^^^^^^^
* Fixed Cursor.execute returns a pyodbc.Cursor instead of itself #114
* Fixed __aiter__ to not be awaitable for python>=3.5.2 #113
* Tests now using aiodocker #106


0.1.0 (2017-04-30)
^^^^^^^^^^^^^^^^^^
* Fixed project version


0.0.4 (2017-04-30)
^^^^^^^^^^^^^^^^^^
* Improved mysql testing


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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aio-libs/aioodbc",
    "name": "aioodbc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Nikolay Novik",
    "author_email": "nickolainovik@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/45/87/3a7580938f217212a574ba0d1af78203fc278fc439815f3fc515a7fdc12b/aioodbc-0.5.0.tar.gz",
    "platform": "POSIX",
    "description": "aioodbc\n=======\n.. image:: https://github.com/aio-libs/aioodbc/workflows/CI/badge.svg\n   :target: https://github.com/aio-libs/aioodbc/actions?query=workflow%3ACI\n   :alt: GitHub Actions status for master branch\n.. image:: https://codecov.io/gh/aio-libs/aioodbc/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/aio-libs/aioodbc\n.. image:: https://img.shields.io/pypi/v/aioodbc.svg\n    :target: https://pypi.python.org/pypi/aioodbc\n.. image:: https://img.shields.io/pypi/pyversions/aioodbc.svg\n    :target: https://pypi.org/project/aioodbc\n.. image:: https://badges.gitter.im/Join%20Chat.svg\n    :target: https://gitter.im/aio-libs/Lobby\n    :alt: Chat on Gitter\n\n**aioodbc** is a Python 3.7+ module that makes it possible to access ODBC_ databases\nwith asyncio_. It relies on the awesome pyodbc_ library and preserves the same look and\nfeel. Internally *aioodbc* employs threads to avoid blocking the event loop,\nthreads_ are not that as bad as you think!. Other drivers like motor_ use the\nsame approach.\n\n**aioodbc** is fully compatible and tested with uvloop_. Take a look at the test\nsuite, all tests are executed with both the default event loop and uvloop_.\n\n\nBasic Example\n-------------\n\n**aioodbc** is based on pyodbc_ and provides the same api, you just need\nto use  ``yield from conn.f()`` or ``await conn.f()`` instead of ``conn.f()``\n\nProperties are unchanged, so ``conn.prop`` is correct as well as\n``conn.prop = val``.\n\n\n.. code:: python\n\n    import asyncio\n\n    import aioodbc\n\n\n    async def test_example():\n        dsn = \"Driver=SQLite;Database=sqlite.db\"\n        conn = await aioodbc.connect(dsn=dsn)\n\n        cur = await conn.cursor()\n        await cur.execute(\"SELECT 42 AS age;\")\n        rows = await cur.fetchall()\n        print(rows)\n        print(rows[0])\n        print(rows[0].age)\n        await cur.close()\n        await conn.close()\n\n\n    asyncio.run(test_example())\n\n\nConnection Pool\n---------------\nConnection pooling is ported from aiopg_ and relies on PEP492_ features:\n\n.. code:: python\n\n    import asyncio\n\n    import aioodbc\n\n\n    async def test_pool():\n        dsn = \"Driver=SQLite3;Database=sqlite.db\"\n        pool = await aioodbc.create_pool(dsn=dsn)\n\n        async with pool.acquire() as conn:\n            cur = await conn.cursor()\n            await cur.execute(\"SELECT 42;\")\n            r = await cur.fetchall()\n            print(r)\n            await cur.close()\n            await conn.close()\n        pool.close()\n        await pool.wait_closed()\n\n\n    asyncio.run(test_pool())\n\n\nContext Managers\n----------------\n`Pool`, `Connection` and `Cursor` objects support the context management\nprotocol:\n\n.. code:: python\n\n    import asyncio\n\n    import aioodbc\n\n\n    async def test_example():\n        dsn = \"Driver=SQLite;Database=sqlite.db\"\n\n        async with aioodbc.create_pool(dsn=dsn) as pool:\n            async with pool.acquire() as conn:\n                async with conn.cursor() as cur:\n                    await cur.execute(\"SELECT 42 AS age;\")\n                    val = await cur.fetchone()\n                    print(val)\n                    print(val.age)\n\n\n    asyncio.run(test_example())\n\n\nInstallation\n------------\n\nIn a linux environment pyodbc_ (hence *aioodbc*) requires the unixODBC_ library.\nYou can install it using your package manager, for example::\n\n      $ sudo apt-get install unixodbc\n      $ sudo apt-get install unixodbc-dev\n\nThen::\n\n   pip install aioodbc\n\n\nRun tests\n---------\nTo run tests locally without docker, install `unixodbc` and `sqlite` driver::\n\n      $ sudo apt-get install unixodbc\n      $ sudo apt-get install libsqliteodbc\n\nCreate virtualenv and install package with requirements::\n\n      $ pip install -r requirements-dev.txt\n\nRun tests, lints etc::\n\n      $ make fmt\n      $ make lint\n      $ make test\n\n\nOther SQL Drivers\n-----------------\n\n* aiopg_ - asyncio client for PostgreSQL\n* aiomysql_ - asyncio client form MySQL\n\n\nRequirements\n------------\n\n* Python_ 3.7+\n* pyodbc_\n* uvloop_ (optional)\n\n\n.. _Python: https://www.python.org\n.. _asyncio: http://docs.python.org/3.4/library/asyncio.html\n.. _pyodbc: https://github.com/mkleehammer/pyodbc\n.. _uvloop: https://github.com/MagicStack/uvloop\n.. _ODBC: https://en.wikipedia.org/wiki/Open_Database_Connectivity\n.. _aiopg: https://github.com/aio-libs/aiopg\n.. _aiomysql: https://github.com/aio-libs/aiomysql\n.. _PEP492: https://www.python.org/dev/peps/pep-0492/\n.. _unixODBC: http://www.unixodbc.org/\n.. _threads: http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databases/\n.. _docker: https://docs.docker.com/engine/installation/\n.. _motor: https://emptysqua.re/blog/motor-0-7-beta/\n\nChanges\n-------\n0.5.0 (2023-10-28)\n^^^^^^^^^^^^^^^^^^\n* Added support for python 3.12\n* Bumped minimal supported version of pyodbc to 5.0.1\n* Dropped aiodocker related testing to unlock python 3.12\n\n0.4.1 (2023-10-28)\n^^^^^^^^^^^^^^^^^^\n* Implemented cursor setinputsizes.\n* Implemented cursor fetchval.\n* Added more type annotations.\n* Added autocommit setter for cusror.\n\n\n0.4.0 (2023-03-16)\n^^^^^^^^^^^^^^^^^^\n* Fixed compatibility with python 3.9+.\n* Removed usage of explicit loop parameter.\n* Added default read size parameter for cursor.\n* Updated tests and CI scripts.\n* Code base formatted with black.\n\n\n0.3.3 (2019-07-05)\n^^^^^^^^^^^^^^^^^^\n* Parameter echo passed properly in cursor #185\n* Close bad connections before returning back to pool #195\n\n0.3.2 (2018-08-04)\n^^^^^^^^^^^^^^^^^^\n* Added basic documentation for after_created and ThreadPoolExecutor #176 (thanks @AlexHagerman)\n* Cursor/connection context managers now rollback transaction on error,\n  otherwise commit if autocommit=False #178 (thanks @julianit)\n\n\n0.3.1 (2018-03-23)\n^^^^^^^^^^^^^^^^^^\n* Add after_create hook for connection configuration (thanks @lanfon72)\n\n\n0.3.0 (2018-02-23)\n^^^^^^^^^^^^^^^^^^\n* Added optional pool connections recycling #167 (thanks @drpoggi)\n\n\n0.2.0 (2017-06-24)\n^^^^^^^^^^^^^^^^^^\n* Fixed Cursor.execute returns a pyodbc.Cursor instead of itself #114\n* Fixed __aiter__ to not be awaitable for python>=3.5.2 #113\n* Tests now using aiodocker #106\n\n\n0.1.0 (2017-04-30)\n^^^^^^^^^^^^^^^^^^\n* Fixed project version\n\n\n0.0.4 (2017-04-30)\n^^^^^^^^^^^^^^^^^^\n* Improved mysql testing\n\n\n0.0.3 (2016-07-05)\n^^^^^^^^^^^^^^^^^^\n* Dockerize tests, now we can add more DBs to tests using docker #15, #17, #19\n* Test suite executed with both default asyncio and uvloop #18\n\n\n0.0.2 (2016-01-01)\n^^^^^^^^^^^^^^^^^^\n* Improved pep 492 support.\n* pool.get method removed, use acquire instead.\n* Added tests against MySQL.\n* Added bunch of doc strings.\n\n\n0.0.1 (2015-10-12)\n^^^^^^^^^^^^^^^^^^\n* Initial release.\n",
    "bugtrack_url": null,
    "license": "Apache 2",
    "summary": "ODBC driver for asyncio.",
    "version": "0.5.0",
    "project_urls": {
        "Documentation": "https://uddsketch.readthedocs.io",
        "Download": "https://pypi.python.org/pypi/aioodbc",
        "Homepage": "https://github.com/aio-libs/aioodbc",
        "Issues": "https://github.com/jettify/uddsketch/issues",
        "Website": "https://github.com/jettify/uddsketch"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0804d1565bc16b53cd603c73dc4bc770e2e6418d957417e05031314760dc28c",
                "md5": "2ca3ee2417c6166fcd5db023548ecac6",
                "sha256": "bcaf16f007855fa4bf0ce6754b1f72c6c5a3d544188849577ddd55c5dc42985e"
            },
            "downloads": -1,
            "filename": "aioodbc-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2ca3ee2417c6166fcd5db023548ecac6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 19449,
            "upload_time": "2023-10-28T21:37:28",
            "upload_time_iso_8601": "2023-10-28T21:37:28.510573Z",
            "url": "https://files.pythonhosted.org/packages/b0/80/4d1565bc16b53cd603c73dc4bc770e2e6418d957417e05031314760dc28c/aioodbc-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45873a7580938f217212a574ba0d1af78203fc278fc439815f3fc515a7fdc12b",
                "md5": "d2577f645b6339328d9ca657ce8c8ddb",
                "sha256": "cbccd89ce595c033a49c9e6b4b55bbace7613a104b8a46e3d4c58c4bc4f25075"
            },
            "downloads": -1,
            "filename": "aioodbc-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d2577f645b6339328d9ca657ce8c8ddb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 41298,
            "upload_time": "2023-10-28T21:37:29",
            "upload_time_iso_8601": "2023-10-28T21:37:29.966287Z",
            "url": "https://files.pythonhosted.org/packages/45/87/3a7580938f217212a574ba0d1af78203fc278fc439815f3fc515a7fdc12b/aioodbc-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-28 21:37:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aio-libs",
    "github_project": "aioodbc",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "aioodbc"
}
        
Elapsed time: 0.14549s