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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35cfc9d92a5a5a852dde839578666dd668291ee21e380fe65d2ee8d87862cfe0 |
|
MD5 | e56a4577d7064c860f5a4824afd8073f |
|
BLAKE2b-256 | 713beea114f4efad24959146f6bdddf4afa198a32a70f72ad6941bb464fb45e9 |
Close
Hashes for pydantic_consul_settings-1.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 743b7bd02ea845c780b3f3f80f9584b48bbaff50c14cea72074d09739b90eee0 |
|
MD5 | a2ca4ac61cc618ba7e9c0539f7e509ee |
|
BLAKE2b-256 | 122d103423c7157ea874ae919fced0d65ea6fcea535066cb7bfd3f28e561eabf |