Guide
Requirements
Section titled “Requirements”| Package | Required | Purpose |
|---|---|---|
lexigram | Yes | Core framework |
lexigram-contracts | Yes | Protocol definitions |
lexigram-web | Yes | Web UI support |
The Problem lexigram-cli Solves
Section titled “The Problem lexigram-cli Solves”Building a Lexigram application involves repeated setup: project scaffolding, code generation, database migrations, and runtime inspection. lexigram-cli automates these tasks through a single lexigram command, using a contributor-based plugin system where packages extend the CLI via lexigram.cli.contributors entry points.
Mental model: Think of lexigram-cli as the framework’s toolbox — one command to create, build, run, and introspect your application.
Core Concepts
Section titled “Core Concepts”- Command groups — commands are organized as sub-Typer apps (
new,run,dev,db,gen,inspect,shell, etc.) - Contributors — packages advertise commands, generators, health checks, shell context, and hooks via
lexigram.cli.contributors; discovered at import with automatic conflict resolution - CLIContext — per-invocation shared state holding config, output mode (Rich/JSON/Quiet), and flags
OutputManager— centralized output with support for Rich formatting, JSON serialization, and debug modes
Full Command Walkthrough
Section titled “Full Command Walkthrough”Scaffolding (new, add)
Section titled “Scaffolding (new, add)”# Create a new project from a templatelexigram new project my-app --template web-api -d ./projects
# Create a project interactivelylexigram new project my-app -i
# Scaffold a new lexigram-* extension packagelexigram new package my-feature
# Add a provider to an existing projectlexigram add weblexigram add sqlAvailable templates: web-api, full, api.
Dev Server (run, dev)
Section titled “Dev Server (run, dev)”# Auto-detect create_app() and start the serverlexigram run
# Explicit entry pointlexigram run my_app.app:create_app --port 9000 --no-reload
# Development server with hot-reloadlexigram dev --entry src/main.py --port 8000 --env development
# Use a specific server backendlexigram run --server granian
# Run with an MCP SSE server alongsidelexigram run --mcp-port 8080The CLI auto-detects the server backend, preferring Granian → Uvicorn → Hypercorn based on availability.
Database Management (db)
Section titled “Database Management (db)”# Create/upgrade a database and generate an initial migrationlexigram db init
# Auto-generate a migration from schema changeslexigram db migrate -m "add email to users"
# Apply pending migrationslexigram db upgrade
# Rollback the last migrationlexigram db rollback
# View migration statuslexigram db status
# Seed test datalexigram db seed
# View migration historylexigram db listDatabase commands require lexigram-sql to be installed:
uv add lexigram-sqlCode Generation (gen)
Section titled “Code Generation (gen)”# List all available generatorslexigram gen list
# Generate codelexigram gen model Userlexigram gen service UserServicelexigram gen repository UserRepositorylexigram gen controller UserControllerGenerators are contributed by installed packages. Each generator creates files in the current project’s source tree.
Runtime Inspection (inspect)
Section titled “Runtime Inspection (inspect)”# List registered container providerslexigram inspect providers
# Show HTTP routeslexigram inspect routes
# Display container bindingslexigram inspect container
# Run health checkslexigram inspect health
# View service listlexigram inspect servicesInteractive Shell (shell)
Section titled “Interactive Shell (shell)”# Start a REPL with the application context pre-loadedlexigram shell
# Plain Python REPL without app bootstraplexigram shell --no-app
# Use IPython if availablelexigram shell --ipythonThe shell provides app, container, config, db, cache, and events as pre-loaded objects.
Other Commands
Section titled “Other Commands”# System informationlexigram system infolexigram version
# Configuration managementlexigram config showlexigram config set default_template=full
# Contributor discoverylexigram contrib checklexigram contrib list
# Meta commandslexigram list # list all commandslexigram completion # generate shell completionlexigram test # run project testslexigram lint # run project lintersIntegration with the DI Container
Section titled “Integration with the DI Container”from lexigram import Applicationfrom lexigram.cli import CLIModule, CLIConfigfrom lexigram.cli.di.provider import CLIProvider
# Via module (recommended)app = Application(name="my-app")app.add_module(CLIModule.configure(CLIConfig(default_template="full")))
# Via provider directlyprovider = CLIProvider(config=CLIConfig(verbose=True))app.add_provider(provider)The CLIProvider has priority APPLICATION (40) — it boots after infrastructure but before domain services.
Best Practices
Section titled “Best Practices”- ✅ Run
lexigram gen listto see all available generators from installed packages - ✅ Use
lexigram project test/lintas a pre-commit gate - ✅ Run
lexigram contrib checkto verify contributors load cleanly after adding packages - ✅ Use
--jsonflag for machine-readable output (useful in CI scripts) - ❌ Don’t manually edit generated file headers — re-run the generator instead
- ❌ Don’t use
lexigram runin production — deploy through your ASGI server directly