Homepage: https://github.com/arterial-io/scheme
Scheme is a declarative, general-purpose data schema framework for Python. It provides a simple approach to defining data schemas, and with those schemas enables serialization and unserialization to and from a variety of data formats, rich validation with descriptive error handling, hierarchical variable interpolation, and other interesting means of interacting with data.
Scheme can be used wherever incoming and outgoing structured data needs to be well-defined and validated: APIs, configuration files, complex user input, workflow and process user cases, and so on.
>>> from scheme import *
>>> from datetime import date
>>> account = Structure({
'name': Text(nonempty=True),
'email': Email(nonempty=True),
'role': Enumeration('guest user admin', required=True, default='user'),
'active': Boolean(required=True, default=True),
'interests': Sequence(Text(nonempty=True), unique=True),
'logins': Integer(minimum=0, default=0),
'birthday': Date(),
}, name='account')
>>> json = '{"name": "Johnny Doe", "email": "johnny.doe@something.com",
"interests": ["baseball", "basketball"], "birthday": "1980-03-05"}'
>>> account.unserialize(json, 'json')
{'name': 'Johnny Doe', 'email': 'johnny.doe@something.com', 'role': 'user',
'active': True, 'interests': ['baseball', 'basketball'], 'logins': 0,
'birthday': datetime.date(1980, 3, 5)}
>>> suzy = {'name': 'Suzy Queue', 'email': 'suzy.queue@something.com',
'role': 'admin', 'active': False, 'logins': 324,
'birthday': date(1985, 12, 2)}
>>> print(account.serialize(suzy, 'yaml'))
active: false
birthday: 1985-12-02
email: suzy.queue@something.com
logins: 324
name: Suzy Queue
role: admin
>>> account.unserialize('{}', 'json')
Traceback (most recent call last):
...
scheme.exceptions.ValidationError: validation failed
[01] Required field error at (structure): account is missing required field 'name'
Field: Structure(name='account', ...)
[02] Required field error at (structure): account is missing required field 'email'
Field: Structure(name='account', ...)
>>> account.serialize({'name': 'Johnny Doe', 'email': 'johnny.doe@something.com',
'logins': -34}, 'json')
Traceback (most recent call last):
...
scheme.exceptions.ValidationError: validation failed
[01] Required field error at (structure): account is missing required field 'active'
Field: Structure(name='account', ...)
[02] Minimum value error at (structure).logins: logins must be greater then or equal to 0
Field: Integer(name='logins', minimum=0, default=0)
Value: -34
[03] Invalid value error at (structure).role: role must be one of 'guest', 'user', 'admin'
Field: Enumeration(name='role', ...)
Value: 'invalid'
Features
Simple, declarative schema definition
Rich set of field types: binary, boolean, date, datetime, decimal, email, enumeration, float integer, map, object, sequence, structure, text, time, token, tuple, uuid
Support for various serialization formats: csv, json, structured text, xml, yaml
Rich validation with descriptive error reporting: minimum/maximum length/value, pattern matching, etc.
Hierarchical variable interpolation
Schema-mediated extraction of values from arbitrary objects
Support for schema-based objects
Serialization and unserialization of schemas, for dynamic use cases
Get it
$ pip install -U scheme
Requirements
Python 2.6+ or 3.3+
License
BSD licensed. See LICENSE for more details.
Metadata
Release files for scheme 2.0.2
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 | |
|---|---|---|---|---|
| scheme-2.0.2.tar.gz | 62.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| scheme-2.0.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 123.6 kB
Release files / scheme-2.0.2.tar.gz
| Download URL | scheme-2.0.2.tar.gz |
|---|---|
| Size | 62.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e73ec58b672c898b5b2d625a96f301181b3b265d49aacd65ce3b06c6f45445c5
|
|
BLAKE2b-256 checksum How to use checksums |
05a2d063266827d5eff802e1bf5392d8fe806a225a142c224a6d32c54ceb6287
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / scheme-2.0.2-py2.py3-none-any.whl
| Download URL | scheme-2.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 61.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
9932bbe8b936fe2ba0e15411d01e803920d4b75bb552b626dd7330438c802ba3
|
|
BLAKE2b-256 checksum How to use checksums |
035afe50efd33fef5a42ea5391808bfe21a38fd5a043c3169e45353408017cbc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for scheme 2.0.2
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.