Skip to content

Environment Variables

Tina4 Python is configured through environment variables, read from .env at the project root. Every variable has a sensible default — most projects set three or four values and leave the rest alone.

This chapter lists every variable the Python framework reads, grouped by subsystem. Start with the minimum-config examples at the end, then come back here when you need to tune something specific.


Core Server

VariableDefaultDescription
HOST0.0.0.0Bind address. 0.0.0.0 listens on every interface. 127.0.0.1 restricts to localhost.
PORT7145HTTP server port. The Rust CLI prefers TINA4_PORT but falls back to PORT.
TINA4_PORT(inherits PORT)Explicit Tina4-specific port override. Takes precedence over PORT when both are set.
HOST_NAMElocalhost:7145Fully-qualified host used in generated absolute URLs (Swagger, OAuth redirects, emails).
TINA4_DEBUGfalseMaster debug toggle. Enables Swagger UI, dev dashboard, live reload, template dump filter, error overlay. Never set to true in production.
TINA4_ENVdevelopmentRuntime environment label. Values like development, staging, production control dev-only features.
TINA4_NO_BROWSERfalseStops tina4 serve from opening your browser on every restart. Recommended during active development.
TINA4_OPEN_BROWSERtrueAlternative flag — set to false to prevent the browser opening on start.
TINA4_NO_RELOADfalseDisables the dev hot-reload signal from the Rust CLI. Use when you want a stable server for debugging.
TINA4_DEV_POLL_INTERVAL1.0Seconds between dev-mode mtime polls. Lower for faster reload, higher to reduce CPU.
TINA4_PUBLIC_DIRsrc/publicDirectory served as static files under /.

Secrets and Authentication

VariableDefaultDescription
SECRETtina4-default-secretJWT signing secret. Must be long, random, and unique per environment. Never commit.
TINA4_TOKEN_LIMIT60JWT token lifetime in minutes.
TINA4_TOKEN_EXPIRES_IN(inherits TOKEN_LIMIT)Alias for TINA4_TOKEN_LIMIT.
TINA4_API_KEY(empty)Static API key used by Auth.validate_api_key() as a fallback to JWT.
API_KEY(empty)Legacy alias for TINA4_API_KEY.

Database

VariableDefaultDescription
DATABASE_URLsqlite:///data/app.dbConnection URL. Scheme selects the driver: sqlite, postgres, mysql, firebird.
DATABASE_USERNAME(empty)Overrides the username embedded in DATABASE_URL.
DATABASE_PASSWORD(empty)Overrides the password embedded in DATABASE_URL.
TINA4_DB_CACHEfalseEnables in-memory query-result caching for read queries.
TINA4_DB_CACHE_TTL60Query cache TTL in seconds when TINA4_DB_CACHE=true.
ORM_PLURAL_TABLE_NAMEStrueWhen true, the ORM pluralises class names into table names (Userusers). Set false to keep them singular.

CORS

VariableDefaultDescription
TINA4_CORS_ORIGINS*Comma-separated allowed origins. Lock down to real domains in production.
TINA4_CORS_MAX_AGE600Preflight cache lifetime in seconds.

Security Headers

VariableDefaultDescription
TINA4_CSPdefault-src 'self'Content-Security-Policy header.
TINA4_CSRFtrueCSRF token validation on POST/PUT/PATCH/DELETE.
TINA4_HSTS(empty/off)Strict-Transport-Security max-age in seconds. Set 31536000 in production with HTTPS.
TINA4_FRAME_OPTIONSDENYX-Frame-Options header.
TINA4_REFERRER_POLICYstrict-origin-when-cross-originReferrer-Policy header.

Rate Limiting

VariableDefaultDescription
TINA4_RATE_LIMIT100Maximum requests per window per IP. Set 0 to disable.
TINA4_RATE_WINDOW60Rate-limit window in seconds.

Sessions

VariableDefaultDescription
TINA4_SESSION_BACKENDfileStorage backend. Options: file, redis, valkey, mongo, database.
TINA4_SESSION_TTL1800Session expiry in seconds (30 minutes).
TINA4_SESSION_SAMESITELaxSameSite cookie attribute. Options: Strict, Lax, None.
TINA4_SESSION_PATHdata/sessionsFilesystem path for the file backend.
TINA4_SESSIONPY_SESSName of the session cookie.

Redis/Valkey session backend

VariableDefaultDescription
TINA4_SESSION_REDIS_HOSTlocalhostRedis host.
TINA4_SESSION_REDIS_PORT6379Redis port.
TINA4_SESSION_REDIS_PASSWORD(none)Redis auth password.
TINA4_SESSION_REDIS_DB0Redis database number.
TINA4_SESSION_VALKEY_HOSTlocalhostValkey host.
TINA4_SESSION_VALKEY_PORT6379Valkey port.
TINA4_SESSION_VALKEY_PASSWORD(none)Valkey auth password.
TINA4_SESSION_VALKEY_DB0Valkey database number.

MongoDB session backend

VariableDefaultDescription
TINA4_SESSION_MONGO_URLmongodb://localhost:27017MongoDB connection string.
TINA4_SESSION_MONGO_DBtina4MongoDB database name.
TINA4_SESSION_MONGO_COLLECTIONsessionsMongoDB collection name.

Cache

VariableDefaultDescription
TINA4_CACHE_BACKENDmemoryResponse cache backend. Options: memory, file, redis.
TINA4_CACHE_DIRdata/cacheCache directory for the file backend.
TINA4_CACHE_TTL60Default cache TTL in seconds.
TINA4_CACHE_MAX_ENTRIES1000Maximum cache entries. Oldest entries evicted first.
TINA4_CACHE_URLredis://localhost:6379Connection URL for remote cache backends.

Queues

VariableDefaultDescription
TINA4_QUEUE_BACKENDliteQueue backend. Options: lite (file-based), kafka, rabbitmq, mongo, database.
TINA4_QUEUE_PATHdata/queueFilesystem path for the lite backend.
TINA4_QUEUE_URL(none)Connection URL for remote backends.

Kafka queue backend

VariableDefaultDescription
TINA4_KAFKA_BROKERSlocalhost:9092Comma-separated broker list.
TINA4_KAFKA_GROUP_IDtina4_consumer_groupKafka consumer group ID.

RabbitMQ queue backend

VariableDefaultDescription
TINA4_RABBITMQ_HOSTlocalhostRabbitMQ host.
TINA4_RABBITMQ_PORT5672RabbitMQ port.
TINA4_RABBITMQ_USERNAMEguestRabbitMQ username.
TINA4_RABBITMQ_PASSWORDguestRabbitMQ password.
TINA4_RABBITMQ_VHOST/RabbitMQ virtual host.

MongoDB queue backend

VariableDefaultDescription
TINA4_MONGO_URI(none)Full MongoDB connection string. Overrides host/port when set.
TINA4_MONGO_HOSTlocalhostMongoDB host.
TINA4_MONGO_PORT27017MongoDB port.
TINA4_MONGO_USERNAME(none)MongoDB username.
TINA4_MONGO_PASSWORD(none)MongoDB password.
TINA4_MONGO_DBtina4MongoDB database name.
TINA4_MONGO_COLLECTIONtina4_queueMongoDB collection name for jobs.

WebSocket

VariableDefaultDescription
TINA4_WS_BACKPLANE(none)Backplane type. Set redis for multi-instance broadcasts.
TINA4_WS_MAX_CONNECTIONS1000Maximum concurrent WebSocket connections.
TINA4_WS_MAX_FRAME_SIZE65536Maximum WebSocket frame size in bytes.

Email

VariableDefaultDescription
TINA4_MAIL_HOST(none)SMTP server hostname.
TINA4_MAIL_PORT587SMTP server port.
TINA4_MAIL_USERNAME(none)SMTP authentication username.
TINA4_MAIL_PASSWORD(none)SMTP authentication password.
TINA4_MAIL_FROM(none)Default sender email address.
TINA4_MAIL_FROM_NAME(none)Default sender display name.
TINA4_MAIL_ENCRYPTIONtlsConnection encryption. Options: tls, ssl, none.
TINA4_MAIL_IMAP_HOST(none)IMAP server for inbound mail.
TINA4_MAIL_IMAP_PORT993IMAP server port.
TINA4_MAILBOX_DIRdata/mailboxDev mailbox directory. All outbound mail lands here when TINA4_DEBUG=true.

SMTP_HOST, SMTP_PORT, SMTP_USERNAME, SMTP_PASSWORD, SMTP_FROM, SMTP_FROM_NAME, IMAP_HOST, IMAP_PORT are accepted as legacy aliases. New projects should use the TINA4_MAIL_* names.


Logging

VariableDefaultDescription
TINA4_LOG_LEVELERRORMinimum log level written to files. Options: ALL, DEBUG, INFO, WARNING, ERROR.
TINA4_LOG_MAX_SIZE10485760Per-file log size limit in bytes (10 MB). Rotated when exceeded.
TINA4_LOG_KEEP5Number of rotated log files to retain.

Uploads

VariableDefaultDescription
TINA4_MAX_UPLOAD_SIZE10485760Maximum multipart upload size in bytes (10 MB).

Localisation

VariableDefaultDescription
TINA4_LOCALEenDefault locale for the I18n module.
TINA4_LOCALE_DIRsrc/localeDirectory containing locale JSON files.

Services (background tasks)

VariableDefaultDescription
TINA4_SERVICE_DIRsrc/servicesDirectory scanned for service classes.

AI and MCP Tooling

VariableDefaultDescription
TINA4_NO_AI_PORTfalseDisables the MCP port listener in dev mode.
TINA4_OVERRIDE_CLIENT(none)Forces a specific AI client ID in /__dev/api/ai. Used for testing.
ANTHROPIC_API_KEY(none)Anthropic API key for built-in AI integrations.
OPENAI_API_KEY(none)OpenAI API key for built-in AI integrations.

Swagger / OpenAPI

VariableDefaultDescription
SWAGGER_TITLETina4 APIOpenAPI spec title.
SWAGGER_DESCRIPTION(empty)OpenAPI spec description.
SWAGGER_VERSION1.0.0OpenAPI spec version.

Minimal .env for Development

bash
TINA4_DEBUG=true
TINA4_LOG_LEVEL=DEBUG
TINA4_NO_BROWSER=true

Debug mode lights up the Swagger UI, the dev dashboard, detailed error pages, and live reload. Keeping the browser flag on stops a new tab opening every time you save a file.


Minimal .env for Production

bash
SECRET=your-long-random-secret-here
DATABASE_URL=postgresql://user:password@db-host:5432/myapp
TINA4_CORS_ORIGINS=https://myapp.com,https://www.myapp.com
TINA4_HSTS=31536000
TINA4_MAIL_HOST=smtp.example.com
TINA4_MAIL_PORT=587
TINA4_MAIL_USERNAME=noreply@myapp.com
TINA4_MAIL_PASSWORD=your-smtp-password
TINA4_MAIL_FROM=noreply@myapp.com

No TINA4_DEBUG. It defaults to false, which is what you want in production. Set a real secret, a real database, locked-down CORS origins, HSTS, and SMTP credentials if you send email. Everything else has a production-appropriate default.

Sponsored with 🩵 by Code InfinityCode Infinity