Apyum
Adapter for Celery that implements JSON-RPC 2.0 protocol.
Key Features
- Turns existing Celery implementation into a JSON RPC api
- Simple to run
- Implements JSON-RPC 2.0 protocol. (see https://www.jsonrpc.org)
- Support asyncio
Getting started
Create a yml config file (for example settings.yaml):
celery:
broker_url: "amqp://guest:guest@localhost:5672//"
result_backend: "rpc://"
result_persistent: False
...
logging:
...
The celery section is to be written as described by the Celery configuration (see https://docs.celeryproject.org/en/stable/userguide/configuration.html).
The logging section is optional and can be customized as described by the Python logging manual (see https://docs.python.org/3/library/logging.config.html).
To start Apyum launch standalone:
apyum settings.yml
This starts Apyum listening to 8080 port. For change listening port user parameter --port or to listen in a unix socket use parameter --path
Or start with gunicorn:
APYUM_SETTINGS=settings.yml gunicorn apyum.main:create --bind localhost:5000 --worker-class aiohttp.GunicornWebWorker --worker 4
Calling service example
Suppose we have defined some Celery tasks as myapp.tasks python module in a external worker like this: (tasks.py)
@app.task
def example_task_x(a, b, c):
...
@app.task
def example_task_y(a, b, c):
...
For running by JSON-RPC call we must send POST to http://localhost:8080/myapp/tasks with body:
{ "jsonrpc": "2.0", "method": "example_task_x", "params": { "a": 5, "b": 3, "c":1}, "id": "1" }
or
{ "jsonrpc": "2.0", "method": "example_task_x", "params": [ 5, 3, 1], "id": "1" }
or can be called on root by:
{ "jsonrpc": "2.0", "method": "myapp.tasks.example_task_x", "params": [ 5, 3, 1], "id": "1" }
The endpoints return response if have it. Also batch calls are supported:
[
{ "jsonrpc": "2.0", "method": "myapp.tasks.example_task_x", "params": [ 5, 3, 1], "id": "1" },
{ "jsonrpc": "2.0", "method": "myapp.tasks.example_task_y", "params": [ 1, 2, 1], "id": "2" },
{ "jsonrpc": "2.0", "method": "myapp.tasks.example_task_y", "params": [ 6, 1, 4], "id": "3" }
]
See JSON-RPC specification for more details.
Installation
It's very simple to install Apyum:
pip install apyum
To Do
- More tests
- Autentication requests
- Insert an api documentation (like https://open-rpc.org)
- Documentation and examples
Requirements
- Python >= 3.8
- Celery 5
License
apyum is offered under the Apache 2 license.
Source code
The latest developer version is available in a GitHub repository: https://github.com/aiselis/apyum
Metadata
Release files for apyum 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| apyum-0.1.2.tar.gz | 11.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| apyum-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.1 kB
Release files / apyum-0.1.2.tar.gz
| Download URL | apyum-0.1.2.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8760d265574f691598f75d67e81b01a34b90b8d85dc30bad1dbb244624a7d85d
|
|
BLAKE2b-256 checksum How to use checksums |
42d285581afadd552acb8c3a7d0076593508746f6c804dbf3eaaa4938637efb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.55.2 CPython/3.9.1
|
Release files / apyum-0.1.2-py3-none-any.whl
| Download URL | apyum-0.1.2-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
321545b3cfed6801c078fcf53519828e6bbb7c272cd17067f743d1cd01fe8fc5
|
|
BLAKE2b-256 checksum How to use checksums |
27332c2462bfb3212bbe8146dd9145fb652bcfb709fe8a2e9a00a9d3f3ed1cd0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.55.2 CPython/3.9.1
|