litestar-org/litestar-skills/litestar-granian

Claude Code and agent skill by litestar-org/litestar-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Auto-activate for litestar_granian, GranianPlugin, litestar run Granian options, runtime threads, HTTP/2, TLS, access logs, metrics, static mounts, or worker lifecycle. Not for non-Granian servers.

Install

npx vskill@latest install litestar-org/litestar-skills/litestar-granian

SKILL.md

litestar-granian

litestar-granian replaces Litestar's run command with a supervised Granian command and bridges Litestar's active log formatter into Granian worker processes. It requires Granian 2.8.0 or later (using Granian 2.8.7).

Code Style Rules

  • Keep handlers async when they perform I/O.
  • Configure the server at the command line or programmatically via granian.Granian.
  • GranianPlugin takes only an optional static mode keyword argument ("off" or "auto").
  • Use the litestar run option names documented here. Do not substitute similarly named options from older Granian or Uvicorn releases.

Quick Reference

Register the plugin
python
from litestar import Litestar, get
from litestar_granian import GranianPlugin
@get("/health")
async def health() -> dict[str, str]:
"""Return health check response."""
return {"status": "ok"}
app = Litestar(
route_handlers=[health],
plugins=[GranianPlugin()],
)
bash
litestar --app app:app run

GranianPlugin registers the Granian-backed run command. When litestar run starts, litestar-granian inspects the active "litestar" standard-library logger (or app.logging_config, including standard_lib_logging_config wrapped by StructlogPlugin), serializes the active formatter into a temporary JSON dictConfig (--log-config), and reconstructs matching generic (_granian) and access (granian.access) formatters inside Granian worker processes.

Defaults in 0.17.0 / Granian 2.8.7
ConcernDefault
Sockets and Bind127.0.0.1:8000
HTTP modeauto (HTTP/1 and HTTP/2 supported; HTTP/3 not supported)
Workers1 worker (process on GIL builds; thread on free-threaded builds)
Runtime threads1 per worker
Runtime blocking threadsAutomatically selected (512 in Granian when unset)
Blocking threads1 on ASGI (fixed; > 1 only supported on WSGI; 30s idle timeout)
Runtime modeauto (resolves to mt on ASGI)
Event loopauto (Granian's standard selection; optional loops require their extras)
Async task implementationasyncio (optional experimental rust on Python < 3.12)
Backlog1024 globally (minimum 128)
Backpressurebacklog / workers per worker (minimum 1)
Granian logEnabled at info (--granian-log, --granian-log-level)
Access logDisabled (--granian-access-log, --granian-access-log-fmt)
WebSocketsEnabled (--ws); automatically disabled in HTTP/2-only mode
Process supervisionSupervised process group (always)
ReloadDisabled (--reload; not supported on free-threaded Python)
MetricsDisabled; 127.0.0.1:9090 when enabled with --metrics
Static-file cache86400 seconds; no implicit route or mount
Minimum TLS protocolTLS 1.3 (`--ssl-protocol-min [tls1.2\tls1.3]`)
Valid Production Controls
bash
litestar --app app:app run \
--host 0.0.0.0 \
--port 8000 \
--workers 4 \
--runtime-mode auto \
--runtime-threads 1 \
--backpressure 1024 \
--granian-access-log \
--respawn-failed-workers \
--workers-lifetime 4h \
--workers-max-rss 512 \
--metrics \
--metrics-address 127.0.0.1 \
--metrics-port 9090

Use these option families:

ConcernOptions
Processes and runtime--workers (--wc, --web-concurrency, -W), --blocking-threads, --blocking-threads-idle-timeout, --runtime-threads, --runtime-blocking-threads, --runtime-mode, --loop, --task-impl
Capacity and flow control--backlog, --backpressure
Protocols`--http [auto\1\2], --ws / --no-ws, --http1-`, `--http2-`
Granian logging--granian-log / --granian-no-log, --granian-log-level, --granian-access-log / --granian-no-access-log, --granian-access-log-fmt
Litestar logging--log-config (formatter matching is automatic)
TLS & mTLS--ssl-certificate (--ssl-certfile alias), --ssl-keyfile, --ssl-keyfile-password, --ssl-protocol-min, --ssl-ca, --ssl-crl, --ssl-client-verify / --no-ssl-client-verify, --create-self-signed-cert
Worker lifecycle--respawn-failed-workers / --no-respawn-failed-workers, --respawn-interval, --workers-lifetime, --workers-kill-timeout, --workers-max-rss, --rss-sample-interval, --rss-samples
Reload & debug (dev)--reload (-r), --reload-paths (--reload-dir, -R), --reload-include (-I), --reload-exclude (-E), --reload-ignore-dirs, --reload-ignore-patterns, --reload-ignore-paths, --reload-tick, --reload-ignore-worker-failure, --debug (-d), --pdb (--use-pdb, -P)
Operations--uds (--unix-domain-socket, -U), --uds-permissions, --fd (--file-descriptor, -F), --url-path-prefix, --process-name, --pid-file, --working-dir, --env-files, --metrics / --no-metrics, --metrics-address, --metrics-port, --metrics-scrape-interval
Static mountsRepeatable --static-path-route and --static-path-mount, plus --static-path-dir-to-file and --static-path-expires
Supervision and Litestar CLI Parity

litestar run has one execution model: the Litestar parent enters server lifespans once and supervises a fresh Granian child process group.

  • POSIX: Starts Granian in a new session (start_new_session=True) and forwards signals (SIGINT, SIGTERM, SIGHUP) to the process group (os.killpg).
  • Windows: Uses a new process group (CREATE_NEW_PROCESS_GROUP) and CTRL_BREAK_EVENT for graceful shutdown, escalating to list-based taskkill only if needed.
  • Graceful Shutdown & Deadlines: The first termination signal is forwarded once and starts a deadline of --workers-kill-timeout plus five seconds (the CLI default is 5 seconds). A second signal or an expired deadline kills the process group.
  • Server Lifespans: Litestar's server lifespans stay active until Granian exits and are unwound cleanly after child termination.
  • Sidecar Variables: Server-lifespan sidecars receive the resolved LITESTAR_APP, LITESTAR_HOST, and LITESTAR_PORT, which is how frontend dev-server sidecars (e.g. Vite) learn the real server bind.
  • Socket Activation: Inherited file descriptors (-F / --fd / --file-descriptor) are supported on POSIX systems (e.g. systemd socket activation).
Native Static Discovery

GranianPlugin(static=...) is the plugin's only constructor option:

python
app = Litestar(route_handlers=[health], plugins=[GranianPlugin(static="auto")])
  • "off" (the default) keeps Litestar's static routing.
  • "auto" lets Granian serve exactly one compatible static provider natively when its configuration is safe, and falls back to Litestar otherwise.
  • Explicit --static-path-* CLI mounts always take precedence over either mode. Any other value raises ValueError at construction.
Metrics and Observability

Metrics are off by default and are controlled only by --metrics / --no-metrics. --metrics exposes Granian server and worker metrics only at http://<metrics-address>:<metrics-port>/metrics. When no Litestar Prometheus middleware is detected, the command warns that application-level request metrics are not being exported — register Litestar's PrometheusPlugin alongside it when request metrics are desired.

Proxy Headers (granian.utils.proxies)

Granian does not expose --proxy-headers or --forwarded-allow-ips CLI flags. When running behind a reverse proxy that sets X-Forwarded-For and X-Forwarded-Proto, register granian.utils.proxies.wrap_asgi_with_proxy_headers on Litestar(middleware=[...]):

python
from functools import partial
from granian.utils.proxies import wrap_asgi_with_proxy_headers
from litestar import Litestar
from litestar_granian import GranianPlugin
app = Litestar(
route_handlers=[health],
plugins=[GranianPlugin()],
middleware=[
partial(wrap_asgi_with_proxy_headers, trusted_hosts=["127.0.0.1", "10.0.0.0/8"]),
],
)
Programmatic / Embedded Runtime

Granian can also be executed programmatically directly from Python:

python
from pathlib import Path
from granian import Granian
from granian.constants import HTTPModes, Interfaces, RuntimeModes
def run_embedded() -> None:
"""Execute Granian embedded server."""
server = Granian(
target="app.server:app",
address="0.0.0.0",
port=8000,
interface=Interfaces.ASGI,
workers=2,
runtime_mode=RuntimeModes.auto,
http=HTTPModes.auto,
ssl_cert=Path("/etc/ssl/certs/app.crt"),
ssl_key=Path("/etc/ssl/private/app.key"),
)
server.serve()

<workflow>

Workflow

Step 1: Match the project's deployment stack

Use GranianPlugin when the project already uses litestar-granian or needs its Granian-specific CLI, HTTP/2, runtime, worker-lifecycle, metrics, or static mount controls.

Keep the project's existing ASGI server when its deployment platform, process manager, observability, or operational runbooks depend on that server. Do not replace an established server solely because Granian is available.

Use the bare granian CLI only when deployment tooling intentionally invokes Granian directly. Its CLI is a separate surface; consult the matching Granian release instead of copying litestar run options.

Step 2: Install and register
bash
pip install "litestar-granian>=0.17.0"

Add GranianPlugin() to Litestar(plugins=[...]), then run the application through litestar --app <module>:<app> run.

Step 3: Configure logging

Supervised execution is standard and matches Granian's formatter to Litestar's automatically:

bash
litestar --app app:app run

--in-subprocess / --no-subprocess and --use-litestar-logger / --no-litestar-logger are accepted for backwards compatibility, but they are ignored and print a deprecation warning. Remove them from deployment scripts.

Pass an explicit JSON --log-config only when overriding the automatic formatter matching completely.

Step 4: Configure the deployment and capacity

Measure the application before changing workers, runtime threads, or backpressure. Preserve the auto runtime defaults unless load tests justify a specific runtime mode.

bash
litestar --app app:app run \
--host 0.0.0.0 \
--port 8000 \
--workers 4 \
--backpressure 1024 \
--granian-access-log

Terminate TLS at the platform proxy when that is the project's established boundary. For Granian-managed TLS, pass both the certificate and key:

bash
litestar --app app:app run \
--ssl-certificate /etc/ssl/certs/app.crt \
--ssl-keyfile /etc/ssl/private/app.key \
--ssl-protocol-min tls1.3
Step 5: Verify the effective command
bash
litestar --app app:app run --help

Confirm the required options appear, start the service, exercise health and WebSocket endpoints, and load-test production capacity settings.

</workflow>

<guardrails>

Guardrails

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/litestar-org/litestar-skills/litestar-granian/badge)](https://verified-skill.com/skills/litestar-org/litestar-skills/litestar-granian)

Something wrong with this skill or its page? Tell us.