Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miguelgrinberg/greenletio
Asyncio integration with sync code using greenlets.
https://github.com/miguelgrinberg/greenletio
async-await asyncio greenlet
Last synced: 3 days ago
JSON representation
Asyncio integration with sync code using greenlets.
- Host: GitHub
- URL: https://github.com/miguelgrinberg/greenletio
- Owner: miguelgrinberg
- License: mit
- Created: 2020-07-15T11:36:43.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-27T23:43:29.000Z (8 months ago)
- Last Synced: 2024-05-02T04:53:20.132Z (8 months ago)
- Topics: async-await, asyncio, greenlet
- Language: Python
- Homepage:
- Size: 168 KB
- Stars: 148
- Watchers: 8
- Forks: 8
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# greenletio
[![Build status](https://github.com/miguelgrinberg/greenletio/workflows/build/badge.svg)](https://github.com/miguelgrinberg/greenletio/actions) [![codecov](https://codecov.io/gh/miguelgrinberg/greenletio/branch/main/graph/badge.svg)](https://codecov.io/gh/miguelgrinberg/greenletio)
This project allows synchronous and asynchronous functions to be used together.
Unlike other methods based on executors and thread or process pools,
`greenletio` allows synchronous functions to work like their asynchronous
counterparts, without the need to create expensive threads or processes.## Examples
The following are some of the possibilities when using `greenletio`.
### Convert a sync function into an awaitable
```python
import asyncio
from greenletio import async_@async_
def sync_function(arg):
passasync def async_function():
await sync_function(42)asyncio.run(async_function())
```### Use await inside a sync function
```python
from greenletio import await_async def async_function():
passdef sync_function():
await_(async_function())
```### Call an async function as a normal function
```python
from greenletio import await_@await_
async def async_function():
passdef sync_function():
async_function()
```## Resources
- [Documentation](http://greenletio.readthedocs.io/en/latest/)
- [PyPI](https://pypi.python.org/pypi/greenletio)
- [Change Log](https://github.com/miguelgrinberg/greenletio/blob/main/CHANGES.md)