Add Consul as source of env variable to settings
Project description
Pydantic Consul settings
Add Consul as source of env variable to settings
This package provides a way to use pydantic settings with consul as source of environment variables.
Installation
pip install pydantic-consul-settings
Usage
from pydantic_settings import SettingsConfigDict
from pydantic_consul_settings import create_settings, ConsulBaseSettings
class ConsulSettings(ConsulBaseSettings):
"""Add additional settings for key generation"""
stage: str = 'dev'
service: str = 'my-service'
@property
def key_prefix(self) -> str:
"""Get the key prefix."""
return f"{self.stage}/{self.service}"
BaseSettings = create_settings(ConsulSettings())
class Settings(BaseSettings):
"""App settings"""
model_config = SettingsConfigDict(
env_prefix='APP_',
)
# Get from env APP_NAME
# and `dev/my-service/APP_NAME` from consul
name: str = 'my-app'
# Get from env APP_VERSION
# and `dev/my-service/APP_VERSION` from consul
version: str = '0.1.0'
# Get from env APP_DESCRIPTION
# and `dev/my-service/APP_DESCRIPTION` from consul
description: str = 'My app description'
settings = Settings()
print(settings.dict())
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for pydantic_consul_settings-1.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbe3fe8d02201f514ad7dc66c039cf969888fdc49435abf4703c6260b9b3aaaf |
|
MD5 | bab0b9746d8c46db05e42217c0bdeddf |
|
BLAKE2b-256 | 4956a83d667ee8b1e7776164553a764a0d37d1f301345147e45417d646c87749 |
Close
Hashes for pydantic_consul_settings-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7af00d9c9cb5542fae27e2500eb66b2190b674de94657a3c3406ecf5043c1a0f |
|
MD5 | c561856b4fd7d7f788ee18b6aa39a61e |
|
BLAKE2b-256 | 6c3f710031eb648287a69925d657edbc8a01865bced75a96f548aebbbc81b707 |