A colorful FastAPI server with rich logging, background traffic generation, and comprehensive endpoint examples for testing HTTP methods and error scenarios.
- Rich Console Logging: Colorized, formatted access logs with response times, status codes, and request IDs
- Background Traffic Generator: Simulates realistic traffic patterns to test your server
- HTTP Method Examples: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
- Error Simulation: Built-in endpoints for testing 400, 404, 500, and 503 responses
- Request Correlation: X-Request-ID headers for request tracing
- Performance Metrics: Response time tracking with visual indicators (green/yellow/red)
- Python 3.14 or higher
- uv - Modern Python package manager
git clone https://github.com/jaredthivener/python-demo.git
cd python-demouv sync
source .venv/bin/activate # On Windows: .venv\Scripts\activateThis command will create a virtual environment and install all dependencies from pyproject.toml. The .venv/bin/activate step activates the environment so you can use the installed packages.
Activate the virtual environment first (if not already activated):
source .venv/bin/activate # On Windows: .venv\Scripts\activateThen start the development server with auto-reload:
uvicorn main:app --reload --no-access-logThe server will be available at http://127.0.0.1:8000
API Documentation:
- Swagger UI:
http://127.0.0.1:8000/docs- Interactive API explorer - ReDoc:
http://127.0.0.1:8000/redoc- Alternative API documentation
- Auto-reload: The server automatically restarts when you modify
main.py - Background Traffic: Once running, the server generates simulated traffic to itself
- Rich Logging: All requests are logged with color-coded formatting
GET /- Returns a simple hello messageGET /api/tags- Returns a list of tagsGET /api/ps- Health check endpoint
POST /api/pull- Simulates a pull operationPUT /api/items/{id}- Updates an itemPATCH /api/items/{id}- Partially updates an itemDELETE /api/items/{id}- Deletes an item
HEAD /api/status- Returns headers onlyOPTIONS /api/options- Returns allowed methods
GET /api/error/400- Returns 400 Bad RequestGET /api/error/404- Returns 404 Not FoundGET /api/error/500- Returns 500 Internal Server ErrorGET /api/error/503- Returns 503 Service Unavailable
# Test GET endpoint
curl http://127.0.0.1:8000/api/tags
# Test POST endpoint
curl -X POST http://127.0.0.1:8000/api/pull
# Test error endpoint
curl http://127.0.0.1:8000/api/error/404python-demo/
├── main.py # Main application file
├── requirements.txt # Python dependencies
├── README.md # This file
└── .venv/ # Virtual environment (ignored by git)
Key settings in main.py:
WARN_MS: Response time threshold for yellow warning (default: 100ms)SLOW_MS: Response time threshold for red slow indicator (default: 500ms)SERVER_PORT: Port for background traffic generation (default: 8000)
The application uses Rich for beautiful console logging. Each request line includes:
- Timestamp
- Status code (color-coded: green 2xx, cyan 3xx, yellow 4xx, red 5xx)
- Response time in milliseconds
- Response size
- Client IP
- HTTP method (color-coded by method type)
- Request path
- Request ID for correlation
Press CTRL+C to stop the development server.
- fastapi: Modern web framework for building APIs
- uvicorn: ASGI server for running FastAPI
- httpx: Async HTTP client for background traffic generation
- rich: Beautiful terminal rendering and logging
MIT
For issues or questions, please open an issue on the GitHub repository.