Configuration Overview
The pydoover configuration system provides a declarative way to define application settings. Configuration schemas automatically generate JSON Schema definitions that enable validation, UI form rendering in the Doover dashboard, and type-safe access to configuration values at runtime.
Key Features
- Declarative Schema Definition: Define configuration using Python classes with typed elements
- JSON Schema Generation: Automatic generation of JSON Schema for validation
- UI Form Generation: Configuration schemas render as forms in the Doover UI
- Type Safety: Access configuration values with proper Python types
- Deployment Injection: Configuration values are injected at deployment time
Basic Usage
Create a configuration schema by subclassing config.Schema and defining elements in __init__:
from pydoover import config
class MyAppConfig(config.Schema):
def __init__(self):
self.pump_pin = config.Integer(
"Digital Output Number",
description="The digital output pin to drive the pump."
)
self.pump_on_time = config.Number(
"Pump On Time",
default=5.2,
description="The time in seconds to run the pump."
)
self.engine_type = config.Enum(
"Engine Type",
choices=["Honda", "John Deere", "Cat"],
default="Honda",
description="The type of diesel engine attached to the pump."
)
How It Works
Schema Definition
When you define a Schema subclass, each attribute you assign becomes a configuration element. The order in which you define elements is preserved, which determines the display order in the UI.
Element Keys
Element display names are transformed into keys for the JSON Schema:
- Converted to lowercase
- Spaces replaced with underscores
For example, "Digital Output Number" becomes digital_output_number.
Required vs Optional
Elements without a default value are considered required. Elements with a default value are optional:
# Required - no default value
self.api_key = config.String("API Key")
# Optional - has default value
self.timeout = config.Integer("Timeout", default=30)
Deployment Configuration
When your application runs, the schema receives configuration values from the deployment:
- Values from the deployment config are injected into matching elements
- Missing optional elements use their default values
- Missing required elements raise a
ValueError
Generated JSON Schema
The schema exports to JSON Schema format (draft 2020-12):
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "",
"title": "Application Config",
"type": "object",
"properties": {
"pump_pin": {
"title": "Digital Output Number",
"type": "integer",
"description": "The digital output pin to drive the pump."
},
"pump_on_time": {
"title": "Pump On Time",
"type": "number",
"default": 5.2,
"description": "The time in seconds to run the pump."
}
},
"required": ["pump_pin"],
"additionalElements": true
}
Exporting Schema
Export your schema to the doover_config.json file:
from pathlib import Path
from pydoover import config
class MyAppConfig(config.Schema):
def __init__(self):
self.pump_pin = config.Integer("Digital Output Number")
if __name__ == "__main__":
schema = MyAppConfig()
schema.export(Path("doover_config.json"), "my_app_name")
Alternatively, use the Doover CLI:
doover config-schema export
Accessing Configuration Values
After deployment configuration is injected, access values through the element's value property:
class MyApp(Application):
config = MyAppConfig()
def setup(self):
pin = self.config.pump_pin.value # int
on_time = self.config.pump_on_time.value # float
engine = self.config.engine_type.value # str
Key Naming Rules
Configuration keys must only contain:
- Alphanumeric characters (a-z, A-Z, 0-9)
- Hyphens (
-) - Underscores (
_) - Spaces (
)
Keys that do not match this pattern will raise a ValueError.
Next Steps
- Schema Class Reference - Detailed Schema class documentation
- Configuration Elements - Available element types
- Advanced Patterns - Nested objects, arrays, and variables