https://github.com/sqlalchemy/awaitlet
invoke asyncio awaitables from non-async functions
https://github.com/sqlalchemy/awaitlet
Last synced: 7 months ago
JSON representation
invoke asyncio awaitables from non-async functions
- Host: GitHub
- URL: https://github.com/sqlalchemy/awaitlet
- Owner: sqlalchemy
- License: mit
- Created: 2024-06-12T18:10:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-01T13:24:52.000Z (over 1 year ago)
- Last Synced: 2025-05-21T04:27:53.016Z (9 months ago)
- Language: Python
- Size: 113 KB
- Stars: 57
- Watchers: 3
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
========
awaitlet
========
Allow non-async defs that invoke awaitables inside of asyncio applications.
awaitlet allows existing programs written to use threads and blocking
APIs to be ported to asyncio, by replacing frontend and backend code with
asyncio compatible approaches, but allowing intermediary code to remain
completely unchanged. Its primary use is to support code that is cross-compatible
with asyncio and non-asyncio runtime environments.
The entire API demonstrated in three lines, where a non ``async`` def can
be invoked in an asyncio context and can then call upon real awaitables
directly::
import asyncio
import awaitlet
def asyncio_sleep():
return awaitlet.awaitlet(asyncio.sleep(5, result='hello'))
print(asyncio.run(awaitlet.async_def(asyncio_sleep)))
awaitlet is spun out from SQLAlchemy's own `asyncio mediation layer
`_, with no
dependencies on SQLAlchemy itself. awaitlet may be compared with another
equivalent library `greenback `_ which was
released at roughly the same time as SQLAlchemy's asyncio API.
awaitlet is intentionally fully compatible with SQLAlchemy's asyncio mediation
layer, and includes API patterns for:
* Converting any threaded program (no SQLAlchemy dependency necessary) to use
asyncio patterns for front facing APIs and backends, without modifying
intermediary code
* Converting threaded database-enabled programs to use asyncio patterns for
front facing APIs and backends, where those backends use SQLAlchemy's asyncio
API for database access
* Converting threaded database-enabled programs to use asyncio patterns for
front facing APIs and backends, without modifying intermediary code that uses
SQLAlchemy's synchronous API for database access
Documentation for awaitlet is within this source distribution and availble on
the web at https://awaitlet.sqlalchemy.org .