kode_rpc
Server Usage
from typing import Mapping
import asyncio
import logging
from kode_rpc.method import RPCMethod, method
from kode_rpc.server import RPCServer, RPCRequestInfo
@method(version=1)
async def some_rpc_method(param: str):
return {'result': True}
async def rpc_logger(rpc_method: RPCMethod, result: Mapping, request_info: RPCRequestInfo):
logging.info('rpc_log', extra={
'rpc_name': rpc_method.name,
'rpc_result': result,
'trace_id': request_info.trace_id,
'master': request_info.master
})
async def rpc_exception_handler(rpc_method: RPCMethod, exc: BaseException, request_info: RPCRequestInfo) -> Mapping:
if isinstance(exc, RuntimeError):
return {
'error': {
'code': 'RuntimeError',
'trace_id': request_info.trace_id
}
}
else:
return {
'error': {
'code': 'ServerError',
'trace_id': request_info.trace_id
}
}
async def main():
logging.basicConfig(level=logging.INFO)
server = RPCServer('my_service', rabbitmq_host='localhost', rabbitmq_user='guest', rabbitmq_password='guest')
server.method_logger(rpc_logger)
server.method_exception_handler(rpc_exception_handler)
await server.register_methods([some_rpc_method])
await server.serve()
if __name__ == '__main__':
asyncio.run(main())
Client Usage
import asyncio
from kode_rpc.client import RPCClient
# To access rpc_client from anywhere it must be initialized at top level module
rpc_client = RPCClient('client_name')
async def main():
# Connect to rpc broker once at startup
await rpc_client.connect(rabbitmq_host='localhost', rabbitmq_user='guest', rabbitmq_password='guest')
# ...
# Somewhere in logic
result = await rpc_client.call(
service_name='my_service',
method='rpc_method',
payload={'param': 'any'}
)
# => {'result': True}
# When application is shutting down do not forget to disconnect from rpc broker
await rpc_client.disconnect()
if __name__ == '__main__':
asyncio.run(main())
Metadata
Release files for kode-rpc 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kode_rpc-0.0.8.tar.gz | 5.1 kB | Without provenance | Details for kode_rpc-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kode_rpc-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for kode_rpc-0.0.8-py3-none-any.whl |
Total release size: 12.0 kB
Release files / kode_rpc-0.0.8.tar.gz
| Download URL | kode_rpc-0.0.8.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
496f4de686f412182752c1a1bcde1a184313f4793482a6b5597af4c85e34e1b2
|
|
BLAKE2b-256 checksum How to use checksums |
3c029a04a29dcd15a6a8d8092d2a47a9030b67ef1abac75d6ce5aed73989d612
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
|
Release files / kode_rpc-0.0.8-py3-none-any.whl
| Download URL | kode_rpc-0.0.8-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc2146e3249ffa215583c34137ac02b02245158632781361d0b72232d809d325
|
|
BLAKE2b-256 checksum How to use checksums |
857ae952227df525a3fb7afb3679877f4c6685d18b7b01309706b482507822f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
|
Security for kode-rpc 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.