{"id":13482056,"url":"https://github.com/aio-libs/aioodbc","last_synced_at":"2025-03-27T12:32:06.775Z","repository":{"id":38375331,"uuid":"39036054","full_name":"aio-libs/aioodbc","owner":"aio-libs","description":"aioodbc - is a library for accessing a ODBC databases from the asyncio","archived":false,"fork":false,"pushed_at":"2023-10-28T21:35:34.000Z","size":420,"stargazers_count":312,"open_issues_count":30,"forks_count":59,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-08T05:48:30.751Z","etag":null,"topics":["async-await","asyncio","hacktoberfest","mysql","odbc","oracle","postgresql","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aio-libs.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.txt","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-07-13T20:38:58.000Z","updated_at":"2025-02-27T21:15:10.000Z","dependencies_parsed_at":"2022-07-12T01:47:36.024Z","dependency_job_id":"7e58dc4f-22dd-47d9-a5b0-48541802b366","html_url":"https://github.com/aio-libs/aioodbc","commit_stats":{"total_commits":529,"total_committers":22,"mean_commits":"24.045454545454547","dds":0.7107750472589792,"last_synced_commit":"5f23dfb227fd07654aa94f5059354efe65423158"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faioodbc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faioodbc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faioodbc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faioodbc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aio-libs","download_url":"https://codeload.github.com/aio-libs/aioodbc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245845194,"owners_count":20681858,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async-await","asyncio","hacktoberfest","mysql","odbc","oracle","postgresql","sqlite"],"created_at":"2024-07-31T17:00:58.563Z","updated_at":"2025-03-27T12:32:06.496Z","avatar_url":"https://github.com/aio-libs.png","language":"Python","funding_links":[],"categories":["Database Drivers","Python","数据库驱动"],"sub_categories":[],"readme":"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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Faioodbc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faio-libs%2Faioodbc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Faioodbc/lists"}