Fast as websocket easy as http
Project description
X-raptor
By: CenturyBoys
⚠️ Fast as a hell, CAUTION!!!
This package is being developed and is in the testing process. 🚨 NOT USE THIS PACKAGE IN PRODUCTION !!!
Fast as websocket easy as http, this package is an abstraction of websockets package
to allow user to register get
, post
, sub
, unsub
asynchronous callbacks. For this all message must be a requests or a response object.
import xraptor
_xraptor = xraptor.XRaptor("localhost", 8765)
@_xraptor.register("/send_message_to_chat_room").as_post
async def send_message(
request: xraptor.Request
) -> xraptor.Response:
...
return xraptor.Response(
request_id=request.request_id,
header={},
payload='{"message": "Message sent"}'
)
To allow multiple asynchronous responses on routes X-raptor use the request_id
as antenna. Those antennas are pubsub channels that yield
string messages.
Antenna
There is no default antenna configuration, you have two options implements your own antenna class using the interface or use one of the extra packages.
from abc import ABC, abstractmethod
from typing import AsyncIterator, Awaitable
class Antenna(ABC):
@abstractmethod
def subscribe(self, key: str) -> AsyncIterator[str]:
"""
async generator that will yield message from the key's channel
:param key: pubsub channel
:return: str message async generator
"""
@abstractmethod
def post(self, key: str, message: str) -> Awaitable:
"""
async function that will publish a message to a key's channel
:param key: pubsub channel
:param message: message
:return:
"""
@abstractmethod
def is_alive(self, antenna_id: str) -> Awaitable[bool]:
"""
verify that antenna_id still alive
:param antenna_id:
:return:
"""
Broadcast
Extras
Redis
This extra add the redis package in version ^5.0.8
.
How to install extra packages?
poetry add xraptor -E redis_edition
OR
pip install 'xraptor[redis_edition]'
You need pass the X_RAPTOR_REDIS_URL
parameter on configuration
Full Example
A very simple chat implementation was created to test sub
, poss
and unsub
routes.
The test work using the redis_edition
.
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 xraptor-0.1.3b0.tar.gz
.
File metadata
- Download URL: xraptor-0.1.3b0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.1.0-23-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcf7e542b6e77b252b63b23ccec0278364b141eed2370fff1028e451316c47b0 |
|
MD5 | cd369d73ffa7a756031d3c54166067e4 |
|
BLAKE2b-256 | eb0afdd18662e0cec61b8cda25e312894e221d359313f22eb1a21ecd3b33a1cc |
File details
Details for the file xraptor-0.1.3b0-py3-none-any.whl
.
File metadata
- Download URL: xraptor-0.1.3b0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.1.0-23-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 725cf937b6d91cecf8951803c03afbc61be1ec9f700adbafd14f46c010c93034 |
|
MD5 | 082f871a477c582f43e203162af68e7f |
|
BLAKE2b-256 | f094a216c90c9edc2f7c2c200d812f2eed785312872e7d867845dd8e0e272a82 |