Bonfig
>>> import os, json, configparser
>>> from bonfig import Bonfig, Store
>>>
>>> class Config(Bonfig):
... with Store() as basic:
... VERSION = basic.Field('0.2')
...
... with Store() as secrets:
... CREDENTIALS = secrets.Field(default="XXXXXX-XX")
... PIN = secrets.IntField(default=1234)
...
... with Store() as data:
... SAMPLE = data.Field()
... AVERAGE = data.FloatField()
...
... with Store() as prefs:
... with prefs.Section('LINES') as lines:
... X_MARKER = lines.Field()
... SHOW = lines.BoolField()
...
... with prefs.Section('META') as meta:
... DATE = meta.DatetimeField(name='start', fmt='%d/%m/%y')
...
... def load(self, fn):
... self.basic = {}
... self.secrets = dict(os.environ)
...
... with open(f"examples/{fn}.json") as f:
... self.data = json.load(f)
...
... with open(f"examples/{fn}.ini") as f:
... self.prefs = configparser.ConfigParser()
... self.prefs.read_file(f)
...
>>> c = Config("bonfig")
>>> c.VERSION
'0.2'
>>> c.CREDENTIALS
"XXXXXX-XX"
>>> c.AVERAGE
3.14159
>>> c.SHOW
True
>>> c.DATE
datetime.datetime(1982, 11, 18, 0, 0)
>>> c = Config(frozen=False) # create a mutable version
>>> c.AVERAGE = 365.2
>>> c.AVERAGE
365.2
Stop writing your configurations as dictionaries and strange floating dataclasses, make them Bonfigs and make use of
a whole bunch of great features:
- Declare your configurations as easy to read classes.
- Pull in values from various sources into one neatly packaged class.
- Get all the power that comes with classes built into your configurations - polymorphism, custom methods and custom initialisation.
- Sleep safe in the knowledge your config won't change unexpectedly with configuration with
Bonfig.freeze. - Ready made serialisation and deserialisation with custom
Fields-IntField,FloatField,BoolFieldandDatetimeField, with tools to help you easily define your own.
Installation
pip install bonfig
Please checkout the project docs for more information: https://0hughman0.github.io/bonfig/index.html
Metadata
Release files for bonfig 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bonfig-0.2.2.tar.gz | 9.8 kB | Without provenance | Details for bonfig-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bonfig-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for bonfig-0.2.2-py3-none-any.whl |
Total release size: 20.1 kB
Release files / bonfig-0.2.2.tar.gz
| Download URL | bonfig-0.2.2.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
79628cfe8257d2507c25886e7a02ac7da4e4be257107a58501311fc5d117cf96
|
|
BLAKE2b-256 checksum How to use checksums |
c1b430aeda94d61d247f6e40f287e8212f86493742fe1398090c9c3d06a33a5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.3 Windows/10
|
Release files / bonfig-0.2.2-py3-none-any.whl
| Download URL | bonfig-0.2.2-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4748805242057a4277c193cded96937d49d2e4704f37bdedb942acc7db537650
|
|
BLAKE2b-256 checksum How to use checksums |
4e6b9fb80debcf78b69200d8206d5d147ca116c0cf7afcfe88f86de446e00a35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.3 Windows/10
|
Security for bonfig 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.