Skip to main content

Websockets ASGI framework as simple as it it.

Project description

Eventum ASGI

Eventum ASGI is a simple WebSocket ASGI framework for Python.

Description

Eventum ASGI is a lightweight, easy-to-use ASGI framework specifically designed for handling WebSocket connections. It provides a straightforward way to create WebSocket servers with event-based routing and middleware support.

Features

  • WebSocket connection handling
  • Event-based routing
  • Middleware support
  • Lifespan event management
  • Pydantic model validation for events and handhakes
  • HTTP response support
  • Connection flags management

Installation

You can install Eventum ASGI using pip:

pip install eventum-asgi

Quick Start

Here's a simple example of how to use Eventum ASGI:

from eventum_asgi import Eventum, WSConnection, Event

app = Eventum()

@app.handshake_route('/')
async def websocket_handler(connection: WSConnection):
    await connection.accept()

@app.event('user_registered')
async def message_handler(connection: WSConnection, event: dict):
    await connection.send_text(f"You said: {message}")

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

Handshake Routes

Handshake routes are used to handle WebSocket handshakes. They are defined using the handshake_route decorator and are responsible for accepting the WebSocket connection and sending the handshake response as well adding a connection to the loop where the application is waiting for events to be sent by the client.

@app.handshake_route('/')
async def websocket_handler(connection: WSConnection):
    await connection.accept()

Event Routes

Event routes are used to handle events sent by the client. They are defined using the event decorator and are responsible for handling the event and sending a response back to the client(optinal). All the events should be defined and send as JSON objects and contain an event name.

JSON

{
    "event": "user_registered",
    "data": {
        "username": "johndoe",
        "email": "johndoe@example.com",
        "password": "password123"
    }
}

Event decorator

@app.event('user_registered')
async def message_handler(connection: WSConnection, event: dict):
    await connection.send_text(f"You said: {message}")

Documentation

For more detailed information on how to use Eventum ASGI, please refer to our documentation (coming soon).

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

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

eventum_asgi-0.0.2.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

eventum_asgi-0.0.2-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file eventum_asgi-0.0.2.tar.gz.

File metadata

  • Download URL: eventum_asgi-0.0.2.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.5 Windows/10

File hashes

Hashes for eventum_asgi-0.0.2.tar.gz
Algorithm Hash digest
SHA256 01ac281e595b882f21eff6644c587e8b23ae5238749f81664803a57e45d37b1b
MD5 2b424deab84fd1c41fdb3584aa705697
BLAKE2b-256 c04f756bae77d64f4069db09c6f7f4976b9a7bed6a9d51d5ff9ea5d9a64be8f1

See more details on using hashes here.

File details

Details for the file eventum_asgi-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: eventum_asgi-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.5 Windows/10

File hashes

Hashes for eventum_asgi-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a63770ce262b3d292a69fc18d91515ab63b477bf0d6903193b787fba5e72590a
MD5 a3eab71a994458603941ea6bdbf9b95c
BLAKE2b-256 b69f5c3efa9f0ef1642868abac70881d9eb8346f0a1b5c4f6b5bddf05994ec3c

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