Configurationlib
A simple configuration manager for Python that allows you to easily manage nested configurations using JSON files.
Features
- Load and save configurations from/to a JSON, YAML or .env file.
- Create nested dictionaries dynamically.
- Retrieve configuration values easily.
Installation
You can install the package via pip:
pip install configurationlib
Note
If the file specified does not exist, it will be created.
Usage
[!WARNING] Please do note, if you specify the wrong file with the wrong format, it may load incorrectly or may break your file.
Here is a simple example of the usage of this module:
import configurationlib
# Create an instance of the configuration manager
config = configurationlib.Instance(file="config.json") # Choose any file name you like! The file will be created if it does not exist.
# Use save() to get access to the current configuration and set values
config.save()["dic1"] = {} # Initialize a new dictionary
config.save()["dic1"]["afewmoredic"] = {} # Initialize a nested dictionary
config.save()["dic1"]["afewmoredic"]["key"] = "value" # Set a value
config.save()['weird'] = True
# Retrieve values from nested dictionaries using get()
retrieved_value = config.get()["dic1"]["afewmoredic"]["key"] # Use config.get to retrieve the value
print(retrieved_value) # Output: value
# Save changes after modifying (optional, since save is called after every modification)
config.save()
Changing formats
If you want, You can change the format of the saved file (YAML, JSON, dotENV) the default already is JSON so if you want json, you don't need to do anything. Here is how you can change it to YAML:
import configurationlib
# Create an instance of the configuration manager
config = configurationlib.Instance(file="config.json", format=configurationlib.Format.YAML) # Use Yaml. Change this to ENV to use env
# Use save() to get access to the current configuration and set values
config.save()["dic1"] = {} # Initialize a new dictionary
config.save()["dic1"]["afewmoredic"] = {} # Initialize a nested dictionary
config.save()["dic1"]["afewmoredic"]["key"] = "value" # Set a value
# Retrieve values from nested dictionaries using get()
retrieved_value = config.get()["dic1"]["afewmoredic"]["key"] # Use config.get to retrieve the value
print(retrieved_value) # Output: value
# Save changes after modifying (optional, since save is called after every modification)
config.save()
The only line that changes is config = configurationlib.Instance(file="config.json", format=configurationlib.Format.YAML nothing else changes. It will automatically save the data into the data you'd like! If you remove format argument, it will default to JSON.
Hot Reloading
[!NOTE] Hot reloading is disabled by default
If you want to enable hot reloading, Use this:
config = configurationlib.Instance(file="config.json", format=configurationlib.Format.YAML, hot_reloading=True)
Hot reloading will check the file for changes and update the variable.
Metadata
Release files for configurationlib 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| configurationlib-1.2.2.tar.gz | 5.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| configurationlib-1.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.8 kB
Release files / configurationlib-1.2.2.tar.gz
| Download URL | configurationlib-1.2.2.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
895cc56ed088e115bd543364c1795a2f6e90b632e8d344794e38f311bb6ae606
|
|
BLAKE2b-256 checksum How to use checksums |
25fd48c19d044a911e0c2d4273f6f7dc6210d284de1a7fc4a6f3109a98c8a853
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Release files / configurationlib-1.2.2-py3-none-any.whl
| Download URL | configurationlib-1.2.2-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
efc2e7794cb929205c2d7bbecd37bcaff30c52ff50880c4107afa3e8d326d880
|
|
BLAKE2b-256 checksum How to use checksums |
10ed741a3cadce3ff82218d5f8ac16dcbe88a3f5567623a00b1d82eecd8a87b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Security for configurationlib 1.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.