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_consul_settings import BaseSettingsWithConsul, ConsulClientSettings, SettingsConfigDict
class ConsulSettings(ConsulClientSettings):
"""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}"
class BaseSettings(BaseSettingsWithConsul):
model_config = SettingsConfigDict(
env_prefix='APP_',
consul_model=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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05c1aa0a22011a8392f3f108c00cc753870d24d88b5519498a4cf7dc62de1cf9 |
|
MD5 | 9fd5b1029027bf4dc1d151bcbd8add18 |
|
BLAKE2b-256 | 50c66981da18a782966cd75de69778f6e52af68e894768b896d87427f234a5ec |
Close
Hashes for pydantic_consul_settings-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79b79f1a58fbfb6e9ed6abedd1118154a7140ef0a38287ed1df791dcf00c12e7 |
|
MD5 | b584672154213d47fcadbe603e8d8516 |
|
BLAKE2b-256 | 08e2852d82fab5acc25445fb4b1153ddb6523b912a0d2ff48d06dc30ee59ceea |