No project description provided
Project description
llsd-asgi
llsd-asgi
adds automatic LLSD content negotiation to ASGI applications
(Starlette, FastAPI, Quart, etc.) with a single line of code:
app.add_middleware(LLSDMiddleware)
The code for llsd-asgi
is based on msgpack-asgi, a similar middleware
library for the MessagePack binary format.
Installation
Install with pip:
pip install llsd-asgi
Quickstart (FastAPI)
You can use llsd-asgi
with FastAPI like so:
from fastapi import FastAPI
from llsd_asgi import LLSDMiddleware
app = FastAPI()
app.add_middleware(LLSDMiddleware)
Quickstart (Starlette)
As a lower level example using Starlette:
from llsd_asgi import LLSDMiddleware
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
async def homepage(request):
return JSONResponse({"hello": "world"})
app = Starlette(debug=True, routes=[
Route('/', homepage),
])
# Wrap your application with the LLSD middleware
app = LLSDMiddleware(app)
How it works
flowchart TD
A(Client) <-->|LLSD| B(LLSDMiddleware)
B <-->|JSON| C(App)
Your ASGI application is wrapped around the LLSDMiddleware
, which performs
content negotiation based on Content-Type
and Accept
HTTP headers.
Quirks mode
Passing quirks=True
to the middleware enables 🤪 quirks mode. The behavior
of this mode matches that of poorly behaved Linden Lab services, where the
server returns LLSD even if the client has not requested it.
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
Built Distribution
Hashes for llsd_asgi-0.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b3eb346eaa32b60f4cf5a5244737c027f83c44c85ed475ba63964148a8f51f2 |
|
MD5 | f9dee36aa57b6b8a8a3c0dcc41c19308 |
|
BLAKE2b-256 | 558477a264fded7e29777b29910bf177b8eb7e48d8d9585ff9ee480159070594 |