constload
constload is a package designed to simplify the process of loading settings into Python applications by providing certain functionality that is frequently reimplemented from project to project. This includes the ability to set defaults and set certain parameters as required.
Usage examples
When loading settings, you have a couple of options. You can provide pre-parsed data in a dictionary, or you have have data parsed for you from a filepath or from a string.
from constload import ConstantLoader
# Loading JSON from file
c = ConstantLoader("/path/to/settings/file.json")
# Loading JSON from string
c = ConstantLoader("{'hello': 'world'}")
# Using preloaded dict
c = ConstantLoader(your_dict)
It's also trivial to write your own loaders.
def my_loader(data):
# Basic CSV loader
my_dict = {}
lines = data.split("\n")
for line in lines:
vals = line.split(",")
my_dict[vals[0]] = vals[1:]
return my_dict
c = ConstantLoader("/path/to/file.csv", loader=my_loader)
When you've got your data loaded, you can begin to extract values.
This is done by using tuples that contain paths to your values.
# ("user", "name") is equivalent to ["user"]["name"]
USER_NAME = c.required(("user", "name"))
USER_PETS = c.default(("user", "pets"), [])
Any changes made by c.default are automatically mirrored to the dictionary as they're being made. This means you can
work directly with the dictionary, if you so choose.
c.default(("user", "pets"), [])
c.data["user", "name"] # -> []
Installing
- With YAML support -
pip install constload[yaml] - Otherwise -
pip install constload
Licence
Licenced under the Mozilla Public Licence 2.0. Licence text.
Support
If you need help, feel free to open an issue.
Contributing
Issues/pull requests are welcome. :)
Metadata
Release files for constload 1.0.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 | Provenance | Actions |
|---|---|---|---|---|
| constload-1.0.1.tar.gz | 4.2 kB | Without provenance | Details for constload-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| constload-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for constload-1.0.1-py3-none-any.whl |
Total release size: 14.5 kB
Release files / constload-1.0.1.tar.gz
| Download URL | constload-1.0.1.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0e22536a3568b64afbc994a59536125e0e8f4d129d5c80c1a0cdd161715cce8
|
|
BLAKE2b-256 checksum How to use checksums |
216aa8343cb05b08651489f17c81e421a40d8aaa6cb2de50976dfdf7ebbf52b3
|
| 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/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Release files / constload-1.0.1-py3-none-any.whl
| Download URL | constload-1.0.1-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c74803ed8c395b65e01cc617635c0d4797040a27b2b972fd726b616509b0bcaa
|
|
BLAKE2b-256 checksum How to use checksums |
4d575ac888732b609d396daf7236b6d49f1bf3733dec243c7f7d07b5db4035ff
|
| 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/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Security for constload 1.0.1
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.