Skip to content
Skillv1.0.0

uvicorn

Deploy Python ASGI apps with Uvicorn. Use when a user asks to run FastAPI in production, configure an ASGI server, set up Gunicorn with Uvicorn workers, or optimize Python web server performance.

by terminalskills(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from terminalskills/skills (skills/uvicorn/SKILL.md). Install upstream with npx skills add terminalskills/skills --skill uvicorn. Copyright stays with the author (Apache-2.0).

Uvicorn

Overview

Uvicorn is a lightning-fast ASGI server for Python. It's the recommended way to run FastAPI, Starlette, and Django ASGI in production. For multi-core utilization, pair it with Gunicorn as a process manager.

Instructions

Step 1: Development

pip install uvicorn[standard]

# Run with auto-reload
uvicorn app.main:app --reload --port 8000

Step 2: Production with Gunicorn

pip install gunicorn

# Gunicorn manages multiple Uvicorn worker processes
gunicorn app.main:app \
  --workers 4 \                    # CPU cores × 2 + 1
  --worker-class uvicorn.workers.UvicornWorker \
  --bind 0.0.0.0:8000 \
  --timeout 120 \
  --graceful-timeout 30 \
  --access-logfile - \
  --error-logfile -

Step 3: Docker Production

FROM python:3.12-slim
WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

# Non-root user
RUN adduser --system --uid 1001 app
USER app

# Production command
CMD ["gunicorn", "app.main:app", \
     "--workers", "4", \
     "--worker-class", "uvicorn.workers.UvicornWorker", \
     "--bind", "0.0.0.0:8000", \
     "--timeout", "120"]

Step 4: Programmatic Configuration

# run.py — Uvicorn with programmatic config
import uvicorn

if __name__ == "__main__":
    uvicorn.run(
        "app.main:app",
        host="0.0.0.0",
        port=8000,
        workers=4,
        log_level="info",
        access_log=True,
        proxy_headers=True,        # trust X-Forwarded-* from reverse proxy
        forwarded_allow_ips="*",
    )

Guidelines

  • Development: uvicorn --reload (single process, auto-reload on file changes).
  • Production: gunicorn with UvicornWorker class (multi-process, no reload).
  • Workers formula: (2 × CPU cores) + 1 — e.g., 4 cores → 9 workers.
  • Always use behind a reverse proxy (nginx, Caddy) for TLS termination and static files.
  • Set proxy_headers=True when behind a load balancer to get real client IPs.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/terminalskills-skills-uvicorn/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

terminalskills-skills-uvicorn.ocm.jsonjson
{
  "ocm": "1",
  "id": "terminalskills-skills-uvicorn",
  "kind": "skill",
  "name": "uvicorn",
  "description": "Deploy Python ASGI apps with Uvicorn. Use when a user asks to run FastAPI in production, configure an ASGI server, set up Gunicorn with Uvicorn workers, or optimize Python web server performance.",
  "publisher": "terminalskills",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "uvicorn",
      "asgi",
      "fastapi",
      "production",
      "server",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Deploy Python ASGI apps with Uvicorn. Use when a user asks to run FastAPI in production, configure an ASGI server, set up Gunicorn with Uvicorn workers, or optimize Python web server performance."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/terminalskills/skills",
      "path": "skills/uvicorn/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/terminalskills/skills/blob/HEAD/skills/uvicorn/SKILL.md",
      "key": "terminalskills/skills/skills/uvicorn/SKILL.md"
    },
    "compatibility": "Python 3.8+, FastAPI, Starlette, Django ASGI",
    "license": "Apache-2.0"
  },
  "instructions": "# Uvicorn\n\n## Overview\n\nUvicorn is a lightning-fast ASGI server for Python. It's the recommended way to run FastAPI, Starlette, and Django ASGI in production. For multi-core utilization, pair it with Gunicorn as a process manager.\n\n## Instructions\n\n### Step 1: Development\n\n```bash\npip install uvicorn[standard]\n\n# Run with auto-reload\nuvicorn app.main:app --reload --port 8000\n```\n\n### Step 2: Production with Gunicorn\n\n```bash\npip install gunicorn\n\n# Gunicorn manages multiple Uvicorn worker processes\ngunicorn app.main:app \\\n  --workers 4 \\                    # CPU cores × 2 + 1\n  --worker-class ",
  "cost": {
    "context_tokens": 500
  }
}

Fetch it by URL: GET /api/v1/registry/terminalskills-skills-uvicorn/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.