Module for simple RPC service implementation
Project description
drakaina
{width=200px height=205px}
❗ WIP
Module for simple RPC service implementation
Quickstart
Drakaina may be installed via pip
and requires Python 3.7 or higher :
pip install drakaina
A minimal Drakaina example is:
from drakaina import remote_procedure
from drakaina.wsgi import WSGIHandler
@remote_procedure
def my_method():
return "Hello Bro! ✋️"
@remote_procedure(name="something.get")
def get_some_string():
return "You called `something.get`."
@remote_procedure(provide_request=True)
def do_something_with_environ(request):
return f"You called `do_something_with_environ`. Request: {request}."
@remote_procedure()
def tell_the_middleware_something():
return "You called `tell_the_middleware_something`. It has a some extra conditions."
async def asynchronous_procedure():
await asyncio.sleep(5)
return "Ding-Dong 🔔!"
"""
>>> JsonRPCv2().handle({"jsonrpc": "2.0", "method": "my_method", "id": 1})
or define WSGI application
"""
app = WSGIHandler(route="/jrpc")
Drakaina may be ran with any WSGI-compliant server, such as Gunicorn.
gunicorn main:app
Features
- WSGI protocol implementation
Documentation
Installation
pip install drakaina
Middlewares
CORS
JWT
Drakaina may be installed via pip
and requires Python 3.7 or higher :
pip install drakaina[jwt]
A minimal Drakaina example is:
from functools import partial
from drakaina import ENV_IS_AUTHENTICATED
from drakaina import ENV_USER_ID
from drakaina import remote_procedure
from drakaina.contrib.jwt import check_permissions
from drakaina.contrib.jwt import login_required
from drakaina.contrib.jwt import match_any
from drakaina.contrib.jwt.middleware import JWTAuthenticationMiddleware
from drakaina.wsgi import WSGIHandler
@login_required
@remote_procedure(provide_request=True)
def my_method(request):
assert request[ENV_IS_AUTHENTICATED]
return f"Hello Bro ✋! Your ID={request[ENV_USER_ID]}"
@check_permissions(
scopes=["user_read", "app/user:admin", "username:johndoe"],
comparison=match_any,
)
@remote_procedure
def my_method():
return "Hello Bro! ✋️"
app = WSGIHandler(
middlewares=[
partial(
JWTAuthenticationMiddleware,
secret_phrase="_secret_",
credentials_required=True,
)
]
)
License
Apache License 2.0
Artwork
"drakaina.png" by Korolko Anastasia is licensed under (CC BY-SA 4.0).
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
drakaina-0.5.2.tar.gz
(41.0 kB
view hashes)
Built Distribution
drakaina-0.5.2-py3-none-any.whl
(50.9 kB
view hashes)