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.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6cad3cf6a817fe89960fea87efe7a6d6ad6a70a143b017b1be29261ec04de3e |
|
MD5 | 36e11a19e483b34d29dcfce2eb16f4d9 |
|
BLAKE2b-256 | 7a5ca6012fd92e3584cf53b9a5e383bbb94c732c102f6c7a37b0aec38de3d953 |
Close
Hashes for pydantic_consul_settings-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43daf00c8eb863b3b2b67d05222ab11cffa8b23b31480d8857afe82c81614c7e |
|
MD5 | bf887720f5dad6c28bd82fba9574d46c |
|
BLAKE2b-256 | 72e5c1a67dc19312b2f38467f3ca73297c0e899d9cb2c430458358445e78e74d |