Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cofin/litestar-granian
Granian plugin for Litestar
https://github.com/cofin/litestar-granian
asgi asgi-server granian litestar litestar-api litestar-framework
Last synced: about 2 months ago
JSON representation
Granian plugin for Litestar
- Host: GitHub
- URL: https://github.com/cofin/litestar-granian
- Owner: cofin
- License: mit
- Created: 2023-10-02T01:34:15.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-01T15:00:43.000Z (2 months ago)
- Last Synced: 2024-10-14T09:54:10.774Z (2 months ago)
- Topics: asgi, asgi-server, granian, litestar, litestar-api, litestar-framework
- Language: Python
- Homepage:
- Size: 335 KB
- Stars: 16
- Watchers: 1
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-litestar - `litestar-granian` - A plugin for the [Granian](https://github.com/emmett-framework/granian) HTTP server, written in Rust.<sup>*</sup> (Third-Party Extensions / General)
README
# Litestar Granian Plugin
## Installation
```shell
pip install litestar-granian
```## Usage
Here is a basic application that demonstrates how to use the plugin.
```python
from __future__ import annotationsfrom litestar import Controller, Litestar, get
from litestar_granian import GranianPlugin
class SampleController(Controller):
@get(path="/sample")
async def sample_route(self ) -> dict[str, str]:
"""Sample Route."""
return {"sample": "hello-world"}app = Litestar(plugins=[GranianPlugin()], route_handlers=[SampleController])
```
Now, you can use the standard Litestar CLI and it will run with Granian instead of Uvicorn.
```shell
❯ litestar --app examples.basic:app run
Using Litestar app from env: 'examples.basic:app'
Starting granian 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 │
└──────────────────────────────┴──────────────────────┘
[INFO] Starting granian
[INFO] Listening at: 127.0.0.1:8000
[INFO] Spawning worker-1 with pid: 2719082
[INFO] Started worker-1
[INFO] Started worker-1 runtime-1
```