# Pydantic Consul settings
[](https://pypi.org/project/pydantic-consul-settings/)
[](https://github.com/jag-k/pydantic-consul-settings/actions/workflows/build.yml)
**Add Consul as source of env variable to settings**
This package provides a way to use [pydantic](https://docs.pydantic.dev/) settings with [consul](https://consul.io) as source of environment variables.
## Installation
```shell
pip install pydantic-consul-settings
```
## Usage
```python
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())
```
Raw data
{
"_id": null,
"home_page": "https://github.com/jag-k/pydantic-consul-settings#readme",
"name": "pydantic-consul-settings",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.11,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Jag_k",
"author_email": "jag-k@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/8a/60/556dec47e005e42fa84e07675a0721b320496395bfaf522578133b99a7e9/pydantic_consul_settings-1.1.0.tar.gz",
"platform": null,
"description": "# Pydantic Consul settings\n\n[](https://pypi.org/project/pydantic-consul-settings/)\n[](https://github.com/jag-k/pydantic-consul-settings/actions/workflows/build.yml)\n\n**Add Consul as source of env variable to settings**\n\nThis package provides a way to use [pydantic](https://docs.pydantic.dev/) settings with [consul](https://consul.io) as source of environment variables.\n\n\n## Installation\n\n```shell\npip install pydantic-consul-settings\n```\n\n## Usage\n\n```python\nfrom pydantic_settings import SettingsConfigDict\nfrom pydantic_consul_settings import create_settings, ConsulBaseSettings\n\n\nclass ConsulSettings(ConsulBaseSettings):\n \"\"\"Add additional settings for key generation\"\"\"\n\n stage: str = 'dev'\n service: str = 'my-service'\n\n\n @property\n def key_prefix(self) -> str:\n \"\"\"Get the key prefix.\"\"\"\n return f\"{self.stage}/{self.service}\"\n\n\nBaseSettings = create_settings(ConsulSettings())\n\n\nclass Settings(BaseSettings):\n \"\"\"App settings\"\"\"\n\n model_config = SettingsConfigDict(\n env_prefix='APP_',\n )\n\n # Get from env APP_NAME\n # and `dev/my-service/APP_NAME` from consul\n name: str = 'my-app'\n # Get from env APP_VERSION\n # and `dev/my-service/APP_VERSION` from consul\n version: str = '0.1.0'\n # Get from env APP_DESCRIPTION\n # and `dev/my-service/APP_DESCRIPTION` from consul\n description: str = 'My app description'\n\n\nsettings = Settings()\n\nprint(settings.dict())\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Add Consul as source of env variable to settings",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/jag-k/pydantic-consul-settings#readme",
"Repository": "https://github.com/jag-k/pydantic-consul-settings"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e8a6fd32bee2fa0f3f78a6b49f4ce3665635ce33386c9b52d1903c00a27a8504",
"md5": "032d0aa3f8e0d86d8932c60890c66215",
"sha256": "43611cdc1f874b67d547d5e4b2a2e6f06e5b838038d1a3e1926f4c8885b06c15"
},
"downloads": -1,
"filename": "pydantic_consul_settings-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "032d0aa3f8e0d86d8932c60890c66215",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11,<4.0",
"size": 5273,
"upload_time": "2024-02-28T19:27:24",
"upload_time_iso_8601": "2024-02-28T19:27:24.351666Z",
"url": "https://files.pythonhosted.org/packages/e8/a6/fd32bee2fa0f3f78a6b49f4ce3665635ce33386c9b52d1903c00a27a8504/pydantic_consul_settings-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8a60556dec47e005e42fa84e07675a0721b320496395bfaf522578133b99a7e9",
"md5": "abcc0ec2975b700202392651353c0e96",
"sha256": "e3154f4917b21a6750960f21fffcfd57d344b209e52a29b822ebc4700fec9c29"
},
"downloads": -1,
"filename": "pydantic_consul_settings-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "abcc0ec2975b700202392651353c0e96",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11,<4.0",
"size": 5110,
"upload_time": "2024-02-28T19:27:25",
"upload_time_iso_8601": "2024-02-28T19:27:25.220301Z",
"url": "https://files.pythonhosted.org/packages/8a/60/556dec47e005e42fa84e07675a0721b320496395bfaf522578133b99a7e9/pydantic_consul_settings-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-28 19:27:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jag-k",
"github_project": "pydantic-consul-settings#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pydantic-consul-settings"
}