Badger_Config_Handler
A python library for handling code-declared and file-defined settings.
Supports saving to JSON and YAML files.
Data types
native
the file handlers have native support for these types and are used as is, no conversion is done on these values
- string
- int
- float
- bool
- None / null
supported
Badger_Config_Section
converted using
- serialize:
{VAR}.to_dict() - de-serialize:
Badger_Config_Section.from_dict({VAR})
datetime.datetime
converted using
- serialize:
{VAR}.isoformat() - de-serialize:
datetime.fromisoformat({VAR})
pathlib.Path
converted using
- serialize:
str({VAR}) - de-serialize:
pathlib.Path({VAR})
Collections
NOTE:
It is recommended to use a Config Section instead of Collections.
If collections are used items should be of native type only, if they are not of native type they are serialized but can NOT be de-serialize.
Code using these values must handle these cases.
dict
list
Config Base
Property's
_config_file_path
path to the config file
ALLOWED_FILE_TYPES
all allowed file extensions
Function's
setup()
save()
Save config to file
load()
Load config from file
sync()
Sync config with file
runs: load() - save() - load()
this adds new config fields to the file or removes old ones
Config Section
Property's
section_name
name of the current section
root_path
by default the project root path or overridden by the parent section
parent_section
reference to the parent section (if it exists)
Function's
setup()
Replacement for __init__()
should be used to set default values
NOTE: the property parent_section is NOT available during this
pre_process()
Pre process values before save()
useful for:
- converting unsupported data type to a native or supported type
- converting absolute paths to relative (keeps them short in the config file)
post_process()
post process values after load()
useful for:
- creating unsupported data type from native or supported type
- converting relative paths to absolute (keeps them short in the config file)
to_dict(bool)
converts all values to a dictionary
Parameters:
| param | type | required | default |
|---|---|---|---|
| convert_to_native | bool | True |
from_dict()
Reconstruct Config Section from dictionary
Parameters:
| param | type | description | required | default |
|---|---|---|---|---|
| data | dict[str, native] | the dict representation of this section (as generated from to_dict(True) ) | x | |
| safe_load | bool | ! UNTESTED ! True -> Only variables that already exist in the class are set (uses hasattr) False -> New variables can be set from config file |
True | |
| danger_convert | bool | ! UNTESTED ! For details see docs of _native_to_var() |
False |
Release files for Badger-Config-Handler-publishing-test 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| Badger-Config-Handler-publishing-test-0.2.1.tar.gz | 11.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Badger_Config_Handler_publishing_test-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:23.9 kB
Release files / Badger-Config-Handler-publishing-test-0.2.1.tar.gz
| Download URL | Badger-Config-Handler-publishing-test-0.2.1.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13ee432831571242086af9682e6277c24a12d52280d38fd55344bf79ad7dc5b4
|
|
BLAKE2b-256 checksum How to use checksums |
391dc97cdcdf0594e5138f625bf9852f7874357120d66591b9310528f08cdb91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / Badger_Config_Handler_publishing_test-0.2.1-py3-none-any.whl
| Download URL | Badger_Config_Handler_publishing_test-0.2.1-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9bcde3ddbfb91c3d500e5f24183bf1fcffd86a12224078ea4009131900f68c59
|
|
BLAKE2b-256 checksum How to use checksums |
63fc119a31575ec856ee38d68931ef87dee90096f634e7db632f4b75b8a6a0db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|