Skip to content

cofin/litestar-socketify

Repository files navigation

Litestar Socketify Plugin

Warning

Socketify currently has an issue with ASGI lifespans. This plugin should be considered experimental.

Installation

pip install litestar-socketify

Usage

Here is a basic application that demonstrates how to use the plugin.

from __future__ import annotations

from litestar import Controller, Litestar, get

from litestar_socketify import SocketifyPlugin


class SampleController(Controller):
    @get(path="/sample")
    async def sample_route(self ) -> dict[str, str]:
        """Sample Route."""
        return {"sample": "hello-world"}


app = Litestar(plugins=[SocketifyPlugin()], route_handlers=[SampleController])

Now, you can use the standard Litestar CLI and it will run with Socketify instead of Uvicorn.

❯ litestar --app examples.basic:app run
Using Litestar app from env: 'examples.basic:app'
Starting socketify server process ──────────────────────────────────────────────
┌──────────────────────────────┬──────────────────────┐
│ Litestar version             │ 2.1.1                │
│ Debug mode                   │ Disabled             │
│ Python Debugger on exception │ Disabled             │
│ CORS                         │ Disabled             │
│ CSRF                         │ Disabled             │
│ OpenAPI                      │ Enabled path=/schema │
│ Compression                  │ Disabled             │
└──────────────────────────────┴──────────────────────┘
...