# ConfigFramework 4.0
![PyPI version](https://img.shields.io/pypi/v/ConfigFramework)
![Python version](https://img.shields.io/pypi/pyversions/ConfigFramework)
![PyPi downloads/m](https://img.shields.io/pypi/dm/ConfigFramework)
![Issues](https://img.shields.io/github/issues/Rud356/ConfigFramework)
[![Python package](https://github.com/Rud356/ConfigFramework/actions/workflows/python-tests.yml/badge.svg)](https://github.com/Rud356/ConfigFramework/actions/workflows/python-tests.yml)
A small and simple framework to build your configs.
This project been created mostly because of me myself needing some simplistic
and at the same time powerful enough tool to create configs, validate them through have simple interface.
## Installing
Pypi link: https://pypi.org/project/ConfigFramework
Install with command:
`pip install ConfigFramework`
To install with mypy you must use command:
`pip install ConfigFramework[mypy]`
If you have python below 3.11 or need toml format with ability to write it back:
`pip install ConfigFramework[toml]`
To install with mypy and dev dependencies building requirements you must use command:
`pip install ConfigFramework[mypy,dev]`
## Documentation
[ConfigFrameworks stable branch documentation](https://configframework.readthedocs.io)
### How to build docs for local usage
1. Install dev-requirements.txt via `pip install -r dev-requirements.txt`
2. Change a current directory to docs/
3. Execute `make html`
4. Open build/html folder and then open index.html in your browser
## Example of usage
Here's basic example:
```python3
from config_framework import BaseConfig, VariableKey, Variable
from config_framework.loaders import Dict
loader = Dict.load(
data=dict(
user_id=1,
nested_val=dict(pi=3.14)
)
)
class ConfigSample(BaseConfig):
user_id: Variable[int] = Variable(VariableKey("user_id"))
pi_value = Variable(VariableKey("nested_val") / "pi")
# Defaults only applied when key isn't found.
# Also default values will be validated after initializing, and after you register new validator.
some_value = Variable("not_found_value", default="Hello world")
@staticmethod
@user_id.register_validator
def validate_user_id(var, value):
# Functions can return bool values or raise
# config_framework.types.custom_exceptions.InvalidValueError
# for more detailed description.
return value == 1
def __post_init__(self) -> None:
print("Post init here!")
print("Values aren't locked yet")
self.new_value = 122
config = ConfigSample(loader)
print("User id:", config.user_id)
print("Pi value:", config.pi_value)
print("Some value:", config.some_value)
print("Post inited value:", config.new_value)
# Configs by default aren't modifiable since frozen=True
# If you need changing variables for modifying config - you must
# create an instance of like this: ConfigSample(frozen=False)
# But right now it will raise NotImplementedError
config.some_value = "random"
```
See examples with explanation [here](https://github.com/Rud356/ConfigFramework/blob/master/examples/)
## Supported formats
Config formats:
- Yaml
- Toml (read only with default lib included with python 3.11, and read-write with toml external lib)
- Json (strings or files)
- Environment variables
- Pythons dictionaries
- Composite loading from multiple simple loaders
## Features
- Loading configs from multiple sources
- Creating custom loaders and variables types
- Flexible configs definition
- Config values validations
- Casting variables values to specific types using functions
- Casting to acceptable variable type before dumping variable to loader
- Variables serialization/deserialization depending on from which loader it was fetched
- Default values for per loader or per variable
- Translating one config loaders data to other (with or without including default values for each one)
- Composite loaders that allow you to define where to look up values using only one loader, that handles
combining others
- Simple access to variables values
- Single entry point for initialization of config with loader
## About 4.0
This version of ConfigFramework is not backwards compatible and requires a bit of work to make migration.
It was needed to get rid of annoying initialization with one config loader per variable listing, which
also made it really hard to replace config sources and made it more uncertain where is the source of data for variable.
### What is different?
- Configs must get only one loader as input when initializing them, and all variables don't have argument for specifying
loader.
- Added toml support for python above 3.11 and with external library that adds ability to read and write data.
- Changes in internals regarding variables initialization to support assigning data from provided loader dynamically on
initialization of whole config.
- Added pyproject.toml for more modern package management.
Raw data
{
"_id": null,
"home_page": "https://github.com/Rud356/ConfigFramework",
"name": "ConfigFramework",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "config, configuration, config managment, configuration managment",
"author": "Rud356",
"author_email": "Rud356 <rud356github@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/21/b0/d4236170df280d6278d6ddf3f48aa4212588089ebdd6d3f82afdebc86449/configframework-4.1.0.tar.gz",
"platform": null,
"description": "# ConfigFramework 4.0\n![PyPI version](https://img.shields.io/pypi/v/ConfigFramework)\n![Python version](https://img.shields.io/pypi/pyversions/ConfigFramework)\n![PyPi downloads/m](https://img.shields.io/pypi/dm/ConfigFramework)\n![Issues](https://img.shields.io/github/issues/Rud356/ConfigFramework)\n[![Python package](https://github.com/Rud356/ConfigFramework/actions/workflows/python-tests.yml/badge.svg)](https://github.com/Rud356/ConfigFramework/actions/workflows/python-tests.yml)\n\nA small and simple framework to build your configs. \n\nThis project been created mostly because of me myself needing some simplistic\nand at the same time powerful enough tool to create configs, validate them through have simple interface.\n\n## Installing\nPypi link: https://pypi.org/project/ConfigFramework\n\nInstall with command:\n`pip install ConfigFramework`\n\nTo install with mypy you must use command:\n`pip install ConfigFramework[mypy]`\n\nIf you have python below 3.11 or need toml format with ability to write it back:\n`pip install ConfigFramework[toml]`\n\nTo install with mypy and dev dependencies building requirements you must use command:\n`pip install ConfigFramework[mypy,dev]`\n\n## Documentation\n[ConfigFrameworks stable branch documentation](https://configframework.readthedocs.io)\n\n### How to build docs for local usage\n1. Install dev-requirements.txt via `pip install -r dev-requirements.txt`\n2. Change a current directory to docs/\n3. Execute `make html`\n4. Open build/html folder and then open index.html in your browser\n\n## Example of usage\n\nHere's basic example:\n```python3\nfrom config_framework import BaseConfig, VariableKey, Variable\nfrom config_framework.loaders import Dict\n\nloader = Dict.load(\n data=dict(\n user_id=1,\n nested_val=dict(pi=3.14)\n )\n)\n\n\nclass ConfigSample(BaseConfig):\n user_id: Variable[int] = Variable(VariableKey(\"user_id\"))\n pi_value = Variable(VariableKey(\"nested_val\") / \"pi\")\n # Defaults only applied when key isn't found.\n # Also default values will be validated after initializing, and after you register new validator.\n some_value = Variable(\"not_found_value\", default=\"Hello world\")\n\n @staticmethod\n @user_id.register_validator\n def validate_user_id(var, value):\n # Functions can return bool values or raise\n # config_framework.types.custom_exceptions.InvalidValueError\n # for more detailed description.\n return value == 1\n\n def __post_init__(self) -> None:\n print(\"Post init here!\")\n print(\"Values aren't locked yet\")\n\n self.new_value = 122\n\n\nconfig = ConfigSample(loader)\nprint(\"User id:\", config.user_id)\nprint(\"Pi value:\", config.pi_value)\nprint(\"Some value:\", config.some_value)\nprint(\"Post inited value:\", config.new_value)\n\n# Configs by default aren't modifiable since frozen=True\n# If you need changing variables for modifying config - you must\n# create an instance of like this: ConfigSample(frozen=False)\n# But right now it will raise NotImplementedError\nconfig.some_value = \"random\"\n```\n\nSee examples with explanation [here](https://github.com/Rud356/ConfigFramework/blob/master/examples/)\n\n## Supported formats\nConfig formats:\n- Yaml\n- Toml (read only with default lib included with python 3.11, and read-write with toml external lib)\n- Json (strings or files)\n- Environment variables\n- Pythons dictionaries\n- Composite loading from multiple simple loaders\n\n## Features\n- Loading configs from multiple sources\n- Creating custom loaders and variables types\n- Flexible configs definition\n- Config values validations\n- Casting variables values to specific types using functions\n- Casting to acceptable variable type before dumping variable to loader\n- Variables serialization/deserialization depending on from which loader it was fetched\n- Default values for per loader or per variable\n- Translating one config loaders data to other (with or without including default values for each one)\n- Composite loaders that allow you to define where to look up values using only one loader, that handles\n combining others\n- Simple access to variables values\n- Single entry point for initialization of config with loader\n\n## About 4.0\nThis version of ConfigFramework is not backwards compatible and requires a bit of work to make migration.\nIt was needed to get rid of annoying initialization with one config loader per variable listing, which\nalso made it really hard to replace config sources and made it more uncertain where is the source of data for variable.\n\n### What is different?\n- Configs must get only one loader as input when initializing them, and all variables don't have argument for specifying\nloader.\n- Added toml support for python above 3.11 and with external library that adds ability to read and write data.\n- Changes in internals regarding variables initialization to support assigning data from provided loader dynamically on\ninitialization of whole config.\n- Added pyproject.toml for more modern package management.\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "A small framework to build your flexible project configurations",
"version": "4.1.0",
"project_urls": {
"Homepage": "https://github.com/Rud356/ConfigFramework"
},
"split_keywords": [
"config",
" configuration",
" config managment",
" configuration managment"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "15240555929f1c50e938b06225e5bf80f40f6939ba289626c901bb29921b799a",
"md5": "ed152281c2472e02db3e1edd13166cc4",
"sha256": "e7d1b8c762afd27a87fe5c28f8f4638cd7eca6cda41280a9fee934afe03edafb"
},
"downloads": -1,
"filename": "ConfigFramework-4.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ed152281c2472e02db3e1edd13166cc4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 21561,
"upload_time": "2024-11-25T11:55:44",
"upload_time_iso_8601": "2024-11-25T11:55:44.423047Z",
"url": "https://files.pythonhosted.org/packages/15/24/0555929f1c50e938b06225e5bf80f40f6939ba289626c901bb29921b799a/ConfigFramework-4.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "21b0d4236170df280d6278d6ddf3f48aa4212588089ebdd6d3f82afdebc86449",
"md5": "be654c39e9d5d230d411ebd0742bc07f",
"sha256": "03d01d97350583d6c6b4847e34ef636ef191fad190762e4e6729668d4cf035c6"
},
"downloads": -1,
"filename": "configframework-4.1.0.tar.gz",
"has_sig": false,
"md5_digest": "be654c39e9d5d230d411ebd0742bc07f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 15943,
"upload_time": "2024-11-25T11:55:47",
"upload_time_iso_8601": "2024-11-25T11:55:47.465236Z",
"url": "https://files.pythonhosted.org/packages/21/b0/d4236170df280d6278d6ddf3f48aa4212588089ebdd6d3f82afdebc86449/configframework-4.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-25 11:55:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Rud356",
"github_project": "ConfigFramework",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "pyyaml",
"specs": [
[
">=",
"6.0.0"
]
]
}
],
"lcname": "configframework"
}