Litestar Python
A Python snippet for Litestar that answers requests for /pixel.gif with the empty GIF, decoded once at startup.
Litestar Python
import base64
from litestar import Litestar, get
from litestar.datastructures import CacheControlHeader
GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
@get(
"/pixel.gif",
media_type="image/gif",
cache_control=CacheControlHeader(no_store=True),
include_in_schema=False,
)
async def pixel() -> bytes:
return GIF
app = Litestar([pixel])
We ran this snippet and compared the bytes it returned.
Check it
curl -sI http://localhost:8080/pixel.gif
More in Python
- AWS Lambda (Python)
- Google Cloud Run functions (Python)
- FastAPI
- Starlette
- Django
- Flask
- aiohttp
- Sanic
- Quart
- Falcon
- Robyn
- BlackSheep
- Tornado
- Bottle
- Pyramid
- Microdot (CPython and MicroPython)
- Raw ASGI (Uvicorn, Granian, Hypercorn)
- Raw WSGI (Gunicorn, uWSGI, mod_wsgi)
- Python standard library (http.server)
- Python one-liner