ワンクリックで
uvicorn
ASGI server for Python web applications - Fast, production-ready server for async frameworks
メニュー
ASGI server for Python web applications - Fast, production-ready server for async frameworks
Database migration management for SQLAlchemy projects using Alembic
Advanced Python Scheduler - Task scheduling and job queue system
Build async APIs with FastAPI, including endpoints, dependency injection, validation, and testing. Use when creating REST APIs, web backends, or microservices.
Data validation and settings management using Python type annotations with Pydantic v2
Structured logging for Python applications with context support and powerful processors
Promise-based HTTP client for making requests from browser and Node.js
| name | uvicorn |
| description | ASGI server for Python web applications - Fast, production-ready server for async frameworks |
| when_to_use | - Running FastAPI, Starlette, Django Channels, or other ASGI applications - Development servers with hot reload - Production deployment with multiple workers - WebSocket applications - Async Python web services |
Uvicorn is a lightning-fast ASGI server implementation, using uvloop and httptools. It's the go-to server for modern Python async web frameworks.
# Run ASGI app
uvicorn main:app
# With host/port
uvicorn main:app --host 0.0.0.0 --port 8000
# Development with auto-reload
uvicorn main:app --reload
# main.py
async def app(scope, receive, send):
assert scope['type'] == 'http'
await send({
'type': 'http.response.start',
'status': 200,
'headers': [(b'content-type', b'text/plain')],
})
await send({
'type': 'http.response.body',
'body': b'Hello, World!',
})
# main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
uvicorn main:app --reload
# main.py
from fastapi import FastAPI
def create_app():
app = FastAPI()
# Configure app
return app
app = create_app()
uvicorn --factory main:create_app
import uvicorn
# Simple run
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
import asyncio
import uvicorn
async def main():
config = uvicorn.Config("main:app", port=5000, log_level="info")
server = uvicorn.Server(config)
await server.serve()
if __name__ == "__main__":
asyncio.run(main())
export UVICORN_HOST="0.0.0.0"
export UVICORN_PORT="8000"
export UVICORN_RELOAD="true"
uvicorn main:app
# Use multiple worker processes
uvicorn main:app --workers 4
# Note: Can't use --reload with --workers
# Install gunicorn
pip install gunicorn
# Run with Gunicorn process manager
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker
uvicorn main:app --ssl-keyfile=./key.pem --ssl-certfile=./cert.pem
uvicorn main:app --uds /tmp/uvicorn.sock
uvicorn main:app \
--host 0.0.0.0 \
--port 8000 \
--reload \
--reload-dir ./app \
--log-level info \
--access-log \
--workers 4
--host: Bind host (default: 127.0.0.1)--port: Bind port (default: 8000)--reload: Enable auto-reload for development--workers: Number of worker processes--log-level: Logging level (critical, error, warning, info, debug)--access-log: Enable access logging--factory: Treat app as application factoryFROM python:3.12-slim
WORKDIR /app
# Install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt
# Copy application
COPY . .
# Run with uvicorn
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
services:
app:
build: .
ports:
- "8000:8000"
environment:
- UVICORN_RELOAD=true
volumes:
- .:/app
command: uvicorn main:app --host 0.0.0.0 --port 8000 --reload
--app-dir--reload-dir--workers for production, avoid with --reloaduvicorn main:app --reload --log-level debug
@app.get("/health")
async def health():
return {"status": "healthy"}