Name | variconfig JSON |
Version |
0.0.2
JSON |
| download |
home_page | None |
Summary | VariConfig is a Python package for managing configuration files in a variety of formats and is able to handle variable substitution. |
upload_time | 2024-10-07 23:22:18 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT License Copyright (c) 2023 lllangWV Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
config
variable
yaml
json
toml
ini
variables
substitution
config-files
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# VariConfig
**VariConfig** is a flexible and powerful Python package for managing configuration files. It supports both YAML and JSON formats and allows for the use of variables within the configuration files, using template placeholders like `{{ var }}`.
## Features
- **Read Configurations**: Load configurations from YAML or JSON files.
- **Template Resolution**: Supports variables inside configuration files using template placeholders (e.g., `{{ var }}`).
- **Nested Configs**: Handles nested dictionaries as attribute-based objects for easy access.
- **Dynamic Updates**: Update configurations dynamically in the code.
- **Conversion**: Convert configurations back to standard Python dictionaries.
## Installation
To install VariConfig, use pip:
```bash
pip install variconfig
```
## Usage
### 1. Loading a Configuration
You can load configuration files in YAML or JSON format:
```python
from variconfig import ConfigDict
# Load a YAML file
config = ConfigDict.from_yaml('config.yml')
# Load a JSON file
config = ConfigDict.from_json('config.json')
```
### 2. Accessing Configuration Values
Once the configuration is loaded, values can be accessed as object attributes:
```python
# Access configuration values
print(config.data_dir) # Output: path from config.yml
print(config.logging_config.loggers.matgraphdb.level) # Output: INFO
```
### 3. Template Resolution
Variables can be defined using `{{ var }}` placeholders in the configuration file. These will be resolved when the configuration is loaded:
```yaml
root_dir: "."
data_dir: "{{ root_dir }}/data"
log_dir: "{{ root_dir }}/logs"
```
In the example above, `data_dir` will be resolved to `./data`, and `log_dir` will be resolved to `./logs`.
### 4. Updating Configurations
You can modify configuration values at runtime:
```python
# Update a configuration value
config.logging_config.loggers.matgraphdb.level = 'DEBUG'
# Print updated value
print(config.logging_config.loggers.matgraphdb.level) # Output: DEBUG
```
### 5. Converting to Dictionary
If you need to convert the configuration back to a standard Python dictionary:
```python
config_dict = config.to_dict()
print(config_dict)
```
## Example Configuration (YAML)
```yaml
root_dir: "."
data_dir: "{{ root_dir }}/data"
log_dir: "{{ root_dir }}/logs"
db_name: 'VariConfig'
logging_config:
version: 1
disable_existing_loggers: False
formatters:
simple:
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
datefmt: '%Y-%m-%d %H:%M:%S'
handlers:
console:
class: logging.StreamHandler
formatter: simple
stream: ext://sys.stdout
file:
class: logging.FileHandler
formatter: simple
filename: "{{ log_dir }}/variconfig.log"
mode: a
loggers:
variconfig:
level: INFO
handlers: [console]
propagate: no
```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "variconfig",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "config, variable, yaml, json, toml, ini, variables, substitution, config-files",
"author": null,
"author_email": "Logan Lang <lllang@mix.wvu.edu>",
"download_url": "https://files.pythonhosted.org/packages/82/b0/293267d7069842cb9285be4e821bd2764b6728df9eeb0a9fc3f7b35d77b7/variconfig-0.0.2.tar.gz",
"platform": null,
"description": "# VariConfig\n\n**VariConfig** is a flexible and powerful Python package for managing configuration files. It supports both YAML and JSON formats and allows for the use of variables within the configuration files, using template placeholders like `{{ var }}`.\n\n## Features\n\n- **Read Configurations**: Load configurations from YAML or JSON files.\n- **Template Resolution**: Supports variables inside configuration files using template placeholders (e.g., `{{ var }}`).\n- **Nested Configs**: Handles nested dictionaries as attribute-based objects for easy access.\n- **Dynamic Updates**: Update configurations dynamically in the code.\n- **Conversion**: Convert configurations back to standard Python dictionaries.\n\n## Installation\n\nTo install VariConfig, use pip:\n\n```bash\npip install variconfig\n```\n\n## Usage\n\n### 1. Loading a Configuration\n\nYou can load configuration files in YAML or JSON format:\n\n```python\nfrom variconfig import ConfigDict\n\n# Load a YAML file\nconfig = ConfigDict.from_yaml('config.yml')\n\n# Load a JSON file\nconfig = ConfigDict.from_json('config.json')\n```\n\n### 2. Accessing Configuration Values\n\nOnce the configuration is loaded, values can be accessed as object attributes:\n\n```python\n# Access configuration values\nprint(config.data_dir) # Output: path from config.yml\nprint(config.logging_config.loggers.matgraphdb.level) # Output: INFO\n```\n\n### 3. Template Resolution\n\nVariables can be defined using `{{ var }}` placeholders in the configuration file. These will be resolved when the configuration is loaded:\n\n```yaml\nroot_dir: \".\"\ndata_dir: \"{{ root_dir }}/data\"\nlog_dir: \"{{ root_dir }}/logs\"\n```\n\nIn the example above, `data_dir` will be resolved to `./data`, and `log_dir` will be resolved to `./logs`.\n\n### 4. Updating Configurations\n\nYou can modify configuration values at runtime:\n\n```python\n# Update a configuration value\nconfig.logging_config.loggers.matgraphdb.level = 'DEBUG'\n\n# Print updated value\nprint(config.logging_config.loggers.matgraphdb.level) # Output: DEBUG\n```\n\n### 5. Converting to Dictionary\n\nIf you need to convert the configuration back to a standard Python dictionary:\n\n```python\nconfig_dict = config.to_dict()\nprint(config_dict)\n```\n\n## Example Configuration (YAML)\n\n```yaml\nroot_dir: \".\"\ndata_dir: \"{{ root_dir }}/data\"\nlog_dir: \"{{ root_dir }}/logs\"\ndb_name: 'VariConfig'\n\nlogging_config:\n version: 1\n disable_existing_loggers: False\n formatters:\n simple:\n format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'\n datefmt: '%Y-%m-%d %H:%M:%S'\n handlers:\n console:\n class: logging.StreamHandler\n formatter: simple\n stream: ext://sys.stdout\n file:\n class: logging.FileHandler\n formatter: simple\n filename: \"{{ log_dir }}/variconfig.log\"\n mode: a\n loggers:\n variconfig:\n level: INFO\n handlers: [console]\n propagate: no\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2023 lllangWV Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "VariConfig is a Python package for managing configuration files in a variety of formats and is able to handle variable substitution.",
"version": "0.0.2",
"project_urls": {
"Changelog": "https://github.com/romerogroup/VariConfig/CHANGELOG.md",
"Issues": "https://github.com/romerogroup/VariConfig/issues",
"Repository": "https://github.com/romerogroup/VariConfig"
},
"split_keywords": [
"config",
" variable",
" yaml",
" json",
" toml",
" ini",
" variables",
" substitution",
" config-files"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "08cc1e83a45f864bae1dc56fe02972aff6c97b2ee1789f3491a09c90d893588a",
"md5": "2bfacdac54509284510a5bcfea611070",
"sha256": "e7e9a66c56720f8390e228e005d62a87b051f16720c84513b4e173826de9957a"
},
"downloads": -1,
"filename": "variconfig-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2bfacdac54509284510a5bcfea611070",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 11123,
"upload_time": "2024-10-07T23:22:16",
"upload_time_iso_8601": "2024-10-07T23:22:16.984583Z",
"url": "https://files.pythonhosted.org/packages/08/cc/1e83a45f864bae1dc56fe02972aff6c97b2ee1789f3491a09c90d893588a/variconfig-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "82b0293267d7069842cb9285be4e821bd2764b6728df9eeb0a9fc3f7b35d77b7",
"md5": "4cf3f8263761e1a9a62005dea92f1acd",
"sha256": "cb9eb01301cf05c59cf970d56083ca21f5e9070c6df87948e6c3ffab7dcb1cfb"
},
"downloads": -1,
"filename": "variconfig-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "4cf3f8263761e1a9a62005dea92f1acd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 20602,
"upload_time": "2024-10-07T23:22:18",
"upload_time_iso_8601": "2024-10-07T23:22:18.510398Z",
"url": "https://files.pythonhosted.org/packages/82/b0/293267d7069842cb9285be4e821bd2764b6728df9eeb0a9fc3f7b35d77b7/variconfig-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-07 23:22:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "romerogroup",
"github_project": "VariConfig",
"github_not_found": true,
"lcname": "variconfig"
}