Skip to main content

Add Consul as source of env variable to settings

Project description

Pydantic Consul settings

PyPI version

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

pydantic_consul_settings-1.1.1.tar.gz (5.2 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.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_consul_settings-1.1.1.tar.gz.

File metadata

  • Download URL: pydantic_consul_settings-1.1.1.tar.gz
  • Upload date:
  • Size: 5.2 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.1.1.tar.gz
Algorithm Hash digest
SHA256 05c1aa0a22011a8392f3f108c00cc753870d24d88b5519498a4cf7dc62de1cf9
MD5 9fd5b1029027bf4dc1d151bcbd8add18
BLAKE2b-256 50c66981da18a782966cd75de69778f6e52af68e894768b896d87427f234a5ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pydantic_consul_settings-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 79b79f1a58fbfb6e9ed6abedd1118154a7140ef0a38287ed1df791dcf00c12e7
MD5 b584672154213d47fcadbe603e8d8516
BLAKE2b-256 08e2852d82fab5acc25445fb4b1153ddb6523b912a0d2ff48d06dc30ee59ceea

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