App Configuration
ArconQ allows you to override the configuration of applications running on its platform. Configuration values provided in ArconQ are automatically converted into environment variables, which your Python application can access.
To handle these environment variables effectively, we recommend using the Pydantic library. Pydantic simplifies configuration management by enabling you to define structured and type-safe configuration models. It also provides built-in support for reading environment variables, making it an excellent choice for managing configuration in applications running on ArconQ.
Additionally, the ArconQ Python SDK leverages Pydantic, ensuring seamless integration and consistency with the recommended approach.
Config example
- JSON
- EnvironmentVariables
An example config in json form.
{
"SenderConfig": {
"ScheduledJobIntervalInSeconds": 1,
"AmountOfMessagesToSendAtOnce": 1,
"SendBiggerMessages": false,
"MessageSizeInMB": 1,
"PersistMessages": false
},
"TestConfig": {
"AreMetricsEnabled": true,
"IsLoggingEnabled": true
}
}
The config mapped to environment variables looks like this.
It can also be passed to the .env file stored in the projects directory and be used to override the app config locally.
SenderConfig__ScheduledJobIntervalInSeconds=1
SenderConfig__AmountOfMessagesToSendAtOnce=1
SenderConfig__SendBiggerMessages=false
SenderConfig__MessageSizeInMB=1
SenderConfig__PersistMessages=false
TestConfig__AreMetricsEnabled=true
TestConfig__IsLoggingEnabled=true
Mapping the config to classes using Pydantic
AppConfig class which aggregates the 2 config sections
from pydantic import Field
from pydantic.alias_generators import to_pascal
from pydantic_settings import BaseSettings, SettingsConfigDict
from configuration.sender_config import SenderConfig
from configuration.test_config import TestConfig
class AppConfig(BaseSettings):
model_config = SettingsConfigDict(
env_nested_delimiter="__",
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=False,
alias_generator=to_pascal,
)
senderConfig: SenderConfig = Field(default=SenderConfig())
testConfig: TestConfig = Field(default=TestConfig())
SenderConfig class
from pydantic import BaseModel, Field
class SenderConfig(BaseModel):
scheduledJobIntervalInSeconds: int = Field(default=1)
amountOfMessagesToSendAtOnce: int = Field(default=1)
sendBiggerMessages: bool = Field(default=False)
messageSizeInMB: float = Field(default=1.0)
persistMessages: bool = Field(default=False)
TestConfig class
from pydantic import BaseModel, Field
class TestConfig(BaseModel):
areMetricsEnabled: bool = Field(default=True)
isLoggingEnabled: bool = Field(default=True)