myfy-cli
Command-line tools for developing and managing myfy applications.
Overview
myfy-cli provides a suite of commands to streamline development, debugging, and deployment of myfy applications. Built on Typer for an excellent CLI experience.
Installation
Dependencies:
- myfy-core - Core framework
- typer - CLI framework
- rich - Terminal formatting
Available Commands
myfy run
Start the development server with auto-reload.
uv run myfy run
# Options
uv run myfy run --port 8080 # Custom port
uv run myfy run --host 0.0.0.0 # Bind to all interfaces
uv run myfy run --no-reload # Disable auto-reload
uv run myfy run --app main:app # Custom app location
Features: - Hot reload on file changes - Colored output - Error reporting - Auto-detects app location
Output:
๐ Starting myfy development server...
โ Found application in app.py
๐ก Listening on http://127.0.0.1:8000
๐ฆ Loaded 2 module(s)
๐ Reload enabled - watching for file changes
myfy routes
List all registered routes in your application.
Output:
โโโโโโโโโโณโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโณโโโโโโโ
โ Method โ Path โ Handler โ Name โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ GET โ / โ home โ - โ
โ GET โ /users โ list_users โ - โ
โ GET โ /users/{id} โ get_user โ - โ
โ POST โ /users โ create_user โ - โ
โ PUT โ /users/{id} โ update_user โ - โ
โ DELETE โ /users/{id} โ delete_user โ - โ
โโโโโโโโโโดโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโ
myfy modules
Show all loaded modules and their status.
Output:
โโโโโโโโโโโโโโโโโณโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Module โ Status โ Description โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ WebModule โ โ Ready โ HTTP/ASGI server โ
โ DataModule โ โ Ready โ Database connections โ
โ CacheModule โ โ Ready โ Redis cache โ
โโโโโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโ
myfy doctor
Validate application configuration and dependencies.
uv run myfy doctor
# Options
uv run myfy doctor --app main:app # Custom app location
uv run myfy doctor --fix # Auto-fix issues if possible
Output:
๐ Running diagnostics...
Configuration:
โ Settings loaded from .env
โ All required settings present
โ DEBUG=true (disable in production)
Dependency Injection:
โ No circular dependencies
โ All providers registered
โ All scopes valid
Modules:
โ 3 modules loaded
โ No conflicts detected
Routes:
โ 12 routes registered
โ 2 routes missing type hints
Summary: 2 warnings, 0 errors
myfy frontend init
Initialize frontend assets (Tailwind, Vite, templates).
What it does:
1. Creates frontend/ directory structure
2. Copies template files
3. Generates package.json and vite.config.js
4. Installs Node.js dependencies
5. Starts Vite dev server
Output:
๐จ Initializing myfy frontend...
โ Created frontend/ directory
โ Copied template files
โ Generated package.json
โ Installed dependencies
โ Vite dev server started on http://localhost:3001
myfy frontend build
Build frontend assets for production.
Output:
๐ฆ Building frontend for production...
โ Optimized CSS (23kb โ 8kb)
โ Minified JavaScript
โ Generated asset manifest
โ Build complete: frontend/static/dist/
myfy frontend dev
Start Vite development server.
Output:
โก Starting Vite dev server...
โ Server running at http://localhost:3001
๐ฅ Hot module replacement enabled
Usage Examples
Development Workflow
# 1. Start development server
uv run myfy run
# 2. In another terminal, check routes
uv run myfy routes
# 3. Validate configuration
uv run myfy doctor
# 4. If using frontend
uv run myfy frontend init
Production Deployment
# 1. Build frontend assets
uv run myfy frontend build
# 2. Validate everything
uv run myfy doctor
# 3. Run with production settings
MYFY_PROFILE=prod uv run myfy run --no-reload
Debugging
# List all routes to verify registration
uv run myfy routes
# Check module loading
uv run myfy modules
# Validate DI configuration
uv run myfy doctor
Configuration
App Location
By default, CLI tools look for app or application in app.py, main.py, or server.py.
Custom app location:
# Via flag
uv run myfy run --app my_app:application
# Via environment variable
export MYFY_APP=my_app:application
uv run myfy run
Environment Profiles
Set the profile before running commands:
# Development
export MYFY_PROFILE=dev
uv run myfy run
# Production
export MYFY_PROFILE=prod
uv run myfy run --no-reload
Command Options
Global Options
Available for all commands:
run Options
--host TEXT # Bind address (default: 127.0.0.1)
--port INTEGER # Port number (default: 8000)
--reload # Enable auto-reload (default: true in dev)
--no-reload # Disable auto-reload
--log-level TEXT # Log level (debug, info, warning, error)
doctor Options
frontend init Options
Integrating with CI/CD
Validation in CI
# .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install uv
uv pip install -e .
- name: Validate configuration
run: uv run myfy doctor
- name: Check routes
run: uv run myfy routes
Production Build
# Dockerfile
FROM python:3.11-slim
WORKDIR /app
# Install dependencies
COPY pyproject.toml .
RUN pip install uv && uv pip install .
# Copy application
COPY . .
# Build frontend
RUN uv run myfy frontend build
# Validate
RUN uv run myfy doctor
# Run
CMD ["uv", "run", "myfy", "run", "--host", "0.0.0.0", "--no-reload"]
Creating Custom Commands
Extend the CLI with your own commands:
# commands.py
import typer
from myfy.cli import app as cli_app
@cli_app.command()
def custom_command(name: str):
"""My custom command."""
typer.echo(f"Hello {name}!")
# Usage: uv run myfy custom-command John
Troubleshooting
App Not Found
# Error: Could not find application
# Solution 1: Specify app location
uv run myfy run --app my_module:app
# Solution 2: Use standard naming
# Rename your app variable to 'app' or 'application'
Module Import Errors
# Error: No module named 'xyz'
# Solution: Ensure you're in the right directory
cd /path/to/your/project
# And dependencies are installed
uv pip install -e .
Port Already in Use
# Error: Address already in use
# Solution: Use different port
uv run myfy run --port 8001
# Or kill the process using the port
lsof -ti:8000 | xargs kill
API Reference
For detailed API documentation, see:
Best Practices
Use Profiles
# โ Good - Explicit profiles
export MYFY_PROFILE=dev
uv run myfy run
# โ Bad - No profile specified
uv run myfy run # Uses default .env
Validate Before Deploy
# โ Good - Check everything first
uv run myfy doctor
uv run myfy routes
uv run myfy frontend build
# โ Bad - Deploy without checking
uv run myfy run --no-reload
Use --no-reload in Production
# โ Good - No reload in production
MYFY_PROFILE=prod uv run myfy run --no-reload
# โ Bad - Auto-reload in production
MYFY_PROFILE=prod uv run myfy run
Next Steps
- Learn Core: Read
myfy-coredocumentation - Add Web Routes: Install
myfy-web - Add Frontend: Install
myfy-frontend - Deployment: Learn how to deploy to production