No project description provided
Project description
Note: The main idea of the project is based on RabbitMQ RPC, so RabbitMQ must be installed. Please keep it mind.
Get started
Simple RPC client using FastAPI
client.py
import asyncio
from fastapi import FastAPI, Depends, status
from rpc_call.async_client import RPCClient
from rpc_call.types import Task, TaskResult
app = FastAPI()
async def rpc_connection() -> RPCClient:
return await RPCClient(
amqp_dsn = "amqp://<client>:<passwd>@<host>:<port>/<vhost>",
queue_name = "<RabbitMQQueueName>"
).connect()
@app.post("/RPCEndpoint", response_model=TaskResult)
async def read_users(task: Task, rpc_conn: RPCClient = Depends(rpc_connection)) -> TaskResult:
task_result = await rpc_conn.call(task)
return task_result
$ uvicorn client:app --host 0.0.0.0 --port 8000 --reload
Simple RPC server
server.py
from rpc_call.server import RPCServer
class CallbackHandler:
def test_func(self, arg: str) -> str:
return f"test_func('{arg}') call result"
if __name__ == "__main__":
RPCServer(
amqp_dsn = "amqp://<client>:<passwd>@<host>:<port>/<vhost>",
queue_name = "<RabbitMQQueueName>",
callback_handler = CallbackHandler
)
$ python server.py
Usage
curl -X 'POST' \
'http://127.0.0.1:8000/RPCEndpoint' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"procedure": "test_func",
"kwargs": {"arg": "Hello world!"}
}'
And the response will be:
{
"status_code": 200,
"result": {
"test_func": "test_func('Hello world!') call result"
}
}
So now, with this elegant and simple library, you can call your code remotely! 👏 Good luck! 😉
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
rpc_call-0.1.5.tar.gz
(4.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rpc_call-0.1.5.tar.gz.
File metadata
- Download URL: rpc_call-0.1.5.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.7.16 Linux/5.10.102.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2e7756331b7b23ebb18ba9bd1aa99c966c42a4ba49977726af3e42fa6cac684
|
|
| MD5 |
0b09b677f5fa0f4063f46dc7ce3276b4
|
|
| BLAKE2b-256 |
8625c846abc4e43ef9777197aaa8327103077c4d2a2d764a8f3c605786cab22d
|
File details
Details for the file rpc_call-0.1.5-py3-none-any.whl.
File metadata
- Download URL: rpc_call-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.7.16 Linux/5.10.102.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94ee8878ab26ceeab6c1026b2cc20e2fb4f32f059fe970cf08067d8146b1d123
|
|
| MD5 |
9e1bc1321d4381da91ab5bce6b76face
|
|
| BLAKE2b-256 |
06ac465883ba346ebbb39e6f8821b25ca58a60497089976fb048c0fb9145cfd9
|