Validobj
Validobj is library that takes semistructured data (for example JSON and YAML configuration files) and converts it to more structured Python objects. It places the emphasis on:
- Good error messages (rather than avoiding extra work in the error handling code).
- Schema defined in terms of dataclasses and other high level objects such as enums, as well as a subset of the typing module.
- Simplicity of implementation (rather than full generality).
Validobj requires a modern Python version and has no other dependencies. It progressively supports typing features as they are implemented in the standard library and language: A limited subset of the parsing facilities work with Python 3.8, which is the minimum version. The custom validation module requires at least Python 3.9.
Documentation
https://validobj.readthedocs.io/en/latest/
Example
- Define a schema using dataclasses
import dataclasses import enum from typing import Literal class DiskPermissions(enum.Flag): READ = enum.auto() WRITE = enum.auto() EXECUTE = enum.auto() @dataclasses.dataclass class Job: name: str os: set[Literal['windows', 'mac', 'linux']] script_path: str framework_version: tuple[int, int] = (1, 0) disk_permissions: DiskPermissions = DiskPermissions.READ @dataclasses.dataclass class CIConf: stages: list[Job] global_environment: dict[str, str] = dataclasses.field(default_factory=dict)
- Process a dictionary input into it using Validobj
from validobj import parse_input inp = { 'global_environment': {'CI_ACTIVE': '1'}, 'stages': [ { 'name': 'compile', 'os': ['linux', 'mac'], 'script_path': 'build.sh', 'disk_permissions': ['READ', 'WRITE', 'EXECUTE'], }, { 'name': 'test', 'os': ['linux', 'mac'], 'script_path': 'test.sh', 'framework_version': [4, 0], }, ], } print(parse_input(inp, CIConf)) # This results in a dataclass instance with the correct types: # # CIConf(stages=[ # Job(name='compile', # os={'linux', 'mac'}, # script_path='build.sh', # framework_version=(1, 0), # disk_permissions=<DiskPermissions.READ|WRITE|EXECUTE: 7>), # Job(name='test', # os={'linux', 'mac'}, # script_path='test.sh', # framework_version=(4, 0), # disk_permissions=<DiskPermissions.READ: 1>)], # global_environment={'CI_ACTIVE': '1'} # )
The set of applied transformations as well as the interface to customise processing are described in the documentation
Installation
The package can be installed with pip:
python3 -m pip install validobj
As well as with conda, from the conda-forge channel:
conda install validobj -c conda-forge
The code is hosted at
Metadata
Release files for validobj 1.6
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 |
|---|---|---|---|---|
| validobj-1.6.tar.gz | 27.6 kB | Without provenance | Details for validobj-1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| validobj-1.6-py3-none-any.whl | Python 3 | none | any | Details for validobj-1.6-py3-none-any.whl |
Total release size: 44.2 kB
Release files / validobj-1.6.tar.gz
| Download URL | validobj-1.6.tar.gz |
|---|---|
| Size | 27.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
75752f227358925d74cdd190849ea1d49a8236567e56cbf09c431bdb18faa8e0
|
|
BLAKE2b-256 checksum How to use checksums |
211ebabee4da2cbc8311e604bf2e850d0fa7b44edbe93cf33e5385197b5f1a9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.5
|
Release files / validobj-1.6-py3-none-any.whl
| Download URL | validobj-1.6-py3-none-any.whl |
|---|---|
| Size | 16.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
953d909a39610f7b4421cc61200fe7882677844aed84a45d5d3af930e281abfe
|
|
BLAKE2b-256 checksum How to use checksums |
41adac1ae033243265798d55cdaebe95f1441fae97e322bcdf63d6037f387ac4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.5
|
Security for validobj 1.6
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.