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.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3154f4917b21a6750960f21fffcfd57d344b209e52a29b822ebc4700fec9c29 |
|
MD5 | abcc0ec2975b700202392651353c0e96 |
|
BLAKE2b-256 | 8a60556dec47e005e42fa84e07675a0721b320496395bfaf522578133b99a7e9 |
Close
Hashes for pydantic_consul_settings-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43611cdc1f874b67d547d5e4b2a2e6f06e5b838038d1a3e1926f4c8885b06c15 |
|
MD5 | 032d0aa3f8e0d86d8932c60890c66215 |
|
BLAKE2b-256 | e8a6fd32bee2fa0f3f78a6b49f4ce3665635ce33386c9b52d1903c00a27a8504 |