Skip to content

Commit 34db231

Browse files
committed
Updated README.md.
Signed-off-by: Pavel Kirilin <[email protected]>
1 parent 7f63c42 commit 34db231

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

README.md

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
<hr/>
88
</div>
99

10+
Documentation: https://taskiq-python.github.io/
11+
12+
## What is taskiq?
13+
1014
Taskiq is an asynchronous distributed task queue for python.
1115
This project takes inspiration from big projects such as [Celery](https://docs.celeryq.dev) and [Dramatiq](https://dramatiq.io/).
12-
But taskiq can send and run both the sync and async functions.
13-
Also, we use [PEP-612](https://peps.python.org/pep-0612/) to provide the best autosuggestions possible. But since it's a new PEP, I encourage you to use taskiq with VS code because Pylance understands all types correctly.
16+
But taskiq can send and run both the sync and async functions, has
17+
integration with popular async frameworks, such as [FastAPI](https://fastapi.tiangolo.com/) and [AioHTTP](https://docs.aiohttp.org/en/stable/).
18+
19+
Also, we use [PEP-612](https://peps.python.org/pep-0612/) to provide the best autosuggestions possible. All code is type-hinted.
1420

1521
# Installation
1622

@@ -25,8 +31,69 @@ Or it can be installed directly from git:
2531
pip install git+https://github.com/taskiq-python/taskiq
2632
```
2733

28-
You can read more about how to use it in our docs: https://taskiq-python.github.io/.
34+
# Usage
35+
36+
At first you need to create a broker. Broker is an object that can communicate to workers using distributed queues.
37+
38+
We have differet brokers for different queue backends. For example, we have a broker for [NATS](https://github.com/taskiq-python/taskiq-nats), [Redis](https://github.com/taskiq-python/taskiq-redis), [RabbitMQ](https://github.com/taskiq-python/taskiq-aio-pika), [Kafka](https://github.com/taskiq-python/taskiq-aio-kafka) and even more. Choose the one that fits you and create an instance.
39+
40+
```python
41+
from taskiq_nats import JetStreamBroker
42+
43+
broker = JetStreamBroker("nats://localhost:4222", queue="my_queue")
44+
```
45+
46+
Declaring tasks is as easy as declaring a function. Just add a decorator to your function and you are ready to go.
47+
48+
```python
49+
import asyncio
50+
51+
from taskiq_nats import JetStreamBroker
52+
53+
broker = JetStreamBroker("nats://localhost:4222", queue="my_queue2")
54+
55+
56+
@broker.task
57+
async def my_task(a: int, b: int) -> None:
58+
print("AB", a + b)
59+
60+
61+
async def main():
62+
await broker.startup()
63+
64+
await my_task.kiq(1, 2)
65+
66+
await broker.shutdown()
67+
68+
69+
if __name__ == "__main__":
70+
asyncio.run(main())
71+
72+
73+
```
74+
75+
The message is going to be sent to the broker and then to the worker. The worker will execute the function. To start worker processes, just run the following command:
76+
77+
```bash
78+
taskiq worker path.to.the.module:broker
79+
```
80+
81+
Where `path.to.the.module` is the path to the module where the broker is defined and `broker` is the name of the broker variable.
82+
83+
If you have tasks in different modules, you can ask taskiq to automatically import them by passing the `--fs-discover` flag:
84+
85+
```bash
86+
taskiq worker path.to.the.module:broker --fs-discover
87+
```
88+
89+
It will import all modules called `tasks.py` in the current directory and all subdirectories.
90+
91+
Also, we support hot reload for workers. To enable it, just pass the `--reload` flag. It will reload the worker when the code changes (To use it, install taskiq with reload extra. E.g `pip install taskiq[reload]`).
92+
93+
94+
Also, we have cool integrations with popular async frameworks. For example, we have an integration with [FastAPI](https://taskiq-python.github.io/framework_integrations/taskiq-with-fastapi.html) or [AioHTTP](https://taskiq-python.github.io/framework_integrations/taskiq-with-aiohttp.html). You can use it to reuse dependencies from your web app in your tasks.
2995

96+
Read about all features in our documentation: https://taskiq-python.github.io/
3097

3198
# Local development
3299

0 commit comments

Comments
 (0)