Skip to main content

Create, update, and remove values from a configuration file made by ConfigHandler.

Project description

ConfigHandler

Description

Create, update, and remove values from a configuration file made by ConfigHandler.

  • Simple Mode: Store simple data (e.g., version, program statistics, etc.) in a single file.
  • Advanced Mode: Store configuration data using JSON data format. Supports metadata, encryption, and compression.

Installation

  • via pip: pip install py-config-handler
  • as a Git submodule: git submodule add https://github.com/Chris1320/ConfigHandler-python.git

Usage

Simple Mode

[QuickStart] Creating a New Configuration File

from config_handler.simple import Simple

config = Simple("config.ini")

# Create a new configuration file by assigning key-value pair.
config.set("foo", "bar")  # "foo" is the key, "bar" is the value.
config.set("nums", 123)
config.set("dec", 3.14)
config.set("Aboolean", True)
config.set("unintentional variable!", "unintentional value.")

# Remove values
config.remove("unintentional variable!")

config.save()  # Save the data to the file.

[QuickStart] Loading an Existing Configuration File

from config_handler.simple import Simple

config = Simple("config.ini")

# Load the data from the file.
config.load()

# Get values from the loaded data.
config.get("foo")  # "foo" is the key.

# Change value of a key.
config.set("foo", "barred")

# Add a new key-value pair.
config.set("new_key", "new_value")

# Encode configuration file to Base64.
config.isbase64 = True

# Save changes
config.save()

A key can be any string, but must not start with a #, include a =, or include a \n. A value can by any string, integer, or float.

Advanced Mode

[QuickStart] Creating a New Configuration File

from config_handler.advanced import Advanced

config = Advanced("config.ini", "p4ssw0rd")  # Password is required when encryption is not None.

config.new(
    name="Advanced Mode Test",
    author="Chris1320",
    compression="zlib",
    encryption="aes256"
)

# Create a new configuration file by assigning key-value pair.
config.set("foo", "bar")  # "foo" is the key, "bar" is the value.
config.set("nums", 123)
config.set("dec", 3.14)
config.set("Aboolean", True)
config.set("unintentional variable!", "unintentional value.")

# Remove values
config.remove("unintentional variable!")

config.save()  # Save the data to the file.

[QuickStart] Loading an Existing Configuration File

from config_handler.advanced import Advanced

config = Advanced("config.ini", "p4ssw0rd")  # Password is required when encryption is not None.

# Load the data from the file.
config.load()

# Get values from the loaded data.
config.get("foo")  # "foo" is the key.

# Change value of a key.
config.set("foo", "barred")

# Add a new key-value pair.
config.set("new_key", "new_value")

# Encode configuration file to Base64.
config.metadata()  # Get metadata of the configuration file.

# Save changes
config.save()

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

py-config-handler-1.0.2.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

py_config_handler-1.0.2-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file py-config-handler-1.0.2.tar.gz.

File metadata

  • Download URL: py-config-handler-1.0.2.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for py-config-handler-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1fe23b6eb434381aded87d6f24b3d91c575340c8b5a644af7e38b18cd37ef47a
MD5 c17ec48fce6112432e7c69d481fe050d
BLAKE2b-256 42805e2c88ed05ecc05be8618a5d4c28643331c12ad52226c820c62c6db116cb

See more details on using hashes here.

File details

Details for the file py_config_handler-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: py_config_handler-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for py_config_handler-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 82bb2f71ca54121b3e3c6730030fb899cbc0a329c0ac5f6615c505f67357234b
MD5 f28acc13cb2c2386bb00c88015d31365
BLAKE2b-256 7708e5930d1f9ac931e510edd12655ee00b606480af3347db79dc6aa53a8aa13

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