Skip to content

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

# Install CLI tools
pip install myfy-cli

# Or with uv
uv pip install myfy-cli

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.

uv run myfy routes

# Options
uv run myfy routes --app main:app    # Custom app location

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.

uv run myfy modules

# Options
uv run myfy modules --app main:app   # Custom app location

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).

uv run myfy frontend init

# Options
uv run myfy frontend init --force    # Overwrite existing files

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.

uv run myfy frontend build

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.

uv run myfy frontend dev

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:

--app TEXT          # Application path (module:variable)
--help             # Show help message

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

--fix             # Attempt to auto-fix issues
--verbose         # Show detailed diagnostics

frontend init Options

--force           # Overwrite existing files
--no-install      # Skip npm install

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-core documentation
  • Add Web Routes: Install myfy-web
  • Add Frontend: Install myfy-frontend
  • Deployment: Learn how to deploy to production