# confeasy
Application configuration inspired by Microsoft.Extensions.Configuration (.NET).
The main idea is to have the following workflow:
1) Define one or more configuration sources from where the actual configuration is created (or downloaded).
2) Build the configuration. This basically means put everything into a big flat dictionary
where lastly defined sources could override values from previous ones if they match on the configuration key.
3) Use resulting configuration:
a. Directly, picking up individual values by their key.
b. Bind all or portion of the configuration to a strongly typed class instance (typically a dataclass)
and use this instance instead of the configuration itself. The benefit is better intellisense in IDEs
and more decoupling.
## Getting started
Install the package.
```shell
poetry add confeasy
# or similar command for your package manager of choice
```
In python, usually around application start:
```python
# DbOptions class is an illustrative example of strongly typed configuration.
class DbOptions:
def __init__(self):
self.connnection_string: str = ""
self.max_connections: int = 100
from confeasy import Builder
from confeasy.jsonfile import JsonFile
from confeasy.tomlfile import TomlFile
from confeasy.envars import EnvironmentVariables
from confeasy.cmdline import CommandLine
# Order of the configuration sources matters; later sources can overwrite values from earlier ones.
builder = (Builder()
.add_source(JsonFile()
.required("settings.json")
.optional("setting.local.json"))
.add_source(TomlFile()
.optional("other_settings.toml"))
.add_source(EnvironmentVariables("MYAPP_"))
.add_source(CommandLine()))
config = builder.build()
# Bind configuration to a class instance and pass the instance to other objects.
options = config.bind(DbOptions(), prefix="db")
# OR pick up individual values:
db_conn_str = config.get_value("db.connection_string")
```
## Out-of-the-box configuration sources
* JSON files
* TOML files
* INI files
* command line arguments
* environment variables
## Additional configuration sources
* **confeasy.azure_appc** - using [Azure AppConfiguration][azure] service; [PyPI][appc_pypi] | [source][appc_gh]
## Development
For developer related information, check [Developer Guide](developer.md).
**Note:**
* YAML files will not be supported unless a parsing module is available in the standard library.
[azure]: https://learn.microsoft.com/en-us/azure/azure-app-configuration/overview
[appc_gh]: https://github.com/jdvor/confeasy-azure-appc
[appc_pypi]: https://pypi.org/project/confeasy.azure_appc
Raw data
{
"_id": null,
"home_page": "https://github.com/jdvor/confeasy",
"name": "confeasy",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.12",
"maintainer_email": null,
"keywords": "configuration, json, environment variables, command line",
"author": "jan Dvorak",
"author_email": "jandvorak.public@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/1d/84/e7d9afb6c6a5cf555551dad5553fc30140ea33e95a4602970cad38de790c/confeasy-1.0.0.tar.gz",
"platform": null,
"description": "# confeasy\n\nApplication configuration inspired by Microsoft.Extensions.Configuration (.NET).\n\nThe main idea is to have the following workflow:\n1) Define one or more configuration sources from where the actual configuration is created (or downloaded).\n2) Build the configuration. This basically means put everything into a big flat dictionary\n where lastly defined sources could override values from previous ones if they match on the configuration key.\n3) Use resulting configuration:\n a. Directly, picking up individual values by their key.\n b. Bind all or portion of the configuration to a strongly typed class instance (typically a dataclass)\n and use this instance instead of the configuration itself. The benefit is better intellisense in IDEs\n and more decoupling.\n\n## Getting started\n\nInstall the package.\n\n```shell\npoetry add confeasy\n# or similar command for your package manager of choice\n```\n\nIn python, usually around application start:\n```python\n\n# DbOptions class is an illustrative example of strongly typed configuration.\nclass DbOptions:\n def __init__(self):\n self.connnection_string: str = \"\"\n self.max_connections: int = 100\n\nfrom confeasy import Builder\nfrom confeasy.jsonfile import JsonFile\nfrom confeasy.tomlfile import TomlFile\nfrom confeasy.envars import EnvironmentVariables\nfrom confeasy.cmdline import CommandLine\n\n# Order of the configuration sources matters; later sources can overwrite values from earlier ones.\nbuilder = (Builder()\n .add_source(JsonFile()\n .required(\"settings.json\")\n .optional(\"setting.local.json\"))\n .add_source(TomlFile()\n .optional(\"other_settings.toml\"))\n .add_source(EnvironmentVariables(\"MYAPP_\"))\n .add_source(CommandLine()))\n\nconfig = builder.build()\n\n# Bind configuration to a class instance and pass the instance to other objects.\noptions = config.bind(DbOptions(), prefix=\"db\")\n\n# OR pick up individual values:\ndb_conn_str = config.get_value(\"db.connection_string\")\n```\n\n## Out-of-the-box configuration sources\n\n* JSON files\n* TOML files\n* INI files\n* command line arguments\n* environment variables\n\n## Additional configuration sources\n\n* **confeasy.azure_appc** - using [Azure AppConfiguration][azure] service; [PyPI][appc_pypi] | [source][appc_gh]\n\n## Development\n\nFor developer related information, check [Developer Guide](developer.md).\n\n**Note:**\n* YAML files will not be supported unless a parsing module is available in the standard library.\n\n\n[azure]: https://learn.microsoft.com/en-us/azure/azure-app-configuration/overview\n[appc_gh]: https://github.com/jdvor/confeasy-azure-appc\n[appc_pypi]: https://pypi.org/project/confeasy.azure_appc",
"bugtrack_url": null,
"license": "MIT",
"summary": "Application configuration inspired by Microsoft.Extensions.Configuration (.NET).",
"version": "1.0.0",
"project_urls": {
"Bug Tracker": "https://github.com/jdvor/confeasy/issues",
"Homepage": "https://github.com/jdvor/confeasy",
"Repository": "https://github.com/jdvor/confeasy"
},
"split_keywords": [
"configuration",
" json",
" environment variables",
" command line"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f4fbaf4137f9f1a781e9c35c88f70f7e1947524ba41a3324daebb518ae148a09",
"md5": "c673793dab891a780532d8870b140b81",
"sha256": "f53faa543cc2be18f9aa67d006a994b28c2b87079928d8da4726d453b76d1bd3"
},
"downloads": -1,
"filename": "confeasy-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c673793dab891a780532d8870b140b81",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.12",
"size": 9859,
"upload_time": "2024-11-04T10:29:14",
"upload_time_iso_8601": "2024-11-04T10:29:14.728624Z",
"url": "https://files.pythonhosted.org/packages/f4/fb/af4137f9f1a781e9c35c88f70f7e1947524ba41a3324daebb518ae148a09/confeasy-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1d84e7d9afb6c6a5cf555551dad5553fc30140ea33e95a4602970cad38de790c",
"md5": "84405df0460f3f3d0bbfd8d485f84af2",
"sha256": "01b4f0c3d8beca6ef9b282276feccd848eb3cf881488b195d7a898910d32d8cf"
},
"downloads": -1,
"filename": "confeasy-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "84405df0460f3f3d0bbfd8d485f84af2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.12",
"size": 9077,
"upload_time": "2024-11-04T10:29:16",
"upload_time_iso_8601": "2024-11-04T10:29:16.306755Z",
"url": "https://files.pythonhosted.org/packages/1d/84/e7d9afb6c6a5cf555551dad5553fc30140ea33e95a4602970cad38de790c/confeasy-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-04 10:29:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jdvor",
"github_project": "confeasy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "confeasy"
}