as-async
Small python library to unblock sync functions and generators
Installation
pip install as-async
Examples
basic usage
import time
import asyncio
from concurrent.futures import ThreadPoolExecutor
from as_async import as_async
@as_async()
def long_running_function():
time.sleep(5)
return "Finished"
async def main():
result = await long_running_function()
print(result)
asyncio.run(main())
specify loop and or executor
import time
import asyncio
from concurrent.futures import ThreadPoolExecutor
from as_async import as_async_generator
@as_async_generator(loop=asyncio.get_event_loop(), executor=ThreadPoolExecutor(max_workers=5))
def long_running_generator():
for i in range(5):
time.sleep(1) # Simulate a long-running operation
yield i
async def main():
async for value in long_running_generator():
print(value)
asyncio.run(main())
equivalents to the above without the decorator also exists
import time
import asyncio
from concurrent.futures import ThreadPoolExecutor
def long_running_function():
time.sleep(5)
return "Finished"
async def main():
async_func = to_async(long_running_function)
result = await async_func()
print(result)
asyncio.run(main())
License
This project is licensed under the MIT License - see the LICENSE file for details
Metadata
Release files for as-async 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| as-async-1.0.1.tar.gz | 4.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| as_async-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.1 kB
Release files / as-async-1.0.1.tar.gz
| Download URL | as-async-1.0.1.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c881d902128fd362f38c41c3a1e373f967c978f3cd87fcb0757780a001b96aa
|
|
BLAKE2b-256 checksum How to use checksums |
47f370a8e738fd6594f38bf11a93b4b9e9585575d5553d86529cfacb259d171b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.0
|
Release files / as_async-1.0.1-py3-none-any.whl
| Download URL | as_async-1.0.1-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
93d16a4eb49227979bbcecd4ec997d6193a9a2e60c40a0a00b73574f8f9ef2ed
|
|
BLAKE2b-256 checksum How to use checksums |
9c78812b255682bb220db0d4b83f7a39b92a2ff6f1904284d9782f364c2ed74e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.0
|