wr-schemas
A schema describes:
a data structure
a mapping of one data structure into another
A schema consists of a list of fields.
A field doesn’t have a type – it is a type itself, in a way. Instead of a type, a field has a bi-directional mapping. Given two different data structures x and y, a mapping describes how to calculate x.f from y.f and how to calculate y.f from x.f.
Fields support following attributes:
name
mapping
default
source_name (source_names)
min_len, max_len, auto_trim
min, max
choices
regex
required, forbidden
nullable
Also:
Nested fields are supported.
Fields are easy to clone for reuse.
Fields and schemas are easy to reverse.
Schemas are easy to chain.
from wr_schemas import Field, Schema, Mappings
class Fields:
user_id = Field('id', mapping=int, min=1)
user_username = Field('username', min_len=5, max_len=100, regex=r'^[a-zA-Z0-9_\-\.@]+$')
user_password = Field('password', min_len=10, max_len=100, regex=r'^[a-zA-Z0-9]+$')
user_dob = Field('date_of_birth', mapping=Mappings.date())
CreateUser = Schema(
Fields.user_username.clone(required=True),
Fields.user_password.clone(default=None),
Fields.user_dob.clone(default=None),
)
payload = CreateUser.load({'username': 'marcus.aurelius@rome.gov'})
assert payload.username == 'marcus.aurelius@rome.gov'
assert payload.password is None
assert payload.date_of_birth is None
print(CreateUser.dump(payload))
Flask:
from wr_schemas import Field, Schema, Mappings
from wr_schemas.flask_request import FlaskRequestSchemaMixin
CreateUser = Schema(
Field('username', required=True),
Field('password', required=True),
mixins=[FlaskRequestSchemaMixin],
)
user = CreateUser.from_request()
Metadata
Release files for wr-schemas 0.5.0
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 |
|---|---|---|---|---|
| wr-schemas-0.5.0.tar.gz | 10.0 kB | Without provenance | Details for wr-schemas-0.5.0.tar.gz |
Release files / wr-schemas-0.5.0.tar.gz
| Download URL | wr-schemas-0.5.0.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
defd0ae7e4bfae34924035a6b816b92640c74feb30239aa1dbae2297f42cf064
|
|
BLAKE2b-256 checksum How to use checksums |
6ad21b2b6d72a149b2d1d7dacad98a77db2ebe88aaf4f676311b03a155057e7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for wr-schemas 0.5.0
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.