Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
.. image:: https://travis-ci.org/mylokin/redisext.svg?branch=master :target: https://travis-ci.org/mylokin/redisext
Schematec is a set of tools that makes input data validation easier. The purpose of this code is attempt to bring simplicity to applications logics using separation of data validation and actual data processing.
.. code:: python
import schematec as s
schema = s.dictionary( id=s.integer & s.required, name=s.string, tags=s.array(s.string), )
.. code:: python
data = { ... 'id': '1', ... 'name': 'Red Hot Chili Peppers', ... 'tags': ['funk', 'rock'], ... 'rank': '1', ... } schema(data) {'id': 1, 'name': u'Red Hot Chili Peppers', 'tags': [u'funk', u'rock']}
Schematec module is based on three basic concepts:
Schema ^^^^^^
Term "schema" is used to describe complex data struct such as dictionary(hashmap) or array(list). Schemas has two different types of validation (it is not related to array schemas):
schematec.exc.SchemaError
is raised in case provided data is incorrect.
Order of schema validations:
#. Unbound Validators #. Schemas(inner) #. Converters #. Bound Validators
Validator ^^^^^^^^^
Term "validator" describes callable objects that perform different types of checks. There are two types of validators in schematec:
Raises schematec.exc.ValidationError
.
Schematec provides following validators:
required check if value is provided
length check iterable for max length
regex check if given value is valid
Converter ^^^^^^^^^
Term "converter" is used to describe cast functions. Schematec supports subset of JSON data types.
Basic types:
Containers:
Raises schematec.exc.ConvertationError
.
#. Any int or long value #. Any suitable string/unicode #. Boolean value
#. Any float or int or long value #. Any suitable string/unicode #. Boolean value
#. Any suitable string/unicode #. Any int or long value
#. Boolean value #. 0 or 1 #. '0' or '1' #. u'0' or u'1'
#. Any mapping value(collections.Mapping)
#. Any iterable value(collections.Iterable), but not a mapping
"Schema", "validator" and "converter" are internally referenced as "descriptors". Common task is creation of complex validation rules for a field(or "complex descriptors"). To do this use bitwise "and" operator on descriptors:
.. code:: python
import schematec schematec.integer & schematec.required <schematec.abc.ComplexDescriptor object at 0x10b05a0d0>
Schematec supports additional "magic" way to define your schemas. You can use simple dicts and lists to describe your data. For example:
.. code:: python
import schematec as s schema = { ... 'a': [{ ... 'b': s.integer, ... }] ... } data = { ... 'a': [{'b': 1}, {'b': '1'}, {}] ... } s.process(schema, data) {'a': [{'b': 1}, {'b': 1}, {}]}
.. code:: python
import schematec as s
schema = s.dictionary( id=s.integer & s.required, entity=s.dictionary( name=s.string & s.required, value=s.string, ) )
.. code:: python
data = { ... 'id': 1, ... 'entity': { ... 'name': 'song', ... 'value': 'californication', ... } ... } schema(data) {'id': 1, 'entity': {'name': u'song', 'value': u'californication'}}
.. code:: python
import schematec as s
schema = s.dictionary( id=s.integer & s.required, entity=s.dictionary( name=s.string & s.required, value=s.string, ) )
.. code:: python
data = { ... 'id': 1, ... 'entity': { ... 'value': 'californication', ... } ... } schema(data) Traceback (most recent call last): File "", line 1, in File "schematec/schema.py", line 44, in call value = schema(value, weak=weak) File "schematec/schema.py", line 32, in call validator(name, data) File "schematec/validators.py", line 12, in call raise exc.ValidationError(name) schematec.exc.ValidationError: name
FAQs
Set of tools that makes input data validation easier
We found that schematec demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.