Skip to content

Server Commands

Commands for running and managing the development server.

serve

Start the development server with auto-reload.

bash
fastpy serve

Options

OptionDefaultDescription
--host127.0.0.1Host to bind to
--port8000Port to bind to
--reloadtrueEnable auto-reload
--workers1Number of workers

Examples

bash
# Default (localhost:8000)
fastpy serve

# Custom host and port
fastpy serve --host 0.0.0.0 --port 3000

# Production mode (no reload)
fastpy serve --reload false --workers 4

Direct uvicorn Usage

You can also use uvicorn directly:

bash
# Development
uvicorn main:app --reload

# Production
uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4

route:list

Display all registered routes.

bash
fastpy route:list

Options

OptionDescription
--tagFilter by tag
--methodFilter by HTTP method

Examples

bash
# List all routes
fastpy route:list

# Filter by tag
fastpy route:list --tag Users

# Filter by method
fastpy route:list --method POST

# Combine filters
fastpy route:list --tag Auth --method POST

Output

╭─────────────────────────────────────────────────────────────╮
│                       Registered Routes                      │
├────────┬────────────────────────┬────────────────────────────┤
│ Method │ Path                   │ Name                       │
├────────┼────────────────────────┼────────────────────────────┤
│ GET    │ /api/users             │ list_users                 │
│ POST   │ /api/users             │ create_user                │
│ GET    │ /api/users/{id}        │ get_user                   │
│ PUT    │ /api/users/{id}        │ update_user                │
│ DELETE │ /api/users/{id}        │ delete_user                │
├────────┼────────────────────────┼────────────────────────────┤
│ POST   │ /api/auth/login        │ login                      │
│ POST   │ /api/auth/register     │ register                   │
│ POST   │ /api/auth/refresh      │ refresh_token              │
│ GET    │ /api/auth/me           │ get_current_user           │
╰────────┴────────────────────────┴────────────────────────────╯

Environment-Based Server Config

The server respects environment variables:

bash
# .env
HOST=0.0.0.0
PORT=8000
WORKERS=4
RELOAD=false

Health Endpoints

When the server starts, these endpoints are available:

EndpointDescription
GET /health/Basic health check
GET /health/readyReadiness probe (includes DB)
GET /health/liveLiveness probe
GET /health/infoService information

Example Response

json
// GET /health/ready
{
  "status": "healthy",
  "database": "connected",
  "timestamp": "2024-01-15T10:30:00Z"
}

Released under the MIT License.