Name | byoconfig JSON |
Version |
0.0.6
JSON |
| download |
home_page | None |
Summary | A configuration class that supports plugins, multiple file formats, heirarchical configuration, and more. |
upload_time | 2025-03-18 20:41:21 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | None |
keywords |
heirachaical
config
yaml
toml
json
plugins
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# BYOConfig
> Bring your own configuration
[](https://github.com/camratchford/byoconfig/actions/workflows/lint_and_test.yml)
[](https://github.com/camratchford/byoconfig/actions/workflows/publish.yml)
[](https://pypi.org/project/byoconfig/)
## Features
- Loading/Dumping configuration data from/to:
- YAML
- TOML
- JSON
- File format auto-detect and override options
- Ability to load configuration data from environment variables
- Allows hierarchical data to be loaded, then updated according to precedence rules.
- Extensible via plugins, allowing your own arbitrary data sources to be merged with config file and environment data.
- Configuration data available as class attributes (ex. `config.variable_1`)
## Installing
```bash
pip install byconfig
```
## Usage
### From file
```python
from pathlib import Path
from byoconfig import Config
"""
# imagining the contents of config.yaml are:
important_path: path/that/must/exists
"""
# Auto-detects the file type based on file extension suffix
conf = Config('path/to/config.yaml')
# Alternatively, specify a forced_file_type argument (One of 'YAML', 'TOML', or 'JSON'
# conf = Config("path/to/config", forced_file_extension="YAML")
def ensure_file(path: str):
Path(path).mkdir(parents=True)
if __name__ == "__main__":
# The configuration variable is accessible by the instance attribute conf.important_path
ensure_file(conf.important_path)
```
### From Environment Variables
```python
from byoconfig import Config
conf = Config(env_prefix="MY_APP")
# Imagining that you have an env var `MY_APP_var_1` set
print(conf.var_1)
# If you want to load all of the environment variables, use the '*' wildcard as env_prefix
conf2 = Config(env_prefix="*")
print(conf2.PATH)
```
### From Custom plugins
```python
from byoconfig.sources import BaseVariableSource
from byoconfig import Config
# Subclass the BaseVariableSource class
class MyVarSource(BaseVariableSource):
def __init__(self, init_options):
# Using an imaginary function 'get_external_data' in place of something like an http request or DB query
self.external_data = get_external_data(init_options)
# Initializes the class attrs, making the data availalble via MyVarSource.var_name
self.set_data(self.external_data)
# Start with a config object, containing the data from any source (optional)
my_config = Config("some/file/data.json")
# Include your plugin, merging the data from MyVarSource and the config object above
# You can pass kwargs to include as if you're passing them to MyVarSource's __init__ method.
my_config.include(MyVarSource, init_options="some data to initialize your custom data source")
```
### Loading Arbitrary Values
```python
from byoconfig import Config
# Via kwargs
conf = Config(my_var="abc", my_var_2=123)
# Via the set_data method / data property
conf.set_data({"my_var": "abc"})
# Equivalent to
conf.data = {"my_var": "abc"}
```
### Dumping Data
```python
from byoconfig import Config
conf = Config()
# We can pretend that you've loaded your configuration data in conf, and you'd like it output to a file
# to be used later
...
# Auto-detects the file-type based on file extension suffix
conf.dump("running_config.yml")
# Overriding the auto-detect in case you have no extension
conf.dump("running_config", forced_file_type="TOML")
```
Raw data
{
"_id": null,
"home_page": null,
"name": "byoconfig",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "heirachaical, config, yaml, toml, json, plugins",
"author": null,
"author_email": "Cam Ratchford <camratchford@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/c2/1c/b56ae6b87b55f814f36779552eaedf446979e50ab358557c956699903c53/byoconfig-0.0.6.tar.gz",
"platform": null,
"description": "# BYOConfig\n\n> Bring your own configuration\n\n[](https://github.com/camratchford/byoconfig/actions/workflows/lint_and_test.yml)\n[](https://github.com/camratchford/byoconfig/actions/workflows/publish.yml)\n[](https://pypi.org/project/byoconfig/)\n\n## Features\n\n- Loading/Dumping configuration data from/to:\n - YAML\n - TOML\n - JSON\n- File format auto-detect and override options\n- Ability to load configuration data from environment variables\n- Allows hierarchical data to be loaded, then updated according to precedence rules.\n- Extensible via plugins, allowing your own arbitrary data sources to be merged with config file and environment data.\n- Configuration data available as class attributes (ex. `config.variable_1`)\n\n## Installing\n\n```bash\npip install byconfig\n```\n\n## Usage\n\n\n### From file\n\n```python\nfrom pathlib import Path\n\nfrom byoconfig import Config\n\n\"\"\"\n# imagining the contents of config.yaml are:\nimportant_path: path/that/must/exists\n\"\"\"\n\n# Auto-detects the file type based on file extension suffix\nconf = Config('path/to/config.yaml')\n\n# Alternatively, specify a forced_file_type argument (One of 'YAML', 'TOML', or 'JSON'\n# conf = Config(\"path/to/config\", forced_file_extension=\"YAML\")\n\ndef ensure_file(path: str):\n Path(path).mkdir(parents=True)\n\nif __name__ == \"__main__\":\n # The configuration variable is accessible by the instance attribute conf.important_path\n ensure_file(conf.important_path)\n\n```\n\n### From Environment Variables\n\n```python\n\nfrom byoconfig import Config\n\nconf = Config(env_prefix=\"MY_APP\")\n\n# Imagining that you have an env var `MY_APP_var_1` set\nprint(conf.var_1)\n\n# If you want to load all of the environment variables, use the '*' wildcard as env_prefix\n\nconf2 = Config(env_prefix=\"*\")\n\nprint(conf2.PATH)\n\n```\n\n\n### From Custom plugins\n\n```python\n\nfrom byoconfig.sources import BaseVariableSource\nfrom byoconfig import Config\n\n# Subclass the BaseVariableSource class\nclass MyVarSource(BaseVariableSource):\n def __init__(self, init_options):\n # Using an imaginary function 'get_external_data' in place of something like an http request or DB query\n self.external_data = get_external_data(init_options)\n \n # Initializes the class attrs, making the data availalble via MyVarSource.var_name \n self.set_data(self.external_data)\n\n# Start with a config object, containing the data from any source (optional)\nmy_config = Config(\"some/file/data.json\")\n\n# Include your plugin, merging the data from MyVarSource and the config object above\n# You can pass kwargs to include as if you're passing them to MyVarSource's __init__ method.\nmy_config.include(MyVarSource, init_options=\"some data to initialize your custom data source\")\n\n```\n\n\n### Loading Arbitrary Values\n\n```python\nfrom byoconfig import Config\n# Via kwargs\nconf = Config(my_var=\"abc\", my_var_2=123)\n\n# Via the set_data method / data property\nconf.set_data({\"my_var\": \"abc\"})\n# Equivalent to\nconf.data = {\"my_var\": \"abc\"}\n\n```\n\n\n### Dumping Data\n\n```python\nfrom byoconfig import Config\n\nconf = Config()\n\n# We can pretend that you've loaded your configuration data in conf, and you'd like it output to a file\n# to be used later\n...\n\n# Auto-detects the file-type based on file extension suffix\nconf.dump(\"running_config.yml\")\n# Overriding the auto-detect in case you have no extension\nconf.dump(\"running_config\", forced_file_type=\"TOML\")\n\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "A configuration class that supports plugins, multiple file formats, heirarchical configuration, and more.",
"version": "0.0.6",
"project_urls": {
"Homepage": "https://github.com/camratchford/byoconfig",
"Source": "https://github.com/camratchford/byoconfig"
},
"split_keywords": [
"heirachaical",
" config",
" yaml",
" toml",
" json",
" plugins"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "495fbd70a5f15354082c67b08bbbaa20305d95ae85abb926ccb84aef55e896ad",
"md5": "4c1863c8beb40d59f7e68c9c64528fe2",
"sha256": "ca52c2c0c1468ab66c294290f8e98354bb0de12d0c35305c027d58037dbee5aa"
},
"downloads": -1,
"filename": "byoconfig-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4c1863c8beb40d59f7e68c9c64528fe2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 10999,
"upload_time": "2025-03-18T20:41:19",
"upload_time_iso_8601": "2025-03-18T20:41:19.474469Z",
"url": "https://files.pythonhosted.org/packages/49/5f/bd70a5f15354082c67b08bbbaa20305d95ae85abb926ccb84aef55e896ad/byoconfig-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c21cb56ae6b87b55f814f36779552eaedf446979e50ab358557c956699903c53",
"md5": "705e0dcd442f7837c9adb6e6fd1ad36d",
"sha256": "320f08daaafe2704b69c2d1d98e46cca813af3f698bf32d2d7bba09053cfaac4"
},
"downloads": -1,
"filename": "byoconfig-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "705e0dcd442f7837c9adb6e6fd1ad36d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 19462,
"upload_time": "2025-03-18T20:41:21",
"upload_time_iso_8601": "2025-03-18T20:41:21.099267Z",
"url": "https://files.pythonhosted.org/packages/c2/1c/b56ae6b87b55f814f36779552eaedf446979e50ab358557c956699903c53/byoconfig-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-03-18 20:41:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "camratchford",
"github_project": "byoconfig",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "byoconfig"
}