Skip to main content

A simple web server with websocket support based on starlette and uvicorn

Project description

from moonlette.ws_request_context import WSRequestContext

moonlette

A simple web server with websockets support based on starlette, uvicorn and authlib.

This library adapts the asynchronous websocket ASGI API to offer a synchronous thread-based API

Installation

pip install moonlette

Example usage (http)

from moonlette.http_request_context import HTTPRequestContext
from moonlette.server import Server

server = Server(port=8081, host="localhost")


def handler(request_context: HTTPRequestContext):
    return (200, b"It Worked!", "text/plain", {})


server.attach_handler("GET", "/test", handler)
server.run()

Example usage (websockets)

from moonlette.server import Server
from moonlette.ws_request_context import WSRequestContext

server = Server(port=8081, host="localhost")

class EchoHandler:

    def __init__(self, ctx:WSRequestContext):
        self.ctx = ctx

    def recv(self, msg):
        # echo the message back
        self.ctx.sender(msg)
        
server.attach_ws_handler("/echo", EchoHandler)
server.run()

Documentation

Coming Soon

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

moonlette-0.0.3.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moonlette-0.0.3-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file moonlette-0.0.3.tar.gz.

File metadata

  • Download URL: moonlette-0.0.3.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for moonlette-0.0.3.tar.gz
Algorithm Hash digest
SHA256 119ee71c2b052f16ba8ee829246ad99d99da41a4c9441e108c165aa34eabdf3c
MD5 e6816ca417ff4c968ddb68a259e44edb
BLAKE2b-256 c699d0df09881268e3624401a86bb2086740ea5696074205f9044ccf870d5eb8

See more details on using hashes here.

File details

Details for the file moonlette-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: moonlette-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for moonlette-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 011dfa2b9e275e69c34cecd204461d1b8b2658813af09b101d1d114035607287
MD5 44ddef0e92001edae7dfe744f4907a64
BLAKE2b-256 504ec03bb90621183a5bd35c9009526c213916f383c0a51cd8aebcdee98b123e

See more details on using hashes here.

Supported by

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