Skip to main content

Add Consul as source of env variable to settings

Project description

Pydantic Consul settings

PyPI version PyPI publish

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

pydantic_consul_settings-1.0.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_consul_settings-1.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

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

Hashes for pydantic_consul_settings-1.0.2.tar.gz
Algorithm Hash digest
SHA256 866f0b87fda7d960230a41f6c7bd209424cdb81b1f5e5de810c9329b43efd97e
MD5 c3dac6fd2f40cd437bfae44962841ca9
BLAKE2b-256 5dc761d2701ee018c6ae81e17186a477027afa0e27c5d46da60eb73231058836

See more details on using hashes here.

File details

Details for the file pydantic_consul_settings-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_consul_settings-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d66007254a3cb3f0bac5acc3d4346b585d93b8f84e02bc7fb26ac00a73495bd4
MD5 903f09364d978d7fdae9fef3d3bed35d
BLAKE2b-256 b0ff7f46633e02bf08809fe4feafd75f3d182c75ce719e419f14e110650e7c8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page