datastruct
A small but useful package to load, validate and use typed data structures, including configuration files.
You get:
An easy way to define a typed hierarchical data structure.
Hassle free definition nested structures.
Loading from a variety of formats (json, yaml and everything supported by Serialize),
Error checking including: missing values, unexpected value, wrong type, wrong value.
Easy to integrate in another app error reporting.
Installation
pip install datastruct
Usage
>>> from typing import List
>>> from datastruct import DataStruct
>>> class EmailServer(DataStruct):
...
... host: str
... port: int
... username: str
... password: str
>>>
>>> class Config(DataStruct):
...
... download_path: str
... email_servers: List[EmailServer]
... wait_time: float
>>>
>>> cfg = Config.from_filename('settings.yaml')
When an invalid value is found, an exception will be raised.
If you want to accumulate all errors for inspection:
>>> cfg = Config.from_filename('settings.yaml', raise_on_error=False)
>>> print(cfg.get_errors())
You can then use the DataStruct object in your code:
>>> print(cfg.email_servers[0].host)
Other features
You can easily specify default values that
>>> class EmailServer(DataStruct):
...
... host: str
... port: int = 25
... username: str
... password: str
See AUTHORS for a list of the maintainers.
To review an ordered list of notable changes for each version of a project, see CHANGES
Metadata
Release files for datastruct 0.5
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 |
|---|---|---|---|---|
| datastruct-0.5.tar.gz | 16.4 kB | Without provenance | Details for datastruct-0.5.tar.gz |
Release files / datastruct-0.5.tar.gz
| Download URL | datastruct-0.5.tar.gz |
|---|---|
| Size | 16.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85153b97cb1579dfbae627ab3294cd873e9501fa614d74eb045db1ce141438ea
|
|
BLAKE2b-256 checksum How to use checksums |
03c9aff0d56492f52112ccb1e2295c9f5863b35ff1bab35b11fe7eb04f20a410
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
|
Security for datastruct 0.5
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.