ConfLoad
A tool to handle configurations
Pypi Linkl <https://pypi.org/project/confload>__
Support
format:
- ini
- json
- yaml
origins:
- url
- environment
- objects
- files
Installation
.. code:: bash
pip3 install confload
Use
.. code:: python
from confload import Config
# Construct config with default values
cfg = Config({"test": 43})
# load from yaml, json or ini specificly
cfg.load_yaml("test.yml")
# guess loading type from suffix
cfg.load("test.ini")
cfg["abcd"]["test4"]["test2"] = 4 # automaticly create dict if key does not exists
dict(cfg) # convertible to dict, best is to use dict method
cfg.dict(copy=False)
# update methods are currently merge and replace
cfg["abcd"].merge(test4={"test3": 5}) # Merge recursively merge two dicts objects
cfg["abcd"].replace(test4={"test3": 5}) # replace will replace objects as dict's update builtins method
cfg["abcd"].update(test4={"test3": 5}) # use the strategy defined on cfg build
# You can also load your config from an url (method's parameters are passed to requests.get method)
cfg.request_json("my_site.com/config.json")
# Or from your env
cfg.env.json("MY_JSON_FILE") # Precise the format
cfg.env("MY_INI_FILE") # or let it guess using the file suffix
# you can also retrieve vars from env
cfg.env.string("MY_VAR", default="not found", name="myvar") # you can give the name to use in the config (default take env var name)
# cfg.env.int, cfg.env.float also exists
cfg.env.bool(...) # Value are case INsensitive tested.
# True value are "on", "True" or any non nulle number
# False value are "off", "False" or 0
# we can get a list too
cfg.list(...)
# and cast the result
cfg.list[int](...) # the value "1,2,3" becomes [1, 2, 3] and not ["1", "2", "3"]
cfg.dump_json("myfile.json") # can be yaml but not ini file
Nb: most of the methods can be chained
.. code:: python
cfg = Config(...).update(...).env(...).load(...)
Custom CLi parser
argparse <https://docs.python.org/3/library/argparse.html>,
click <https://click.palletsprojects.com/en/7.x/> and many others
are goods, but i found them too complicated for most of the used i had.
Based on those two, here is another parser
.. code:: python
from confload.cli import Parser, SubParser, String, Int, Float, Bool, Toggle, List
parser = Parser(
# Positional values
[
String("name"),
Int("abcde"),
],
# Optional values
[
String("lastname", aliases=["lastname", "l"]),
List("children", aliases=["child", "c"]),
Toggle("active", aliases=["active", "y"], default=False),
],
)
print(str(parser))
print(parser.aliases)
res = parser()
print(res)
Running
python3 test_parser.py -l abcde --child foo,bar --lastname trew -c another -c some,other test 56
we get the following output
.. code:: txt
[OPTIONS] NAME ABCDE
{'--lastname': lastname, '-l': lastname, '--child': children, '-c': children, '--active': active, '-y': active}
{'active': False, 'name': 'test', 'abcde': 56, 'lastname': 'trew', 'children': ['foo', 'bar', 'another', 'some', 'other']}
When we implement a tool, it is usefull to use subparser automaticly calling functions. (This is in progress)
Futur
- add support for argparse
- documentation will be done, some change may appear as well.
Metadata
Release files for confload 0.3
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 |
|---|---|---|---|---|
| confload-0.3.tar.gz | 8.4 kB | Without provenance | Details for confload-0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| confload-0.3-py3-none-any.whl | Python 3 | none | any | Details for confload-0.3-py3-none-any.whl |
Total release size: 29.2 kB
Release files / confload-0.3.tar.gz
| Download URL | confload-0.3.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9ca5e9e540759b44f9f3a49377c9e30604d010c33830b59d4b0c512e8810f0a
|
|
BLAKE2b-256 checksum How to use checksums |
f6beec8237872e720e2779fc4d906440cb376dc490d2c894b6125116ac21d0ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9
|
Release files / confload-0.3-py3-none-any.whl
| Download URL | confload-0.3-py3-none-any.whl |
|---|---|
| Size | 20.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02c416f68848817d17370b76521fadcce944a32ade3446e96d08dc653ad00c5c
|
|
BLAKE2b-256 checksum How to use checksums |
938fef8621a444149708ee58920b56d28ba4caa1e42ce1d75a411ab80d96dffa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9
|
Security for confload 0.3
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.