dictspec – Validator for JSON/YAML/dicts
dictspec is a simple Python library that validates dictionary and list based data structures. You can use it to validate JSON/YAML documents against your own specification.
It is MIT licensed and uses relative imports, so you can just drop it into your project.
Examples
Validate against plain Python data objects or types:
>>> spec = {
... 'foo': 1,
... 'bar': [basestring],
... }
>>> data = {
... 'foo': 4,
... 'bar': ['hello', u'w\x00F6rld']}
... }
>>> from dictspec.validator import validate
>>> validate(spec, data)
Use more complex specs and get detailed errors:
>>> from dictspec.spec import number, required >>> spec = { ... required('foo'): number(), ... 'bar': bool(), ... } >>> data = { ... # missing 'foo' key ... 'bar': 4, # wrong type ... 'baz': True, # unknown key ... }>>> from dictspec.validator import ValidationError >>> try: ... validate(spec, data) ... except ValidationError, ex: ... print ex.errors ["missing 'foo' not in .", "unknown 'baz' in .", '4 in bar not of type bool']
Also with recursion and arbitrary keys:
>>> from dictspec.spec import anything, recursive
>>> spec = {
... 'hello': recursive({
... anything(): recursive(),
... })
... }
>>> data = {
... 'hello': {'any': {'thing': {'recursive':{}}}}
... }
>>> validate(spec, data)
Metadata
Release files for dictspec 0.2.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 |
|---|---|---|---|---|
| dictspec-0.2.1.tar.gz | 6.3 kB | Without provenance | Details for dictspec-0.2.1.tar.gz |
Release files / dictspec-0.2.1.tar.gz
| Download URL | dictspec-0.2.1.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
305568ce191759b410047cecdcec16534f0580e5f33a740eb8965ad56557d14d
|
|
BLAKE2b-256 checksum How to use checksums |
434bbfa11631ea2d26ccf0b244f4a1a0583e92c6586f5c8df3d051c880238dca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for dictspec 0.2.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.