Skip to main content

A simple configuration manager

Project description

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

configurationlib-1.2.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

configurationlib-1.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file configurationlib-1.2.0.tar.gz.

File metadata

  • Download URL: configurationlib-1.2.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for configurationlib-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e668d190d9c93e652b411affe0c489c01ec619bab93a219748845cf03ae24892
MD5 1de665385ee043084b862c472b539fe8
BLAKE2b-256 39230f772da6ede488a85487071d092fcb4fb82a149b1d6a50d26cfa1110f268

See more details on using hashes here.

File details

Details for the file configurationlib-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for configurationlib-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2601876f65686eda1f8d5d2ae0c8fe12c264e8eda961593340f5d70be0d8a865
MD5 d18c6f07e3c7225d0e6d5b09be8acb24
BLAKE2b-256 9f84cc5e0e5644a05f58db90319b258d04bc84d52c9e0ce5484e5074342445d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page