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>
Metadata
Release files for psiconfig 0.0.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| psiconfig-0.0.18.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| psiconfig-0.0.18-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.5 kB
Release files / psiconfig-0.0.18.tar.gz
| Download URL | psiconfig-0.0.18.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa79839799b33c53b19ff7fa839ee224866506767d685828b0c3a89d7882d958
|
|
BLAKE2b-256 checksum How to use checksums |
7c14eeb60688d882fb6680febedbc1ce670085582e6b660485aaa1a89f2aa527
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / psiconfig-0.0.18-py3-none-any.whl
| Download URL | psiconfig-0.0.18-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
621eb58330f7132eef6d3a1573051e3c97def644ec99c63b2d08a024c6db0aeb
|
|
BLAKE2b-256 checksum How to use checksums |
e978f14d045faf19e242a70c5006db6963b92200331fe8398ddf7f3d83837f9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|