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
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file psiconfig-0.0.8.tar.gz.
File metadata
- Download URL: psiconfig-0.0.8.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7fbb22ac8f1ed80b05abe79b93b1bf34e255e82bcd37056d3adc1f7415f4f3e
|
|
| MD5 |
a5c0dfd5b7b08f9d175de4da9429ab7e
|
|
| BLAKE2b-256 |
d0298556d6cfa0ac658fcbb5ae61ff51dbb6ef9ea96c76076412dc337fe65ef5
|
File details
Details for the file psiconfig-0.0.8-py3-none-any.whl.
File metadata
- Download URL: psiconfig-0.0.8-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b760ca35511c96801ca9ee63575c240407a632f75bdade6a2f983713e55d35d4
|
|
| MD5 |
a2c77c28c6591d1ee128f0d0625c4e7f
|
|
| BLAKE2b-256 |
1bb75e73f87cfa843dd03f5b0c28d2f9bbbf67538fd7934e4e9b85d488a946e6
|