Adapter for Celery that implements JSON-RPC 2.0 protocol.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file apyum-0.1.2.tar.gz
.
File metadata
- Download URL: apyum-0.1.2.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8760d265574f691598f75d67e81b01a34b90b8d85dc30bad1dbb244624a7d85d |
|
MD5 | 2ed8044914de20bb32ca3f4398254cd5 |
|
BLAKE2b-256 | 42d285581afadd552acb8c3a7d0076593508746f6c804dbf3eaaa4938637efb8 |
File details
Details for the file apyum-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: apyum-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 321545b3cfed6801c078fcf53519828e6bbb7c272cd17067f743d1cd01fe8fc5 |
|
MD5 | 319125a629533bf9e21872aa74fd71b0 |
|
BLAKE2b-256 | 27332c2462bfb3212bbe8146dd9145fb652bcfb709fe8a2e9a00a9d3f3ed1cd0 |