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.9.tar.gz (20.9 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.9-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: psiconfig-0.0.9.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.12.7 Linux/6.6.65-1-MANJARO

File hashes

Hashes for psiconfig-0.0.9.tar.gz
Algorithm Hash digest
SHA256 c7046ec14c3a3f7211812d3a3b35dbe5ccd8f798d4b641528d071c5e4035a6e7
MD5 f14830ecb7b4d8baa9184495d4f07066
BLAKE2b-256 0a538b8b183ec63519efb8748e03833df40fea6ff5ea769c63456501cb3851d0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: psiconfig-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.12.7 Linux/6.6.65-1-MANJARO

File hashes

Hashes for psiconfig-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 7b7f1d8dd9a72795e070c49a16b61d525d3b7de5b0875ab94ea92369376720c0
MD5 ff240082db7b56e6eedc8f29e0b19587
BLAKE2b-256 c314189c900bf67876e67736a405dc15349b4a764b72663b39b1e19e55692f31

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