sqlalchemy_aio
==============
|PyPI Version| |Documentation| |Travis| |Coverage| |MIT License|
``sqlalchemy_aio`` adds asyncio and `Trio`_ support to SQLAlchemy core, derived
from `alchimia`_.
.. _alchimia: https://github.com/alex/alchimia
.. _Trio: https://github.com/python-trio/trio
Getting started
---------------
.. code-block:: python
import asyncio
from sqlalchemy_aio import ASYNCIO_STRATEGY
from sqlalchemy import (
Column, Integer, MetaData, Table, Text, create_engine, select)
from sqlalchemy.schema import CreateTable, DropTable
async def main():
engine = create_engine(
# In-memory sqlite database cannot be accessed from different
# threads, use file.
'sqlite:///test.db', strategy=ASYNCIO_STRATEGY
)
metadata = MetaData()
users = Table(
'users', metadata,
Column('id', Integer, primary_key=True),
Column('name', Text),
)
# Create the table
await engine.execute(CreateTable(users))
conn = await engine.connect()
# Insert some users
await conn.execute(users.insert().values(name='Jeremy Goodwin'))
await conn.execute(users.insert().values(name='Natalie Hurley'))
await conn.execute(users.insert().values(name='Dan Rydell'))
await conn.execute(users.insert().values(name='Casey McCall'))
await conn.execute(users.insert().values(name='Dana Whitaker'))
result = await conn.execute(users.select(users.c.name.startswith('D')))
d_users = await result.fetchall()
await conn.close()
# Print out the users
for user in d_users:
print('Username: %s' % user[users.c.name])
# Supports context async managers
async with engine.connect() as conn:
async with conn.begin() as trans:
assert await conn.scalar(select([1])) == 1
await engine.execute(DropTable(users))
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Getting started with Trio
-------------------------
To use the above example with `Trio`_, just change the following:
.. code-block:: python
import trio
from sqlalchemy_aio import TRIO_STRATEGY
async def main():
engine = create_engine('sqlite:///test.db', strategy=TRIO_STRATEGY)
...
trio.run(main)
What is this?
-------------
It's *not* an ``asyncio`` implementation of SQLAlchemy or the drivers it uses.
``sqlalchemy_aio`` lets you use SQLAlchemy by running operations in a separate
thread.
If you're already using `run_in_executor`_ to execute SQLAlchemy tasks,
``sqlalchemy_aio`` will work well with similar performance. If performance is
critical, perhaps `asyncpg`_ can help.
.. _asyncpg: https://github.com/MagicStack/asyncpg
.. _`run_in_executor`: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.run_in_executor
Documentation
-------------
`The documentation`_ has more information, including limitations of the API.
.. _The documentation: https://sqlalchemy-aio.readthedocs.io/en/latest/
.. |PyPI Version| image:: https://img.shields.io/pypi/v/sqlalchemy_aio.svg?style=flat-square
:target: https://pypi.python.org/pypi/sqlalchemy_aio/
.. |Documentation| image:: https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat-square
:target: https://sqlalchemy-aio.readthedocs.io/en/latest/
.. |Travis| image:: http://img.shields.io/travis/RazerM/sqlalchemy_aio/master.svg?style=flat-square&label=travis
:target: https://travis-ci.org/RazerM/sqlalchemy_aio
.. |Coverage| image:: https://img.shields.io/codecov/c/github/RazerM/sqlalchemy_aio/master.svg?style=flat-square
:target: https://codecov.io/github/RazerM/sqlalchemy_aio?branch=master
.. |MIT License| image:: http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
:target: https://raw.githubusercontent.com/RazerM/sqlalchemy_aio/master/LICENSE
Raw data
{
"_id": null,
"home_page": "https://github.com/RazerM/sqlalchemy_aio",
"name": "sqlalchemy-aio",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Frazer McLean",
"author_email": "frazer@frazermclean.co.uk",
"download_url": "https://files.pythonhosted.org/packages/73/ac/817e18bdd735a4e9bf4a2d6a25229dfe50847fd072249d500a06b588b0a5/sqlalchemy_aio-0.17.0.tar.gz",
"platform": "",
"description": "sqlalchemy_aio\n==============\n\n|PyPI Version| |Documentation| |Travis| |Coverage| |MIT License|\n\n``sqlalchemy_aio`` adds asyncio and `Trio`_ support to SQLAlchemy core, derived\nfrom `alchimia`_.\n\n.. _alchimia: https://github.com/alex/alchimia\n.. _Trio: https://github.com/python-trio/trio\n\n\nGetting started\n---------------\n\n.. code-block:: python\n\n import asyncio\n\n from sqlalchemy_aio import ASYNCIO_STRATEGY\n\n from sqlalchemy import (\n Column, Integer, MetaData, Table, Text, create_engine, select)\n from sqlalchemy.schema import CreateTable, DropTable\n\n\n async def main():\n engine = create_engine(\n # In-memory sqlite database cannot be accessed from different\n # threads, use file.\n 'sqlite:///test.db', strategy=ASYNCIO_STRATEGY\n )\n\n metadata = MetaData()\n users = Table(\n 'users', metadata,\n Column('id', Integer, primary_key=True),\n Column('name', Text),\n )\n\n # Create the table\n await engine.execute(CreateTable(users))\n\n conn = await engine.connect()\n\n # Insert some users\n await conn.execute(users.insert().values(name='Jeremy Goodwin'))\n await conn.execute(users.insert().values(name='Natalie Hurley'))\n await conn.execute(users.insert().values(name='Dan Rydell'))\n await conn.execute(users.insert().values(name='Casey McCall'))\n await conn.execute(users.insert().values(name='Dana Whitaker'))\n\n result = await conn.execute(users.select(users.c.name.startswith('D')))\n d_users = await result.fetchall()\n\n await conn.close()\n\n # Print out the users\n for user in d_users:\n print('Username: %s' % user[users.c.name])\n\n # Supports context async managers\n async with engine.connect() as conn:\n async with conn.begin() as trans:\n assert await conn.scalar(select([1])) == 1\n\n await engine.execute(DropTable(users))\n\n\n if __name__ == '__main__':\n loop = asyncio.get_event_loop()\n loop.run_until_complete(main())\n\nGetting started with Trio\n-------------------------\n\nTo use the above example with `Trio`_, just change the following:\n\n.. code-block:: python\n\n import trio\n from sqlalchemy_aio import TRIO_STRATEGY\n\n async def main():\n engine = create_engine('sqlite:///test.db', strategy=TRIO_STRATEGY)\n\n ...\n\n trio.run(main)\n\nWhat is this?\n-------------\n\nIt's *not* an ``asyncio`` implementation of SQLAlchemy or the drivers it uses.\n``sqlalchemy_aio`` lets you use SQLAlchemy by running operations in a separate\nthread.\n\nIf you're already using `run_in_executor`_ to execute SQLAlchemy tasks,\n``sqlalchemy_aio`` will work well with similar performance. If performance is\ncritical, perhaps `asyncpg`_ can help.\n\n.. _asyncpg: https://github.com/MagicStack/asyncpg\n.. _`run_in_executor`: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.run_in_executor\n\nDocumentation\n-------------\n\n`The documentation`_ has more information, including limitations of the API.\n\n.. _The documentation: https://sqlalchemy-aio.readthedocs.io/en/latest/\n\n\n.. |PyPI Version| image:: https://img.shields.io/pypi/v/sqlalchemy_aio.svg?style=flat-square\n :target: https://pypi.python.org/pypi/sqlalchemy_aio/\n.. |Documentation| image:: https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat-square\n :target: https://sqlalchemy-aio.readthedocs.io/en/latest/\n.. |Travis| image:: http://img.shields.io/travis/RazerM/sqlalchemy_aio/master.svg?style=flat-square&label=travis\n :target: https://travis-ci.org/RazerM/sqlalchemy_aio\n.. |Coverage| image:: https://img.shields.io/codecov/c/github/RazerM/sqlalchemy_aio/master.svg?style=flat-square\n :target: https://codecov.io/github/RazerM/sqlalchemy_aio?branch=master\n.. |MIT License| image:: http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square\n :target: https://raw.githubusercontent.com/RazerM/sqlalchemy_aio/master/LICENSE\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Async support for SQLAlchemy.",
"version": "0.17.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "ce092c120bd5bda11cd141c18eba45a4",
"sha256": "3f4aa392c38f032d6734826a4138a0f02ed3122d442ed142be1e5964f2a33b60"
},
"downloads": -1,
"filename": "sqlalchemy_aio-0.17.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ce092c120bd5bda11cd141c18eba45a4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 20757,
"upload_time": "2022-02-14T21:42:36",
"upload_time_iso_8601": "2022-02-14T21:42:36.811040Z",
"url": "https://files.pythonhosted.org/packages/0b/06/6a5e9301bbaca31d3a50938a074e053adf4a44b0dc58afa4d0e4c37b9eb9/sqlalchemy_aio-0.17.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "51a62f015acd042093ed6fcd8d25a60e",
"sha256": "f531c7982662d71dfc0b117e77bb2ed544e25cd5361e76cf9f5208edcfb71f7b"
},
"downloads": -1,
"filename": "sqlalchemy_aio-0.17.0.tar.gz",
"has_sig": false,
"md5_digest": "51a62f015acd042093ed6fcd8d25a60e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 15506,
"upload_time": "2022-02-14T21:42:38",
"upload_time_iso_8601": "2022-02-14T21:42:38.458336Z",
"url": "https://files.pythonhosted.org/packages/73/ac/817e18bdd735a4e9bf4a2d6a25229dfe50847fd072249d500a06b588b0a5/sqlalchemy_aio-0.17.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-02-14 21:42:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "RazerM",
"github_project": "sqlalchemy_aio",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "sqlalchemy-aio"
}