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 confighandler-python
  • as a Git submodule: git submodule add https://github.com/Chris1320/ConfigHandler-python.git

Requirements

The following modules are optional:

  • pycryptodomex: AES256 encryption
  • prettytable: Prettier layout in interactive mode
  • lz4: LZ4 compression support

Usage

Simple Mode

[QuickStart] Creating a New Configuration File

    from config_handler.simple import Simple

    config = Simple("test.conf")  # Create a new Simple ConfigHandler object.

    # Add key-value pairs to the configuration file.
    config["foo"] = "bar"  # "foo" is the key, "bar" is the value.
    config["nums"] = 123
    config["dec"] = 3.14
    config["Aboolean"] = True
    config["unintentional variable!"] = "unintentional value."

    # Remove values
    del config["unintentional variable!"]

    print(config.exists)  # It will print `False` because the file does not exist yet.
    config.save()  # Save the data to the file.
    print(config.exists)  # It is now True.

[QuickStart] Loading an Existing Configuration File

    from config_handler.simple import Simple

    config = Simple("test.conf")

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

    # Get values from the loaded data.
    print(config["foo"])  # "foo" is the key.

    config["foo"] = "barred"  # Change value of a key.
    config["new_key"] = "new_value"  # Add a new key-value pair.

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

    # 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 be any string, integer, float, or boolean.

Advanced Mode

[QuickStart] Creating a New Configuration File

    from config_handler.advanced import Advanced

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

    config.new(  # Initialize a new configuration file.
        name="Advanced Mode Test",
        author="Chris1320",
        compression="zlib",
        encryption="aes256"
    )

    # Add key-value pairs to configuration file.
    config["foo"] = "bar"  # "foo" is the key, "bar" is the value.
    config["nums"] = 123
    config["dec"] = 3.14
    config["Aboolean"] = True
    config["unintentional variable!"] = "unintentional value."

    # Remove values
    del config["unintentional variable!"]

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

[QuickStart] Loading an Existing Configuration File

    from config_handler.advanced import Advanced

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

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

    # Get values from the loaded data.
    print(config["foo"])  # "foo" is the key.

    config["foo"] ="barred"  # Change value of a key.
    config["new_key"] = "new_value"  # Add a new key-value pair.

    config()  # Get metadata of the configuration file.
              # This is formerly called as `config.metadata()`.

    config.save()  # Save changes

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

ConfigHandler-python-2.0.2.tar.gz (22.5 kB view hashes)

Uploaded Source

Built Distribution

ConfigHandler_python-2.0.2-py3-none-any.whl (37.4 kB view hashes)

Uploaded Python 3

Supported by

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