Crate is a lightweight Python (3.5) coroutine worker (ร la Celery) to allow asynchronous tasks into your application.
Create your my_crate.py into your project:
import asyncio
from datetime import datetime
from crate import Crate
app = Crate()
@app.task
async def hello_world(waiting: int=2) -> None:
print('[{}] Hello world!'.format(datetime.now()))
await asyncio.sleep(waiting)
print('[{}] Wumba lumba dub dub...'.format(datetime.now()))
And run your worker:
crate --app my_crate:app
You can call tasks in two different ways:
# If you have access to task code
from my_crate import hello_world
hello_world.delay()
# Or just task name
from crate import Crate
app = Crate()
app.send_task('hello_world')
Some examples in example.py.
Want to do file system I/O? aiofiles
Want to do http requests? aiohttp
Want to do postgresql? aiopg
License is MIT.