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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_consul_settings-1.0.2.tar.gz.
File metadata
- Download URL: pydantic_consul_settings-1.0.2.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.1 CPython/3.10.12 Linux/6.5.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
866f0b87fda7d960230a41f6c7bd209424cdb81b1f5e5de810c9329b43efd97e
|
|
| MD5 |
c3dac6fd2f40cd437bfae44962841ca9
|
|
| BLAKE2b-256 |
5dc761d2701ee018c6ae81e17186a477027afa0e27c5d46da60eb73231058836
|
File details
Details for the file pydantic_consul_settings-1.0.2-py3-none-any.whl.
File metadata
- Download URL: pydantic_consul_settings-1.0.2-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.1 CPython/3.10.12 Linux/6.5.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d66007254a3cb3f0bac5acc3d4346b585d93b8f84e02bc7fb26ac00a73495bd4
|
|
| MD5 |
903f09364d978d7fdae9fef3d3bed35d
|
|
| BLAKE2b-256 |
b0ff7f46633e02bf08809fe4feafd75f3d182c75ce719e419f14e110650e7c8e
|