Skip to main content

Fast as websocket easy as http

Project description

X-raptor

banner

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.

  • The server.py implementation can be found here.
  • The client.py implementation can be found here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xraptor-0.1.5b0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

xraptor-0.1.5b0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file xraptor-0.1.5b0.tar.gz.

File metadata

  • Download URL: xraptor-0.1.5b0.tar.gz
  • Upload date:
  • Size: 11.7 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

Hashes for xraptor-0.1.5b0.tar.gz
Algorithm Hash digest
SHA256 1602e822def81e30ef3cb381bb34c3e25290499b2838898c998151a4e7d54806
MD5 fb91adb4c253b9d60356c418660764ac
BLAKE2b-256 8e60c0d05fded4a3a5f2c78e24a04b45cabf9c46dbd181f8f664d17a188f9578

See more details on using hashes here.

File details

Details for the file xraptor-0.1.5b0-py3-none-any.whl.

File metadata

  • Download URL: xraptor-0.1.5b0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 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

Hashes for xraptor-0.1.5b0-py3-none-any.whl
Algorithm Hash digest
SHA256 aae527b3bd9f207ed7517c237b3a633ddd2a9bd24e07348a93cf5e8f518d3bca
MD5 fc4fc0b7b8c164d7abfe96f1ec43ff99
BLAKE2b-256 b33eaf2b8bf9b576c34c20f389b4c1876f616d215fa414ce653f22f7723c2204

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page