poormanschema
Simple and effective schema checker:
>>> from poormanschema import *
>>> check({'first_name': 1}. [{'first_name': str, 'last_name': str}])
ValueError: {first_name} should be of type "str"
It can also normalize data:
>>> check(' 2016-03-23T12:23:12 ', OR(STRIP, ISO8601))
'2016-03-23T12:23:12'
Or convert them on entry:
>>> repr(check(['1.3'], [DECIMAL]))
[Decimal('1.3')]
List of predicates
check(data, schema, path=’’) - check data agains schema, prefix error messages with path
OR(*schemas) - first schema to match is returned
ANY - can be anything
AND(*schemas) - all schemas must match
MANDATORY(schema) - only useful on dict values, indicate the corresponding key is mandatory, all other keys are optional
RE(regexp, repl=None, count=0, flag=0) - value must be a string matching regexp
ISO8601 - value must be a string like ‘2016-09-07T12:12:34’
NORMALIZE(schema, convert) - apply schema then apply converter to the result
STRIP - remove starting and ending spaces
LOWER - lowercase the string
UPPER - uppercase the string
DECIMAL - convert a string into a decimal.Decimal object
Exemple: SCIM 1.0 Core Schema of an User object
schema = {
'schemas': MANDATORY([basestring]),
'id': MANDATORY(basestring),
'externalId': MANDATORY(basestring),
'userName': MANDATORY(unicode),
'name': MANDATORY({
'formatted': MANDATORY(str),
'familyName': str,
'givenName': str,
'middleName': str,
'honorificPrefix': str,
'honorificSuffix': str,
}),
'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User': MANDATORY({
'employeeNumber': OR(STRIP, RE(r'^\d+$')),
'costCenter': OR(STRIP, RE(r'^\d+$')),
}),
'meta': {
'resourceType': 'User',
'created': ISO8601,
'lastModified': ISO8601,
'version': RE(r'^(W\\)?"[^"]"$'),
'location': str,
}
}
Metadata
Release files for poormanschema 0.0.0.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 | |
|---|---|---|---|---|
| poormanschema-0.0.0.1.tar.gz | 3.7 kB | Without provenance | Details |
Release files / poormanschema-0.0.0.1.tar.gz
| Download URL | poormanschema-0.0.0.1.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f13c5c6ac6e29d86adab0e2ab8d9c19978574f9814c8185a830ec002218bc34f
|
|
BLAKE2b-256 checksum How to use checksums |
f4a08246b2e981dace63bc43630aee2e2aac04c72e62c1c45aacac1fe3d3a450
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for poormanschema 0.0.0.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.