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())
Metadata
Release files for pydantic-consul-settings 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pydantic_consul_settings-1.1.1.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_consul_settings-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.6 kB
Release files / pydantic_consul_settings-1.1.1.tar.gz
| Download URL | pydantic_consul_settings-1.1.1.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05c1aa0a22011a8392f3f108c00cc753870d24d88b5519498a4cf7dc62de1cf9
|
|
BLAKE2b-256 checksum How to use checksums |
50c66981da18a782966cd75de69778f6e52af68e894768b896d87427f234a5ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.1 CPython/3.10.12 Linux/6.5.0-1015-azure
|
Release files / pydantic_consul_settings-1.1.1-py3-none-any.whl
| Download URL | pydantic_consul_settings-1.1.1-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
79b79f1a58fbfb6e9ed6abedd1118154a7140ef0a38287ed1df791dcf00c12e7
|
|
BLAKE2b-256 checksum How to use checksums |
08e2852d82fab5acc25445fb4b1153ddb6523b912a0d2ff48d06dc30ee59ceea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.1 CPython/3.10.12 Linux/6.5.0-1015-azure
|