Skip to content

settings

utils.settings.UrlValidate

Bases: BaseModel

Source code in utils/settings.py
30
31
class UrlValidate(BaseModel):
	url: PostgresDsn

utils.settings.Settings

Bases: BaseSettings

Source code in utils/settings.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Settings(BaseSettings):
	model_config = SettingsConfigDict(
		env_file='.env', env_file_encoding='utf-8', frozen=True
	)
	DEV: bool

	DATABASE_USER: str
	DATABASE_PASSWORD: str
	DATABASE_HOST: str
	DATABASE_PORT: PositiveInt = 5432
	DATABASE_NAME: str

	CEP_ABERTO_TOKEN: str | None = None

	@computed_field  # type: ignore[prop-decorator]
	@property
	def DATABASE_URL(self) -> str:
		"""Generate and validate database url based on other fields."""
		url = (
			'postgresql+psycopg://'
			f'{self.DATABASE_USER}:{quote_plus(self.DATABASE_PASSWORD)}@'
			f'{self.DATABASE_HOST}:{self.DATABASE_PORT}/{self.DATABASE_NAME}'
		)

		return str(UrlValidate(url=url).url)

DATABASE_URL: str property

Generate and validate database url based on other fields.

utils.settings.settings = Settings() module-attribute