📖 Looking for karrio's legacy docs? Visit docs.karrio.io

Environment Variables

This page provides a comprehensive reference for all environment variables you can use to configure your self-hosted Karrio instance.

Core Configuration

These variables control the basic functionality of your Karrio installation.

VariableDescriptionDefaultRequired
SECRET_KEYDjango secret key used for cryptographic signingRandom stringYes
DEBUG_MODEEnable debug mode (not recommended in production)FalseNo
USE_HTTPSEnable HTTPS supportFalseNo
DOMAINYour domain namelocalhostYes (for production)
ALLOWED_HOSTSComma-separated list of allowed hosts*No

Database Configuration

These variables configure the PostgreSQL database connection.

VariableDescriptionDefaultRequired
DATABASE_ENGINEDatabase engine to usepostgresql_psycopg2Yes
DATABASE_NAMEDatabase namedbYes
DATABASE_USERNAMEDatabase userpostgresYes
DATABASE_PASSWORDDatabase passwordpostgresYes
DATABASE_HOSTDatabase hostdbYes
DATABASE_PORTDatabase port5432Yes

Redis Configuration

Redis is used for caching and background task management. You can configure Redis using either a connection URL (recommended) or individual parameters.

VariableDescriptionDefaultRequired
REDIS_URLComplete Redis connection URL (e.g., redis://user:pass@host:port)NoneNo
REDIS_HOSTRedis host (used if REDIS_URL not set)NoneNo
REDIS_PORTRedis port (used if REDIS_URL not set)6379No
REDIS_PASSWORDRedis password (used if REDIS_URL not set)NoneNo
REDIS_USERNAMERedis username (used if REDIS_URL not set)defaultNo
REDIS_SSLEnable SSL/TLS for Redis connectionFalseNo
REDIS_PREFIXKey prefix for cached datakarrioNo

Note: REDIS_URL takes precedence over individual parameters. If REDIS_URL is set, it will supersede all individual Redis parameters (REDIS_HOST, REDIS_PORT, etc.). Use rediss:// scheme in the URL for SSL connections.

Examples:

  • Without SSL: REDIS_URL=redis://localhost:6379
  • With SSL: REDIS_URL=rediss://user:password@redis-host:6380/0
  • With individual params: REDIS_HOST=localhost REDIS_PORT=6379 REDIS_SSL=True

API Configuration

These variables configure the Karrio API server.

VariableDescriptionDefaultRequired
KARRIO_HTTP_PORTHTTP port for the API server5002No
KARRIO_PUBLIC_URLPublic URL for the APIhttp://localhost:5002Yes (for production)
KARRIO_WORKERSNumber of API workers2No

Background Workers & Tasks Configuration

These variables configure Huey background workers for async task processing (shipment tracking, webhooks, etc.).

VariableDescriptionDefaultRequired
BACKGROUND_WORKERSNumber of background worker processes2No
DETACHED_WORKERRun workers in detached mode (separate from API process)FalseNo
WORKER_IMMEDIATE_MODEExecute tasks immediately (useful for testing)FalseNo
WORKER_DB_DIRDirectory for SQLite task database (when Redis not available)/dataNo
TRACKING_PULSEInterval in seconds for automatic shipment tracking updates7200No
DEFAULT_SCHEDULER_RUN_INTERVALInterval in seconds for scheduled task checks3600No

Background Worker Modes:

  • Redis Mode (recommended for production): When Redis is configured, Huey uses Redis for task queue management. This allows multiple worker processes to share tasks.
  • SQLite Mode (development/single instance): When Redis is not configured, Huey uses SQLite for task storage. This mode is suitable for development or single-instance deployments.
  • Immediate Mode: When WORKER_IMMEDIATE_MODE=True, tasks execute synchronously in the same process. Useful for debugging.

Dashboard Configuration

These variables configure the Karrio dashboard.

VariableDescriptionDefaultRequired
DASHBOARD_PORTHTTP port for the dashboard3002No
DASHBOARD_URLPublic URL for the dashboardhttp://localhost:3002Yes (for production)
NEXTAUTH_SECRETSecret key for NextAuth (dashboard auth)Same as JWT_SECRETYes
JWT_SECRETSecret key for JWT tokensRandom stringYes

Email Configuration

These variables configure email sending for notifications.

VariableDescriptionDefaultRequired
EMAIL_HOSTSMTP server hostNoneNo
EMAIL_PORTSMTP server port587No
EMAIL_HOST_USERSMTP usernameNoneNo
EMAIL_HOST_PASSWORDSMTP passwordNoneNo
EMAIL_USE_TLSUse TLS for SMTP connectionTrueNo
DEFAULT_FROM_EMAILDefault sender email addressnoreply@localhostNo

Admin Account

These variables configure the default admin account created on first startup.

VariableDescriptionDefaultRequired
ADMIN_EMAILAdmin user emailadmin@example.comNo
ADMIN_PASSWORDAdmin user passworddemoNo

File Storage

These variables configure where files are stored.

VariableDescriptionDefaultRequired
WORK_DIRWorking directory for the API/karrio/appNo
LOG_DIRDirectory for log files/karrio/logNo
WORKER_DB_DIRDirectory for worker databases/karrio/dataNo
STATIC_ROOT_DIRDirectory for static files/karrio/staticNo
KARRIO_PLUGINSHost path for mounting plugins./pluginsNo

Advanced Configuration

These variables enable advanced features and optimizations.

VariableDescriptionDefaultRequired
LOG_LEVELLogging level (DEBUG, INFO, WARNING, ERROR)INFONo
SENTRY_DSNSentry DSN for error monitoringNoneNo
CORS_ALLOWED_ORIGINSComma-separated list of allowed CORS origins*No
MAX_UPLOAD_SIZEMaximum upload size in MB10No
THROTTLE_RATEAPI throttle rate (requests/minute)NoneNo
CACHE_TIMEOUTCache timeout in seconds300No

Observability Configuration (OpenTelemetry)

Karrio supports OpenTelemetry for distributed tracing, metrics, and logging. This allows you to monitor your Karrio deployment’s performance and troubleshoot issues across services.

VariableDescriptionDefaultRequired
OTEL_ENABLEDEnable OpenTelemetry instrumentationFalseNo
OTEL_SERVICE_NAMEService name for traces and metricskarrio-apiNo
OTEL_EXPORTER_OTLP_ENDPOINTOTLP exporter endpoint (e.g., http://jaeger:4317)NoneYes (if OTEL_ENABLED=True)
OTEL_EXPORTER_OTLP_PROTOCOLProtocol for OTLP exporter (grpc or http)grpcNo
OTEL_EXPORTER_OTLP_HEADERSHeaders for OTLP exporter (comma-separated key=value pairs)NoneNo
OTEL_ENVIRONMENTEnvironment name for telemetry data (e.g., production, staging)productionNo
OTEL_RESOURCE_ATTRIBUTESAdditional resource attributes (comma-separated key=value pairs)NoneNo

For detailed setup instructions, supported backends, and configuration examples, see the OpenTelemetry documentation.

Example .env File

Here’s a complete example of a .env file for a production deployment:

Core settings
1SECRET_KEY=your_secure_secret_key 2DEBUG_MODE=False 3USE_HTTPS=True 4DOMAIN=karrio.yourdomain.com 5 6# Database settings 7DATABASE_ENGINE=postgresql_psycopg2 8DATABASE_NAME=karrio 9DATABASE_USERNAME=karrio_user 10DATABASE_PASSWORD=your_secure_db_password 11DATABASE_HOST=db 12DATABASE_PORT=5432 13 14# Redis settings (Option 1: Using REDIS_URL - recommended) 15REDIS_URL=redis://redis:6379 16 17# Redis settings (Option 2: Individual parameters - alternative) 18# REDIS_HOST=redis 19# REDIS_PORT=6379 20# REDIS_SSL=False 21# REDIS_PASSWORD=your_redis_password # if required 22# REDIS_USERNAME=default # if required 23 24# API settings 25KARRIO_PUBLIC_URL=https://api.yourdomain.com 26KARRIO_WORKERS=4 27 28# Background worker settings 29BACKGROUND_WORKERS=2 30DETACHED_WORKER=True 31TRACKING_PULSE=7200 # 2 hours in seconds 32 33# Dashboard settings 34DASHBOARD_URL=https://app.yourdomain.com 35JWT_SECRET=your_secure_jwt_secret 36 37# Email settings 38EMAIL_HOST=smtp.provider.com 39EMAIL_PORT=587 40EMAIL_HOST_USER=your_email@provider.com 41EMAIL_HOST_PASSWORD=your_email_password 42EMAIL_USE_TLS=True 43DEFAULT_FROM_EMAIL=karrio@yourdomain.com 44 45# Admin account 46ADMIN_EMAIL=admin@yourdomain.com 47ADMIN_PASSWORD=your_secure_admin_password 48 49# Plugin mounting 50KARRIO_PLUGINS=./plugins 51 52# Carrier credentials - USPS example 53USPS_USERNAME=your_usps_username 54USPS_PASSWORD=your_usps_password 55USPS_TEST_MODE=False

Redis SSL/TLS Configuration Examples

For secure Redis connections (common with managed Redis services like AWS ElastiCache, Azure Cache, or Redis Enterprise), use these configurations:

Using REDIS_URL with SSL

AWS ElastiCache example (rediss:// scheme for SSL)
1REDIS_URL=rediss://master.your-cluster.cache.amazonaws.com:6380/0 2 3# Azure Cache for Redis example with password 4REDIS_URL=rediss://:your_access_key@your-cache.redis.cache.windows.net:6380/0 5 6# Redis Enterprise Cloud example with username and password 7REDIS_URL=rediss://default:your_password@redis-endpoint.cloud.redislabs.com:12345/0

Using Individual Parameters with SSL

Managed Redis with SSL enabled
1REDIS_HOST=master.your-cluster.cache.amazonaws.com 2REDIS_PORT=6380 3REDIS_SSL=True 4REDIS_PASSWORD=your_redis_password 5REDIS_USERNAME=default

Important Notes:

  • Most managed Redis services use port 6380 for SSL connections and port 6379 for non-SSL
  • The rediss:// scheme (with double ‘s’) in REDIS_URL automatically enables SSL
  • When using individual parameters, set REDIS_SSL=True to enable SSL
  • Some providers (like Azure) require authentication - include credentials in the URL or via separate parameters

Environment Variables in Docker

When using Docker, there are multiple ways to set environment variables:

  1. Docker Compose: Add environment variables in the docker-compose.yml file under the appropriate service:
1services: 2 api: 3 environment: 4 SECRET_KEY: your_secure_secret_key 5 DEBUG_MODE: "False" 6 # other variables
  1. Environment Files: Use an .env file in the same directory as your docker-compose.yml file. Docker Compose will automatically load these variables.

  2. Command Line: Pass variables through the command line when running containers:

1docker-compose up -d -e SECRET_KEY=your_secure_secret_key

Best Practices

  1. Security: Never commit sensitive environment variables to your repository. Use .env files that are added to your .gitignore.

  2. Production vs. Development: Maintain separate environment files for different environments.

  3. Secret Management: For production deployments, consider using a secret management service like AWS Secrets Manager, GCP Secret Manager, or HashiCorp Vault.

  4. Documentation: Document any custom environment variables you create for your specific deployment or extensions.