cofin / litestar-granian Goto Github PK
View Code? Open in Web Editor NEWGranian plugin for Litestar
License: MIT License
Granian plugin for Litestar
License: MIT License
Litestar CLI cause crash on application exit, but when I start via granian cli, it works cool.
MCVE:
def init_app(
init_api_routers: Callable or None,
structlog_config: StructLoggingConfig,
context: str,
middlewares: list[Middleware],
) -> Litestar:
set_event_loop_policy(EventLoopPolicy())
if init_api_routers is None:
def init_api_routers():
return []
structlog_plugin = StructlogPlugin(StructlogConfig(structlog_logging_config=structlog_config))
app = Litestar(
route_handlers=[*init_api_routers()],
middleware=middlewares,
plugins=[structlog_plugin, GranianPlugin()],
)
return app
def init_apps() -> Litestar:
context = "schedule_service"
structlog_config = init_logging(context)
logger = get_logger()
app: Litestar = init_app(
None, structlog_config, context, [GZipMiddleware]
)
app.on_startup = []
app.on_shutdown = []
app.logger = logger
return app
app = init_apps()
I'm trying to use granian using the plugin (v0.4.0) in the latest version of Litestar (v2.9.0). However, with a basic setup below:
from __future__ import annotations
from 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])
and running litestar run
, I get:
Using Litestar app from app:app
Starting Granian server process ──────────────────────────────────────────────────────────────────────────────────────────────────
┌──────────────────────────────┬──────────────────────┐
│ Litestar version │ 2.9.0 │
│ Debug mode │ Disabled │
│ Python Debugger on exception │ Disabled │
│ CORS │ Disabled │
│ CSRF │ Disabled │
│ OpenAPI │ Enabled path=/schema │
│ Compression │ Disabled │
└──────────────────────────────┴──────────────────────┘
INFO - 2024-06-10 11:17:19,358 - _granian - server - Starting granian (main PID: 6266)
INFO - 2024-06-10 11:17:19,358 - _granian - server - Listening at: http://127.0.0.1:8000
then it crashed.
However, using the granian command granian --interface asgi app:app
, it works fine.
See: https://github.com/litestar-org/litestar/pull/3190/files
Usage:
litestar-granian/litestar_granian/cli.py
Line 16 in e241452
You will need to update this or should pin to <2.8.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.