OxenORM provides a comprehensive command-line interface for database management, migrations, and development tasks.
The CLI is automatically installed with OxenORM:
pip install oxen-ormThe CLI is accessed via the oxen command:
oxen --help
oxen <command> --helpInitialize a new database connection and create tables:
# Initialize with connection string
oxen db init --url postgresql://user:pass@localhost/mydb
# Initialize with config file
oxen db init --config config.yaml
# Initialize with environment variables
oxen db init --env-file .envCheck the status of your database connection:
# Check connection status
oxen db status --url postgresql://user:pass@localhost/mydb
# Check with detailed information
oxen db status --url postgresql://user:pass@localhost/mydb --verbose
# Check multiple databases
oxen db status --config multi_db_config.yamlCreate tables for your models:
# Create all tables
oxen schema create --url postgresql://user:pass@localhost/mydb
# Create specific tables
oxen schema create --url postgresql://user:pass@localhost/mydb --models User,Post
# Create with custom schema
oxen schema create --url postgresql://user:pass@localhost/mydb --schema publicDrop tables from the database:
# Drop all tables
oxen schema drop --url postgresql://user:pass@localhost/mydb
# Drop specific tables
oxen schema drop --url postgresql://user:pass@localhost/mydb --models User,Post
# Drop with confirmation
oxen schema drop --url postgresql://user:pass@localhost/mydb --confirmInspect the current database schema:
# Show all tables
oxen schema inspect --url postgresql://user:pass@localhost/mydb
# Show specific table
oxen schema inspect --url postgresql://user:pass@localhost/mydb --table users
# Export schema to file
oxen schema inspect --url postgresql://user:pass@localhost/mydb --output schema.json
# Show with details
oxen schema inspect --url postgresql://user:pass@localhost/mydb --verboseGenerate migration files for schema changes:
# Create migration for all changes
oxen migrate makemigrations --url postgresql://user:pass@localhost/mydb
# Create migration for specific models
oxen migrate makemigrations --url postgresql://user:pass@localhost/mydb --models User,Post
# Create migration with custom name
oxen migrate makemigrations --url postgresql://user:pass@localhost/mydb --name add_user_fields
# Create migration with custom path
oxen migrate makemigrations --url postgresql://user:pass@localhost/mydb --migrations-dir ./migrationsApply pending migrations to the database:
# Apply all pending migrations
oxen migrate migrate --url postgresql://user:pass@localhost/mydb
# Apply specific migration
oxen migrate migrate --url postgresql://user:pass@localhost/mydb --migration 0001_initial
# Apply with fake flag (for testing)
oxen migrate migrate --url postgresql://user:pass@localhost/mydb --fake
# Apply with dry-run
oxen migrate migrate --url postgresql://user:pass@localhost/mydb --dry-runCheck the status of migrations:
# Show migration status
oxen migrate show --url postgresql://user:pass@localhost/mydb
# Show with details
oxen migrate show --url postgresql://user:pass@localhost/mydb --verbose
# Show specific migration
oxen migrate show --url postgresql://user:pass@localhost/mydb --migration 0001_initialRollback applied migrations:
# Rollback last migration
oxen migrate rollback --url postgresql://user:pass@localhost/mydb
# Rollback specific number of migrations
oxen migrate rollback --url postgresql://user:pass@localhost/mydb --steps 3
# Rollback to specific migration
oxen migrate rollback --url postgresql://user:pass@localhost/mydb --to 0001_initialRun performance benchmarks on your database:
# Run basic performance test
oxen benchmark performance --url postgresql://user:pass@localhost/mydb
# Run with custom iterations
oxen benchmark performance --url postgresql://user:pass@localhost/mydb --iterations 1000
# Run specific benchmarks
oxen benchmark performance --url postgresql://user:pass@localhost/mydb --benchmarks crud,query,bulk
# Run with custom data size
oxen benchmark performance --url postgresql://user:pass@localhost/mydb --data-size 10000
# Export results to file
oxen benchmark performance --url postgresql://user:pass@localhost/mydb --output results.jsonMonitor database performance in real-time:
# Start performance monitoring
oxen monitor start --url postgresql://user:pass@localhost/mydb
# Monitor with custom interval
oxen monitor start --url postgresql://user:pass@localhost/mydb --interval 5
# Monitor specific metrics
oxen monitor start --url postgresql://user:pass@localhost/mydb --metrics queries,connections,performance
# Export monitoring data
oxen monitor start --url postgresql://user:pass@localhost/mydb --output monitoring.logStart an interactive Python shell with OxenORM:
# Start interactive shell
oxen shell --url postgresql://user:pass@localhost/mydb
# Start with specific models
oxen shell --url postgresql://user:pass@localhost/mydb --models User,Post
# Start with custom Python path
oxen shell --url postgresql://user:pass@localhost/mydb --python-path ./myapp
# Start with custom environment
oxen shell --url postgresql://user:pass@localhost/mydb --env-file .envGenerate code templates and boilerplate:
# Generate model template
oxen generate model User --fields name:CharField,email:CharField,age:IntField
# Generate migration template
oxen generate migration add_user_fields --models User
# Generate API template
oxen generate api User --methods create,read,update,delete
# Generate test template
oxen generate test User --coverageImport data from various sources:
# Import from CSV
oxen data import --url postgresql://user:pass@localhost/mydb --file users.csv --model User
# Import from JSON
oxen data import --url postgresql://user:pass@localhost/mydb --file users.json --model User
# Import with custom mapping
oxen data import --url postgresql://user:pass@localhost/mydb --file users.csv --model User --mapping name:full_name,email:email_address
# Import with validation
oxen data import --url postgresql://user:pass@localhost/mydb --file users.csv --model User --validateExport data to various formats:
# Export to CSV
oxen data export --url postgresql://user:pass@localhost/mydb --model User --output users.csv
# Export to JSON
oxen data export --url postgresql://user:pass@localhost/mydb --model User --output users.json
# Export with filters
oxen data export --url postgresql://user:pass@localhost/mydb --model User --filter "is_active=True" --output active_users.csv
# Export with custom fields
oxen data export --url postgresql://user:pass@localhost/mydb --model User --fields name,email --output user_names.csvOxenORM CLI supports configuration files:
# config.yaml
databases:
default:
url: postgresql://user:pass@localhost/mydb
pool_size: 10
max_overflow: 20
analytics:
url: mysql://user:pass@localhost/analytics
pool_size: 5
logging:
level: INFO
format: json
file: oxenorm.log
performance:
query_cache_ttl: 300
connection_pool_health_check: trueUsing configuration files:
# Use config file
oxen db init --config config.yaml
# Use specific database from config
oxen db status --config config.yaml --database analyticsOxenORM CLI supports environment variables:
# Set database URL
export OXENORM_DATABASE_URL="postgresql://user:pass@localhost/mydb"
# Set log level
export OXENORM_LOG_LEVEL="DEBUG"
# Use environment variables
oxen db init
oxen db statusAll commands support these global options:
--help, -h Show help message
--version, -v Show version information
--verbose, -V Enable verbose output
--quiet, -q Suppress output
--config, -c Configuration file path
--env-file, -e Environment file pathDatabase-related commands support:
--url, -u Database connection URL
--database, -d Database name (for multi-database configs)
--timeout, -t Connection timeout in seconds
--pool-size, -p Connection pool size
--ssl-mode SSL mode (disable, allow, prefer, require)Commands that produce output support:
--output, -o Output file path
--format, -f Output format (json, csv, table, yaml)
--pretty, -P Pretty-print output
--no-color Disable colored outputHere's a complete workflow example:
# 1. Initialize database
oxen db init --url postgresql://user:pass@localhost/mydb
# 2. Create initial migration
oxen migrate makemigrations --url postgresql://user:pass@localhost/mydb --name initial
# 3. Apply migration
oxen migrate migrate --url postgresql://user:pass@localhost/mydb
# 4. Import initial data
oxen data import --url postgresql://user:pass@localhost/mydb --file users.csv --model User
# 5. Run performance test
oxen benchmark performance --url postgresql://user:pass@localhost/mydb --iterations 1000
# 6. Start monitoring
oxen monitor start --url postgresql://user:pass@localhost/mydb --interval 10Development workflow with OxenORM CLI:
# 1. Start development shell
oxen shell --url postgresql://user:pass@localhost/mydb --models User,Post
# 2. Make model changes in Python shell
# ... make changes ...
# 3. Generate migration for changes
oxen migrate makemigrations --url postgresql://user:pass@localhost/mydb --name add_user_fields
# 4. Apply migration
oxen migrate migrate --url postgresql://user:pass@localhost/mydb
# 5. Test performance
oxen benchmark performance --url postgresql://user:pass@localhost/mydb --benchmarks crud
# 6. Export test data
oxen data export --url postgresql://user:pass@localhost/mydb --model User --output test_users.csvProduction deployment workflow:
# 1. Check database status
oxen db status --url postgresql://user:pass@localhost/prod_db --verbose
# 2. Apply migrations
oxen migrate migrate --url postgresql://user:pass@localhost/prod_db
# 3. Import production data
oxen data import --url postgresql://user:pass@localhost/prod_db --file prod_data.csv --model User --validate
# 4. Start monitoring
oxen monitor start --url postgresql://user:pass@localhost/prod_db --interval 30 --output prod_monitoring.log
# 5. Run performance benchmarks
oxen benchmark performance --url postgresql://user:pass@localhost/prod_db --iterations 5000 --output prod_benchmarks.jsonConnection Issues:
# Test connection
oxen db status --url postgresql://user:pass@localhost/mydb --verbose
# Check SSL settings
oxen db status --url postgresql://user:pass@localhost/mydb --ssl-mode require
# Check timeout settings
oxen db status --url postgresql://user:pass@localhost/mydb --timeout 30Migration Issues:
# Check migration status
oxen migrate show --url postgresql://user:pass@localhost/mydb --verbose
# Rollback problematic migration
oxen migrate rollback --url postgresql://user:pass@localhost/mydb --steps 1
# Fake migration (mark as applied without running)
oxen migrate migrate --url postgresql://user:pass@localhost/mydb --fakePerformance Issues:
# Run detailed performance test
oxen benchmark performance --url postgresql://user:pass@localhost/mydb --iterations 10000 --verbose
# Monitor in real-time
oxen monitor start --url postgresql://user:pass@localhost/mydb --interval 5 --metrics all
# Check connection pool
oxen db status --url postgresql://user:pass@localhost/mydb --verboseEnable debug mode for troubleshooting:
# Enable debug logging
export OXENORM_LOG_LEVEL="DEBUG"
oxen db status --url postgresql://user:pass@localhost/mydb --verbose
# Enable SQL logging
export OXENORM_LOG_SQL="true"
oxen migrate migrate --url postgresql://user:pass@localhost/mydb --verbose
# Enable performance logging
export OXENORM_LOG_PERFORMANCE="true"
oxen benchmark performance --url postgresql://user:pass@localhost/mydb --verbose