-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmodels.py
More file actions
49 lines (35 loc) · 1.36 KB
/
models.py
File metadata and controls
49 lines (35 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Pydantic models are declared here, and then imported wherever needed
"""
from datetime import timedelta
from typing import Literal
from pydantic import BaseModel
from pydantic_settings import BaseSettings, SettingsConfigDict
class ServiceConfig(BaseSettings):
"""
Global service configuration.
Pydantic Settings (https://docs.pydantic.dev/latest/concepts/pydantic_settings/)
provides the `BaseSettings` model that loads values from environment variables.
To access the loaded model, we use `utils.get_config()`.
"""
model_config = SettingsConfigDict(
# `name` is now loaded from the environment variable `your_package_name`
env_prefix='your_package_',
# You can use either `your_package_name=name` or `YOUR_PACKAGE_NAME=name`
case_sensitive=False,
# Ignores all unknown environment variables that happen to have the same prefix
json_schema_extra='ignore',
)
name: str = 'your_package'
debug: bool = False
mqtt_protocol: Literal['mqtt', 'mqtts'] = 'mqtt'
mqtt_host: str = 'eventbus'
mqtt_port: int = 1883
history_topic: str = 'brewcast/history'
publish_interval: timedelta = timedelta(seconds=5)
class ExampleMessage(BaseModel):
"""
The data model for the example HTTP endpoint.
For more options, see https://docs.pydantic.dev/latest/
"""
content: str