Skip to content

Configuration

Horizon reads application settings from config.yml in the current working directory. Use HORIZON_CONFIG_FILE to point to another YAML file.

config.yml
admin_users:
  - admin

database:
  url: postgresql+asyncpg://user:password@localhost:5432/horizon

server:
  debug: true
  cors:
    enabled: true
    allow_origins: ["*"]

Every setting can also be passed through an environment variable. Environment variable names are prefixed with HORIZON__, and nested keys are separated with __.

Environment variables
export HORIZON__DATABASE__URL=postgresql+asyncpg://user:password@localhost:5432/horizon
export HORIZON__ADMIN_USERS='["admin"]'
export HORIZON__SERVER__DEBUG=true
export HORIZON__SERVER__CORS__ENABLED=true
export HORIZON__SERVER__CORS__ALLOW_ORIGINS='["*"]'

Values loaded from the YAML file override values passed through environment variables. Settings passed directly to the Settings constructor have the highest priority.

Settings

Horizon backend settings.

Backend can be configured in 3 ways, in descending order of priority:

  • By explicitly passing settings object as an argument to application_factory
  • By storing settings in a config.yml configuration file
  • By setting environment variables matching a specific key

Environment variable names are written in uppercase, prefixed with HORIZON__, and use __ to delimit nested items.

More details can be found in Pydantic documentation.

Examples:

config.yml
database:
  url: postgresql+asyncpg://postgres:postgres@localhost:5432/horizon

server:
  debug: true

auth:
  provider: horizon.backend.providers.auth.dummy.DummyAuthProvider

admin_users:

- admin

Parameters:

  • database

    (DatabaseSettings, default: <dynamic> ) –

    Database settings

  • logging

    (LoggingSettings, default: LoggingSettings(version=1, formatters={'colored': FormatterConfig(format='%(asctime)s.%(msecs)03d %(processName)s:%(process)d %(name)s:%(lineno)d [%(levelname)s] %(correlation_id)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', style='%', validate_format=None, defaults=None, class_='coloredlogs.ColoredFormatter')}, filters={'correlation_id': CallableFactoryConfig(callable='asgi_correlation_id.CorrelationIdFilter', uuid_length=32, default_value='-')}, handlers={'main': StreamHandlerConfig(class_='logging.StreamHandler', level=None, formatter='colored', filters=['correlation_id'], stream='ext://sys.stdout')}, loggers={'uvicorn': LoggerConfig(level='INFO', propagate=False, filters=None, handlers=['main'])}, root=RootLoggerConfig(level='INFO', filters=None, handlers=['main']), incremental=False, disable_existing_loggers=False) ) –

    Logging settings

  • server

    (ServerSettings, default: <dynamic> ) –

    Server settings

  • auth

    (AuthSettings, default: <dynamic> ) –

    Auth provider setting

  • admin_users

    (list[str], default: <dynamic> ) –

ServerSettings

Backend server settings.

Examples:

config.yml
server:
  debug: true
  monitoring:
    enabled: true
  cors:
    enabled: true
  request_id:
    enabled: true
  openapi:
    enabled: true
    swagger:
      enabled: true
    redoc:
      enabled: true

Parameters: