Skip to main content

Anonymous datatype validation

Project description

Example:
--------

>>> from datatype.validation import failures

>>> datatype = {'foo': [{'bar': 'int'}]}
>>> bad_value = {'foo': [{'bar': 'baz'}], 'bif': 'pow!'}

>>> failures(datatype, bad_value)
['foo[0].bar: expected int, got str', 'unexpected property "bif"']


Datatype Definitions
--------------------

Datatype definitions are represented with a small set of types that should be built-in for most languages.

Required types for proper validation:

* int
* float
* string
* boolean
* dictionary (or anonymous object)
* list (or array)


Specification
-------------

DEFINITION = PRIMITIVE | LIST | DICTIONARY
PRIMITIVE = ["nullable "] + ("int" | "str" | "float" | "bool")
DICTIONARY = {DICTIONARY-KEY: DEFINITION}
DICTIONARY-KEY = (["optional "] + DICTIONARY-KEY-NAME) | "_any_"
DICTIONARY-KEY-NAME = [A-Za-z0-9_]+
LIST = [DEFINITION]


Definition Examples (in python):
--------------------------------

definition: "int"
example value: 5

definition: {"foo": "int"}
example value: {"foo": 5}

definition: [{"foo": ["bool"]}]
example value: [{"foo": [True, False]}, {"foo": [False, False]}]


Copyright and License
---------------------

Copyright 2011 LearningStation, Inc.

Licensed under the BSD-3 License. You may obtain a copy of the License in the LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datatype-0.3.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file datatype-0.3.tar.gz.

File metadata

  • Download URL: datatype-0.3.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for datatype-0.3.tar.gz
Algorithm Hash digest
SHA256 92d3734d39b0958c6ea75f5b8b975378489bea181b5f6e4c23100f0a563d9761
MD5 b97924748f4579efe4eb2c6d14fbc3c5
BLAKE2b-256 bc20d408d3f651ef6034691fbf7ee0fb336eb22e998936f60137da850ea1e23a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page