Configurations¶
Keywords: environment variables, .env, app config, settings, env casting, settings dictionary, config variables
Asok is designed to require minimal configuration for common use-cases, but it provides a comprehensive set of options that can be tuned via environment variables or directly in your wsgi.py / asgi.py file.
1. Core Settings¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
bool |
|
Enables detailed error pages and auto-reloading. Set to |
|
str |
auto |
Used for signing cookies, tokens, and CSRF protection. Required (min 32 chars) in production. |
|
str |
|
The name of the default entry point file in your page directories. |
|
str |
|
The default language code for translations. |
|
str |
|
The display name of your project. |
|
str |
|
Your application’s current version. |
|
bool |
|
Set to |
|
str |
|
The class name of the User model used for authentication (e.g., |
|
str |
|
Environment mode (e.g., |
2. Server & Routing¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
The base URL of your app (e.g., |
|
int |
|
The default port for the |
|
int |
|
The port used by the built-in WebSocket server. |
|
list/str |
|
Comma-separated list of allowed origins for WebSocket connections. If not set, falls back to |
|
int |
|
Maximum allowed size (in bytes) for request bodies (default 10 MB). |
|
list/str |
|
List of IP addresses (or |
|
bool |
|
Alias for |
|
bool |
|
Enables or disables the automatic documentation UI. |
3. Session Management¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
Storage backend for sessions: |
|
str |
|
Directory path for file-based session storage. |
|
int |
|
Max age for the session cookie (in seconds, default 30 days). |
|
int |
|
Server-side session expiration time (in seconds, default 24 hours). |
|
str |
|
SameSite attribute for the session cookie ( |
|
bool |
auto |
Forces session cookie to be sent over HTTPS only. Defaults to |
|
str |
|
Connection string for Redis backend (e.g., |
|
int |
|
Expiration time for authentication magic links (in seconds, default 1 hour). |
4. Caching System¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
Caching backend: |
|
str |
|
Directory path for file-based caching. |
5. Security & CORS¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
bool |
|
Enables global Cross-Site Request Forgery protection for forms. |
|
list/str |
|
Allowed origins for cross-domain requests. Use |
|
bool/dict |
|
Enables default security headers (CSP, HSTS, etc.). Can be customized with a dict. |
|
dict |
|
Dictionary of custom Content Security Policy (CSP) directives to extend or override defaults. |
|
bool |
|
Optional. Forces |
|
str |
|
Endpoint URL to receive Content Security Policy (CSP) violation reports. |
|
bool |
|
Enables automatic conditional caching headers for responses. |
|
bool |
|
Enables or disables the developer debugging toolbar. Also accepts |
|
bool |
|
Enables global request rate limiting. |
|
int |
|
Max requests allowed per IP per minute if rate limiting is enabled. |
6. Performance & Optimization¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
bool |
|
Enables transparent Gzip compression for text-based responses. |
|
int |
|
Minimum response size (in bytes) to trigger Gzip compression. |
|
bool |
|
Enables aggressive whitespace removal for HTML responses. |
|
bool |
|
Enables automatic WebP conversion for uploaded/served images. |
|
bool |
|
Retains the original uploaded file when generating optimized versions. |
7. File Storage & Uploads¶
Configure where and how files uploaded via forms are saved on the server.
Key |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
Storage backend: |
|
str |
|
The name of the S3 bucket. Also accepts |
|
str |
|
The S3 region. Also accepts |
|
str |
|
Optional S3 endpoint URL (useful for custom endpoints like MinIO, DigitalOcean Spaces). |
|
str |
|
AWS access key credential. |
|
str |
|
AWS secret key credential. |
|
str |
|
Optional custom CDN domain mapping (e.g. |
|
bool |
|
Optional. Set to |
8. Background Tasks & Queue¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
Tasks queue backend: |
|
int |
|
Maximum background threads in the local thread pool. |
|
str |
|
Redis connection URL (e.g. |
|
int |
|
Number of concurrent execution threads in the Redis worker pool. |
|
str |
|
Comma-separated list of queue names to poll from in order of priority. |
9. Database & ORM¶
Asok supports SQLite (default, zero dependencies), PostgreSQL, and MySQL.
Key |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
Connection DSN. Can be SQLite ( |
10. Email Configuration¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
SMTP server hostname. |
|
int |
|
SMTP server port. |
|
str |
|
Username for SMTP authentication. |
|
str |
|
Password for SMTP authentication. |
|
str |
|
Default sender address. |
|
bool |
|
Use TLS for secure email transmission. |
11. Logging¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
Minimal logging level ( |
|
str |
|
Optional path to a file for persistent logging. |
|
str |
|
Format of logs: |
12. API, GraphQL & UI¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
The URL path where the auto-generated docs are served. |
|
str |
|
The URL path for the generated OpenAPI specification. |
|
callable |
|
Hook |
|
str |
PROJECT_NAME |
The title shown in the documentation UI. |
|
str |
SITE_LOGO |
URL of the logo shown in the documentation UI. |
|
str |
|
URL of the default site-wide logo (fallback for |
|
bool |
|
Show “GraphQL Explorer” link in the |
|
str |
|
Path used for the docs sidebar link. Does not change the actual endpoint. |
|
callable |
|
Hook |
|
bool |
|
Set to |
|
int |
|
Statically checks query complexity to prevent abuse. |
|
int |
|
Maximum allowed query nesting depth. |
13. Admin Interface¶
The Admin interface is initialized by passing parameters to the Admin extension class in wsgi.py.
Param |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
Branding title shown in the sidebar and page titles. |
|
str |
|
The URL path where the admin interface is served. |
|
str |
|
Default language for the admin interface. |
|
str |
|
Path to a custom logo/favicon (resolves to |
|
tuple |
|
Bruteforce protection: |
14. Mandatory Production Settings¶
When running Asok in production (DEBUG=False), certain configurations are strictly enforced to ensure the security of your application. The framework will raise a RuntimeError on startup if these are missing or insecure.
Required Variables¶
Key |
Requirement |
Rationale |
|---|---|---|
|
Must be at least 32 characters |
Used for HMAC signing of sessions, CSRF tokens, and secure cookies. |
|
Must be a valid URL (e.g., |
Required to prevent Host Header Injection and to generate absolute URLs for Magic Links. |
How to Configure¶
You can define your configurations in two ways. Asok will merge them, with wsgi.py settings taking precedence over .env.
Option A: Using a .env file (Recommended)¶
Create a .env file in your project root. This is the preferred method for sensitive secrets.
DEBUG=false
SECRET_KEY=your-ultra-secure-64-character-key-here
APP_URL=https://myapp.com
DATABASE_URL=sqlite:///data/prod.db
Option B: In your wsgi.py¶
You can set configurations directly on the app instance using the config dictionary.
from asok import Asok
app = Asok()
# Production overrides
app.config["DEBUG"] = False
app.config["SECRET_KEY"] = "your-ultra-secure-64-character-key-here"
app.config["APP_URL"] = "https://myapp.com"
In production,
DEBUGdefaults toFalse. You only need to set it toTrueexplicitly in your development environment.