CLI Tools
Zenith CLI Tools
Section titled “Zenith CLI Tools”The zen command provides essential tools for developing and deploying Zenith applications. The CLI has been streamlined to focus on the most valuable, reliable commands that developers use daily.
Quick Reference
Section titled “Quick Reference”zen new <path> # Create new Zenith application with secure defaultszen keygen # Generate secure SECRET_KEYzen dev # Start development server (hot reload)zen serve # Start production serverzen --version # Show Zenith versionProject Creation
Section titled “Project Creation”zen new - Create New Application
Section titled “zen new - Create New Application”Create a new Zenith application:
zen new my-app # Create in ./my-app/zen new . # Create in current directoryzen new /path/to/app --name MyAPI # Specify name explicitlyGenerated structure:
my-app/├── app.py # Application entry point with sample endpoints├── .env # Environment variables (with generated secret key)├── requirements.txt # Python dependencies├── .gitignore # Git ignore rules└── README.md # Quick start documentationGenerated app.py includes:
- Basic Zenith application setup
- Sample API endpoints (
/and/health) - Production-ready configuration examples
- Clear documentation and next steps
Security Commands
Section titled “Security Commands”zen keygen - Generate Secure Keys
Section titled “zen keygen - Generate Secure Keys”Generate cryptographically secure SECRET_KEY values for your application:
zen keygen # Print key to stdoutzen keygen --output .env # Write to .env filezen keygen --output .env --force # Overwrite existing keyzen keygen --length 32 # Generate 32-byte key (default: 64)Use cases:
- Key rotation - Generate new keys for production rotation
- Environment setup - Add keys to existing .env files
- CI/CD pipelines - Generate keys for automated deployments
Note: The zen new command automatically generates a secure SECRET_KEY, so you typically only need zen keygen for key rotation or adding keys to existing projects.
Automatic .env Loading: Zenith automatically loads .env and .env.local files from your project directory, so keys generated with zen keygen --output .env work immediately without additional configuration.
Development Commands
Section titled “Development Commands”zen dev - Development Server
Section titled “zen dev - Development Server”Start a development server with hot reload enabled:
zen dev # Start on 127.0.0.1:8000zen dev --host 0.0.0.0 # Bind to all interfaceszen dev --port 3000 # Use custom portzen dev --open # Open browser automaticallyzen dev --app src.api.app:app # Specify app import pathzen dev --testing # Enable testing modeFeatures:
- Development environment - Automatically sets
ZENITH_ENV=development - Hot reload - Automatically restarts on file changes
- File watching - Watches
.py,.html,.css,.jsfiles - Intelligent app discovery - Finds your app automatically
- Testing mode - Disables rate limiting for test suites
- Interactive logs - Real-time request logging
- Health endpoints -
/healthand/docsavailable automatically
Testing Mode
Section titled “Testing Mode”The --testing flag is crucial for test suites that make multiple rapid requests:
# Development with testing mode (disables rate limiting)zen dev --testing
# For test scripts and CI/CDZENITH_ENV=test zen devWhy testing mode?
- Disables rate limiting middleware that can cause
429 Too Many Requestserrors in tests - Automatically enabled when
ZENITH_ENV=testenvironment variable is set - Safe for production (only affects rate limiting, not security features)
App Discovery
Section titled “App Discovery”The CLI automatically discovers your application:
Search strategy:
- Explicit app path (if provided):
--app src.api.app:app - Common app files:
app.py,main.py,application.py - Nested structures:
src/app.py,src/api/app.py,app/main.py
Error messages:
No Zenith app found
🔍 Searched for: • app.py, main.py, application.py (with 'app' variable) • src/app.py, src/api/app.py, src/main.py • app/main.py, api/app.py
Quick solutions: 1. Specify explicitly: zen dev --app=my_module:app 2. Create main.py: from src.api.app import app 3. Generate new app: zen new .
For testing: zen dev --testing --app=your.module:app
Current directory contents: • main.py • config.py Subdirectories with Python files: • src/ (5 .py files)Production Commands
Section titled “Production Commands”zen serve - Production Server
Section titled “zen serve - Production Server”Start a production-ready server with multiple workers:
zen serve # Start with 4 workers on 0.0.0.0:8000zen serve --workers 8 # Use 8 worker processeszen serve --host 127.0.0.1 # Bind to localhost onlyzen serve --port 80 # Use port 80zen serve --reload # Enable reload (development mode)Features:
- Production environment - Automatically sets
ZENITH_ENV=production - Multi-process - Automatic worker scaling based on CPU cores
- Production logging - Structured logs with access logs
- Performance optimized - Optimized for high throughput
- Health checks - Built-in health monitoring
- Graceful shutdown - Proper signal handling
Production Example:
# Production deploymentzen serve --host 0.0.0.0 --port 8000 --workers 4
# Behind reverse proxyzen serve --host 127.0.0.1 --port 8000 --workers 8
# Container deploymentzen serve --host 0.0.0.0 --port 8000 --workers 2Common Workflows
Section titled “Common Workflows”New Project Workflow
Section titled “New Project Workflow”# Create new projectzen new my-apicd my-api
# Install dependenciespip install -r requirements.txt
# Start developmentzen dev --open
# The generated app includes:# - GET / (API root with welcome message)# - GET /health (health check)# - GET /docs (automatic OpenAPI documentation)Development Workflow
Section titled “Development Workflow”# Start development serverzen dev
# For rapid testing (disables rate limiting)zen dev --testing
# Custom configurationzen dev --host 0.0.0.0 --port 3000 --app src.main:appTesting Workflow
Section titled “Testing Workflow”# Enable testing mode for test suitesZENITH_ENV=test python -m pytest
# Or in development serverzen dev --testing
# Testing mode prevents these common errors:# - 429 Too Many Requests from rate limiting# - Middleware interference with test isolationProduction Deployment
Section titled “Production Deployment”# Test production server locallyzen serve --workers 1 --reload
# Production deploymentzen serve --host 0.0.0.0 --port 8000 --workers 4
# With environment variablesSECRET_KEY=your-secret zen serve --workers 4Configuration
Section titled “Configuration”Environment Variables
Section titled “Environment Variables”The CLI respects these environment variables:
ZENITH_ENV=test- Enables testing mode (disables rate limiting)SECRET_KEY- Application secret keyDATABASE_URL- Database connection stringDEBUG- Enable debug mode
App Path Resolution
Section titled “App Path Resolution”For non-standard setups, use explicit app paths:
# Module notationzen dev --app mypackage.application:appzen dev --app src.main:application
# For complex structureszen dev --app project.apps.api:create_appConfiguration Files
Section titled “Configuration Files”The CLI respects these configuration files:
.env- Environment variables (automatically generated byzen new)requirements.txt- Python dependenciespyproject.toml- Project configuration
Troubleshooting
Section titled “Troubleshooting”Command Not Found
Section titled “Command Not Found”If zen command is not available:
# Check installationpip show zenithweb
# Alternative commandpython -m zenith.cli --version
# Reinstall if neededpip install --force-reinstall zenithwebApp Discovery Issues
Section titled “App Discovery Issues”If CLI can’t find your app:
# Use explicit app pathzen dev --app myfile:myapp
# Check app variable existsgrep "app = " *.py
# Verify app file syntaxpython -m py_compile app.py
# Create main.py wrapper for complex structuresecho "from src.api.app import app" > main.pyTesting Issues
Section titled “Testing Issues”If tests fail with rate limiting errors:
# Enable testing modezen dev --testing
# Or set environment variableexport ZENITH_ENV=testzen dev
# In pytest configuration (conftest.py)import osos.environ["ZENITH_ENV"] = "test"Development Server Issues
Section titled “Development Server Issues”If development server won’t start:
# Check for port conflictslsof -i :8000
# Use different portzen dev --port 8001
# Check app file importspython -c "from app import app; print(' App loads successfully')"Migration from Previous Versions
Section titled “Migration from Previous Versions”If upgrading from earlier Zenith versions, note that these commands have been removed for simplicity:
zen routes→ Use/docsendpoint in your browserzen shell→ Use standard Python REPL or IPythonzen test→ Usepytestdirectlyzen info→ Usezen --versionand standard Python toolszen d/zen s→ Use full command names for clarity
Why simplified?
- Focus on high-value commands used daily
- Reduce maintenance burden and potential bugs
- Clearer, more predictable CLI interface
- Better error messages and app discovery
Tips & Best Practices
Section titled “Tips & Best Practices”Development
Section titled “Development”- Use
zen dev --testingwhen running test suites - Use
zen dev --opento automatically open browser - Set up
.envfile for consistent local configuration
Testing
Section titled “Testing”- Always enable testing mode:
ZENITH_ENV=test - Use explicit app paths in CI/CD:
zen dev --app src.main:app - Create wrapper files for complex app structures
Production
Section titled “Production”- Always use
zen servewith multiple workers - Set appropriate
--hostand--portfor your environment - Use environment variables for secrets, not command-line arguments
- Use reverse proxy (nginx/traefik) for static files and SSL
Performance
Section titled “Performance”- Use
zen servefor production (multiple workers) - Use
zen devonly for development (single worker, reload enabled) - Monitor with
/healthendpoint - Consider container orchestration for scaling