PyCont
Validate and genereate pythpon objects from templates. Library is powered by Trafaret and helps to validate and genereate data from template.
Documentation
https://pycont.readthedocs.io/en/latest/index.html
Usage
pip install pycont
Simple data template
>>> from pycont import Template, Contract
>>> import trafaret as t
>>> contract = Contract(Template(t.Int()))
>>> print(contract(42))
42
>>> print(contract('test'))
Traceback (most recent call last):
...
ValueError: Invalid value: value can't be converted to int
Simple list template
>>> from pycont import Template, Contract
>>> import trafaret as t
>>> contract = Contract([
... Template(t.Int())
...])
>>> print(contract([42]))
[42]
>>> print(contract([1, 2, 3, 4, 5]))
[1, 2, 3, 4, 5]
>>> print(contract([1, 2, 3, 'error']))
Traceback (most recent call last):
...
ValueError: Invalid value: value can't be converted to int
Static list template
>>> from pycont import Template, Contract
>>> import trafaret as t
>>> contract = Contract([
... Template(t.Int()),
... Template(t.String()),
... Template(t.Float()),
...])
>>> print(contract([42, 'test', 12.5]))
[42, 'test', 12.5]
Dict template
>>> from pycont import Template, Contract
>>> import trafaret as t
>>> contract = Contract(Template(t.Int(), default=42))
>>> print(contract('error'))
42
>>> contract = Contract({
... 'id': Template(t.Int()),
... 'value': Template(t.String()),
...})
# Key 'key' not contains in template
>>> print(contract({'id': 1, 'value': 'test', 'key': None}))
{'id': 1, 'value': 'test'}
Deafult value
pycont.Template contains an optional argument default (the default type must be valid to Tremplate checker). If the argument is set, then if the check fails, this value will be returned.
>>> from pycont import Template, Contract
>>> import trafaret as t
>>> contract = Contract({
... 'id': Template(t.Int()),
... 'value': Template(t.String(), default='None'), # 'None' is a string
...})
>>> print(contract({'id': 1, 'key': None})) # key 'value' is not set
{'id': 1, 'value': 'None'}
Metadata
Release files for pycont 0.0.4
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 | |
|---|---|---|---|---|
| pycont-0.0.4.tar.gz | 9.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pycont-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.1 kB
Release files / pycont-0.0.4.tar.gz
| Download URL | pycont-0.0.4.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a966714104bed7751d4800a4b43e60408d21330bd3f3fbcd12436ba8b51d9cf5
|
|
BLAKE2b-256 checksum How to use checksums |
a211b71180c45c5eaa265a19c588bd2639111d5df0995a2ca2848e3105b2799a
|
| 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/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.0
|
Release files / pycont-0.0.4-py3-none-any.whl
| Download URL | pycont-0.0.4-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
57502033c896f0e46bc2d8aeaed854b46af7a760c74177784403c393a5cb86bb
|
|
BLAKE2b-256 checksum How to use checksums |
505dfb9af048594583dc517034772bbf32845b5e368a56dbc32bf924cdddd1b3
|
| 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/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.0
|
Security for pycont 0.0.4
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.