Name | pydantic-config JSON |
Version |
0.2.3
JSON |
| download |
home_page | |
Summary | Support for Pydantic settings configuration file loading |
upload_time | 2023-07-21 18:46:50 |
maintainer | |
docs_url | None |
author | Jordan Shaw |
requires_python | >=3.7 |
license | |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Pydantic Config
Support for Pydantic settings configuration file loading
## Installation
`pip install pydantic-config`
### Optional Dependencies
Pydantic-Config has the following optional dependencies:
- yaml - `pip install pydantic-config[yaml]`
- toml - `pip install pydantic-config[toml]`
You can install all the optional dependencies with `pip install pydantic-config[all]`
## Usage
```toml
# config.toml
app_name = "Python Application"
description = "Test application description"
```
```python
from pydantic_config import SettingsModel, SettingsConfig
class Settings(SettingsModel):
app_id: str = 1
app_name: str = None
description: str = None
log_level: str = 'INFO'
model_config = SettingsConfig(
config_file='config.toml',
)
settings = Settings()
print(settings)
# app_id='1' app_name='Python Application' description='Test application description' log_level='INFO'
```
## Using multiple config files
Multiple config files can be loaded by passing a `list` of file names. Files will be loaded in the order they are listed.
Meaning later files in the `list` will take priority over earlier files.
```toml
# config.toml
app_name = "Python Application"
description = "Test application description"
```
```json
// config.json
{
"description": "Description from JSON file",
"log_level": "WARNING"
}
```
```python
from pydantic_config import SettingsModel, SettingsConfig
class Settings(SettingsModel):
app_id: str = 1
app_name: str = 'App Name'
description: str = None
log_level: str = 'INFO'
model_config = SettingsConfig(
config_file=['config.toml', 'config.json'] # The config.json file will take priority over config.toml
)
settings = Settings()
print(settings)
# app_id='1' app_name='Python Application' description='Description from JSON file' log_level='WARNING'
```
## Supported file formats
Currently, the following file formats are supported:
- `.yaml` _Requires `pyyaml` package_
- `.toml` _Requires `toml` package_
- `.json`
- `.ini`
## Merging
If your configurations have existing `list` or `dict` variables the contents will be merged by default. To disable
this behavior and override the contents instead you can set the `config_merge` option to `False` in the settings
`Config` class.
```toml
# config.toml
[foo]
item1 = "value1"
```
```toml
# config2.toml
[foo]
item2 = "value2"
```
```python
from pydantic_config import SettingsModel, SettingsConfig
class Settings(SettingsModel):
foo: dict = {}
model_config = SettingsConfig(
config_file=['config.toml', 'config2.toml'],
config_merge= True,
)
settings = Settings()
print(settings)
# foo={'item1': 'value1', 'item2': 'value2'}
# If config_merge=False then config2.toml would ovverride the values from config.toml
# foo={'item2': 'value2'}
```
## Duplicate items in merged lists
By default, only unique `list` items will be merged. To disable this behavior and keep all items
of a `list` regardless of duplication set the `config_merge_unique` option to `False`.
Raw data
{
"_id": null,
"home_page": "",
"name": "pydantic-config",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Jordan Shaw",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/06/4e/9d0de702a6cbdd4e6becd0c5fdbe29ad2cdc543fa88d8c09b5fbc4e939d0/pydantic-config-0.2.3.tar.gz",
"platform": null,
"description": "# Pydantic Config\nSupport for Pydantic settings configuration file loading\n\n## Installation\n`pip install pydantic-config`\n\n### Optional Dependencies\n\nPydantic-Config has the following optional dependencies:\n - yaml - `pip install pydantic-config[yaml]`\n - toml - `pip install pydantic-config[toml]`\n\nYou can install all the optional dependencies with `pip install pydantic-config[all]`\n\n## Usage\n\n```toml\n# config.toml\napp_name = \"Python Application\"\ndescription = \"Test application description\"\n```\n\n```python\nfrom pydantic_config import SettingsModel, SettingsConfig\n\n\nclass Settings(SettingsModel):\n app_id: str = 1\n app_name: str = None\n description: str = None\n log_level: str = 'INFO'\n \n model_config = SettingsConfig(\n config_file='config.toml',\n )\n\n\nsettings = Settings()\nprint(settings)\n# app_id='1' app_name='Python Application' description='Test application description' log_level='INFO'\n\n```\n\n## Using multiple config files\nMultiple config files can be loaded by passing a `list` of file names. Files will be loaded in the order they are listed.\nMeaning later files in the `list` will take priority over earlier files.\n\n\n```toml\n# config.toml\napp_name = \"Python Application\"\ndescription = \"Test application description\"\n```\n\n\n```json\n// config.json\n{\n \"description\": \"Description from JSON file\",\n \"log_level\": \"WARNING\"\n}\n```\n\n```python\nfrom pydantic_config import SettingsModel, SettingsConfig\n\n\nclass Settings(SettingsModel):\n app_id: str = 1\n app_name: str = 'App Name'\n description: str = None\n log_level: str = 'INFO'\n \n model_config = SettingsConfig(\n config_file=['config.toml', 'config.json'] # The config.json file will take priority over config.toml\n )\n\nsettings = Settings()\nprint(settings)\n# app_id='1' app_name='Python Application' description='Description from JSON file' log_level='WARNING'\n```\n\n## Supported file formats\nCurrently, the following file formats are supported:\n - `.yaml` _Requires `pyyaml` package_\n - `.toml` _Requires `toml` package_\n - `.json`\n - `.ini`\n\n\n## Merging\nIf your configurations have existing `list` or `dict` variables the contents will be merged by default. To disable\nthis behavior and override the contents instead you can set the `config_merge` option to `False` in the settings \n`Config` class.\n\n\n\n```toml\n# config.toml\n[foo]\nitem1 = \"value1\"\n```\n```toml\n# config2.toml\n[foo]\nitem2 = \"value2\"\n```\n\n```python\nfrom pydantic_config import SettingsModel, SettingsConfig\n\n\nclass Settings(SettingsModel):\n foo: dict = {}\n \n model_config = SettingsConfig(\n config_file=['config.toml', 'config2.toml'],\n config_merge= True,\n )\n\n\nsettings = Settings()\nprint(settings)\n# foo={'item1': 'value1', 'item2': 'value2'}\n\n# If config_merge=False then config2.toml would ovverride the values from config.toml\n# foo={'item2': 'value2'}\n```\n\n## Duplicate items in merged lists\nBy default, only unique `list` items will be merged. To disable this behavior and keep all items\nof a `list` regardless of duplication set the `config_merge_unique` option to `False`. \n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Support for Pydantic settings configuration file loading",
"version": "0.2.3",
"project_urls": {
"Homepage": "https://github.com/jordantshaw/pydantic-config"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f181318dc55bc1691063b28215055efa9e207383c3ba19df914f40b05f051ae6",
"md5": "0c5b7b8a481df1531dd92d2300d7d00d",
"sha256": "6baf7745d9aab9fefdd991760acf8b5f4abc0da0a726a3026155b928eb184dbb"
},
"downloads": -1,
"filename": "pydantic_config-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0c5b7b8a481df1531dd92d2300d7d00d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 6183,
"upload_time": "2023-07-21T18:46:48",
"upload_time_iso_8601": "2023-07-21T18:46:48.711963Z",
"url": "https://files.pythonhosted.org/packages/f1/81/318dc55bc1691063b28215055efa9e207383c3ba19df914f40b05f051ae6/pydantic_config-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "064e9d0de702a6cbdd4e6becd0c5fdbe29ad2cdc543fa88d8c09b5fbc4e939d0",
"md5": "f57fa94e6b84d3174460b1bf294cbb29",
"sha256": "417357b651aa6b33a59708b9daa75089aff1af765b231a164ac0791805f10507"
},
"downloads": -1,
"filename": "pydantic-config-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "f57fa94e6b84d3174460b1bf294cbb29",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 6908,
"upload_time": "2023-07-21T18:46:50",
"upload_time_iso_8601": "2023-07-21T18:46:50.127211Z",
"url": "https://files.pythonhosted.org/packages/06/4e/9d0de702a6cbdd4e6becd0c5fdbe29ad2cdc543fa88d8c09b5fbc4e939d0/pydantic-config-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-21 18:46:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jordantshaw",
"github_project": "pydantic-config",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pydantic-config"
}