Skip to main content

A module to validate and load config files.

Project description

configration

A module to validate and load config files.

Installation

pip install psiconfig

How to use

psiconfig supports json and toml configurations. (To use json replace TomlConfig with JsonConfig in the following code.)

Set up a module to handle configuration

  1. Create a config module in your project:
"""Config for <project>."""
from psiconfig import TomlConfig
CONFIG_PATH = <path to config file>  # NB need not exist


DEFAULT_CONFIG = {
    # a dictionary of default items that will be used if no config file is found
}


def get_config() -> TomlConfig:
    return TomlConfig(path=CONFIG_PATH, defaults=DEFAULT_CONFIG)


def save_config(config: TomlConfig) -> TomlConfig | None:
    result = config.save()
    if result != config.STATUS_OK:
        return None
    config = TomlConfig(CONFIG_PATH)
    return config


config = get_config()

Accessing config in a module

If you want to access config in a module, then, if you want the config version at start up:

from config import config

or, if you want the latest saved version of config:

from config import get_config
...
    self.config = get_config()

Config properties and methods

config.config: a dict of items in the configuration

get_config(path): returns the config object

save_config(config): saves the config items

Updating config items

config.config[<item key>] = <item value>

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

psiconfig-0.0.15.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

psiconfig-0.0.15-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file psiconfig-0.0.15.tar.gz.

File metadata

  • Download URL: psiconfig-0.0.15.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for psiconfig-0.0.15.tar.gz
Algorithm Hash digest
SHA256 255ae595392262067ee9ea7ecaf0b0df92b4ec0bffd3e18ae1a0cf7f35913c83
MD5 4f5588cd47cb285de2ae6e3eb5b674f4
BLAKE2b-256 79599aeb78e7e8b9a8ce1bdd81c37745fdca51bad1d4e7818b66fc2b9ec47e37

See more details on using hashes here.

File details

Details for the file psiconfig-0.0.15-py3-none-any.whl.

File metadata

File hashes

Hashes for psiconfig-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 cccfd4b9b6b34543fe02a79f037eeda11df2d9ce0c283c4586ba5e88d5a0befe
MD5 b3ca5414cefec0f8404827f7ae2554c4
BLAKE2b-256 ad4b2b60a4c39dfd7f908b77db2d2222adc2a0ac28db9a91adb7f4688911f1b0

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