Kohlrabi is a asynchronous task queue for Python applications. It runs on top of a Redis server, and fits in with any existing application that runs on Python 3.3 or higher. It allows easy converting of parts of applications to asyncio-compatible parts, without affecting any normal blocking code.
Installation
Kohlrabi is available on PyPI to install easily:
pip install kohlrabi
Or, you can install it from GitHub directly:
pip install https://github.com/SunDwarf/Kohlrabi.git@master
Usage
Kohlrabi comes in two parts - the client and the server.
A single object is shared by both sides, and should be defined in your main file.
kh = kohlrabi.Kohlrabi()
When running the server, this object must be specified in a specific format on the command line:
kohlrabi-server yourapp.mainfile:kh
In your app code, using Kohlrabi is incredibly simple.
Creating tasks
To create a task, simply decorate a function with Kohlrabi task decorator.
@kh.task
def hello():
print("Hello, world!")
Then, inside your main method (or __name__ check), call the task as if it was a function.
if __name__ == "__main__":
hello()
If you check the console of the server process, it will have printed Hello, world!.
More advanced tasks
An example of a more advanced task would be an addition task.
@kh.task
def add(a, b):
return a + b
Inside your main method, call the add task with the parameters chosen:
fut = add(1, 2)
This returns a ClientTaskResult object, which you can use to get the result of the task.
print("Added together 1 and 2 to get:", fut.result)
Note that ClientTaskResult.result is blocking, and will wait until the task has finished to get the result of the task. If you wish to only wait a certain amount of time, use the ClientTaskResult.result_with_timeout method.
print("Added together 1 and 2 to get:", fut.result_with_timeout(1))
Chaining tasks
If you wish to chain tasks together, use the yield from keywords. On the server side, a task is just a wrapped coroutine, meaning you can use it as if it was a coroutine.
@kh.task
def add_two(a):
return a + 2
@kh.task
def get_four():
four = yield from add_two(2)
return four
Metadata
Release files for Kohlrabi 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| Kohlrabi-1.0.0.tar.gz | 6.7 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Kohlrabi-1.0.0.linux-x86_64.tar.gz | Details | |||
| Kohlrabi-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.6 kB
Release files / Kohlrabi-1.0.0.tar.gz
| Download URL | Kohlrabi-1.0.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0fad419b1f33ef5787f18aa3891d9269c8d9295ff4df3e48893b32e49e897635
|
|
BLAKE2b-256 checksum How to use checksums |
854d9fe2c64d72a594df5281121306192f29b50e18c29fb7ef574ab7ca989a28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / Kohlrabi-1.0.0.linux-x86_64.tar.gz
| Download URL | Kohlrabi-1.0.0.linux-x86_64.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9dddbf0432bc82f1a21509a8c81cb52db934ba67c47a1da761f8c32716ea7a1
|
|
BLAKE2b-256 checksum How to use checksums |
ff755179669547809d12e199002e505728abee3fd99f0cecd92bcc686f50f3f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / Kohlrabi-1.0.0-py3-none-any.whl
| Download URL | Kohlrabi-1.0.0-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
500e6cff1c1cfe62637358ec76a10a2893c5eb7eed1010db6b126202fc79b855
|
|
BLAKE2b-256 checksum How to use checksums |
fbda753e44c4ce3b9515c9a9de5f4ad75d90da88c2a72168960ffacd957add8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |