schema-markdown


Nameschema-markdown JSON
Version 1.2.7 PyPI version JSON
download
home_pagehttps://github.com/craigahobbs/schema-markdown
SummaryA schema definition and validation library
upload_time2024-04-03 22:47:35
maintainerNone
docs_urlNone
authorCraig A. Hobbs
requires_pythonNone
licenseMIT
keywords schema validate json
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # schema-markdown

[![PyPI - Status](https://img.shields.io/pypi/status/schema-markdown)](https://pypi.org/project/schema-markdown/)
[![PyPI](https://img.shields.io/pypi/v/schema-markdown)](https://pypi.org/project/schema-markdown/)
[![GitHub](https://img.shields.io/github/license/craigahobbs/schema-markdown)](https://github.com/craigahobbs/schema-markdown/blob/main/LICENSE)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/schema-markdown)](https://pypi.org/project/schema-markdown/)

schema-markdown is a schema definition and validation library.


## Links

- [The Schema Markdown Language](https://craigahobbs.github.io/schema-markdown-js/language/)
- [API Documentation](https://craigahobbs.github.io/schema-markdown/)
- [Source code](https://github.com/craigahobbs/schema-markdown)


## Define a Schema

Schemas are defined using the
[Schema Markdown language](https://craigahobbs.github.io/schema-markdown-js/language/),
which is parsed by the
[parse_schema_markdown](https://craigahobbs.github.io/schema-markdown/reference.html#parse-schema-markdown)
function. For example:

~~~ python
from schema_markdown import parse_schema_markdown

model_types = parse_schema_markdown('''\
# An aggregate numerical operation
struct Aggregation

    # The aggregation function - default is "Sum"
    optional AggregationFunction aggregation

    # The numbers to aggregate on
    int[len > 0] numbers

# An aggregation function
enum AggregationFunction
    Average
    Sum
''')
~~~


## Validate using a Schema

To validate an object using the schema, use the
[validate_type](https://craigahobbs.github.io/schema-markdown/reference.html#validate-type)
function. For example:

~~~ python
from schema_markdown import validate_type

validate_type(model_types, 'Aggregation', {'numbers': [1, 2, '3', 4]})

{'numbers': [1, 2, 3, 4]}
~~~

Notice that the numerical input '3' above is *type-massaged* to the integer 3 by validation.

Validation fails if the object does not match the schema:

~~~ python
from schema_markdown import ValidationError

try:
    validate_type(model_types, 'Aggregation', {'numbers': [1, 2, 'asdf', 4]})
except ValidationError as exc:
    str(exc)

"Invalid value 'asdf' (type 'str') for member 'numbers.2', expected type 'int'"
~~~

Validation also fails if a member constraint is violated:

~~~ python
try:
    validate_type(model_types, 'Aggregation', {'numbers': []})
except ValidationError as exc:
    str(exc)

"Invalid value [] (type 'list') for member 'numbers', expected type 'array' [len > 0]"
~~~


## Document a Schema

To document the schema, download the
[documentation application](https://github.com/craigahobbs/schema-markdown-doc#the-schema-markdown-documentation-viewer)
stub and save the type model as JSON:

~~~ sh
curl -O https://craigahobbs.github.io/schema-markdown-doc/extra/index.html
python3 \
    -c 'from model import model_types; import json; print(json.dumps(model_types))' \
    > model.json
~~~

To host locally, start a local static web server:

~~~ sh
python3 -m http.server
~~~


## Development

This package is developed using [python-build](https://github.com/craigahobbs/python-build#readme).
It was started using [python-template](https://github.com/craigahobbs/python-template#readme) as follows:

~~~ sh
template-specialize python-template/template/ schema-markdown/ -k package schema-markdown -k name 'Craig A. Hobbs' -k email 'craigahobbs@gmail.com' -k github 'craigahobbs' -k nomain 1
~~~

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/craigahobbs/schema-markdown",
    "name": "schema-markdown",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "schema, validate, json",
    "author": "Craig A. Hobbs",
    "author_email": "craigahobbs@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5a/4e/838716efa189d10ab6f87c4ae197a14b71f4465b8b36712161cadb7878cc/schema-markdown-1.2.7.tar.gz",
    "platform": null,
    "description": "# schema-markdown\n\n[![PyPI - Status](https://img.shields.io/pypi/status/schema-markdown)](https://pypi.org/project/schema-markdown/)\n[![PyPI](https://img.shields.io/pypi/v/schema-markdown)](https://pypi.org/project/schema-markdown/)\n[![GitHub](https://img.shields.io/github/license/craigahobbs/schema-markdown)](https://github.com/craigahobbs/schema-markdown/blob/main/LICENSE)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/schema-markdown)](https://pypi.org/project/schema-markdown/)\n\nschema-markdown is a schema definition and validation library.\n\n\n## Links\n\n- [The Schema Markdown Language](https://craigahobbs.github.io/schema-markdown-js/language/)\n- [API Documentation](https://craigahobbs.github.io/schema-markdown/)\n- [Source code](https://github.com/craigahobbs/schema-markdown)\n\n\n## Define a Schema\n\nSchemas are defined using the\n[Schema Markdown language](https://craigahobbs.github.io/schema-markdown-js/language/),\nwhich is parsed by the\n[parse_schema_markdown](https://craigahobbs.github.io/schema-markdown/reference.html#parse-schema-markdown)\nfunction. For example:\n\n~~~ python\nfrom schema_markdown import parse_schema_markdown\n\nmodel_types = parse_schema_markdown('''\\\n# An aggregate numerical operation\nstruct Aggregation\n\n    # The aggregation function - default is \"Sum\"\n    optional AggregationFunction aggregation\n\n    # The numbers to aggregate on\n    int[len > 0] numbers\n\n# An aggregation function\nenum AggregationFunction\n    Average\n    Sum\n''')\n~~~\n\n\n## Validate using a Schema\n\nTo validate an object using the schema, use the\n[validate_type](https://craigahobbs.github.io/schema-markdown/reference.html#validate-type)\nfunction. For example:\n\n~~~ python\nfrom schema_markdown import validate_type\n\nvalidate_type(model_types, 'Aggregation', {'numbers': [1, 2, '3', 4]})\n\n{'numbers': [1, 2, 3, 4]}\n~~~\n\nNotice that the numerical input '3' above is *type-massaged* to the integer 3 by validation.\n\nValidation fails if the object does not match the schema:\n\n~~~ python\nfrom schema_markdown import ValidationError\n\ntry:\n    validate_type(model_types, 'Aggregation', {'numbers': [1, 2, 'asdf', 4]})\nexcept ValidationError as exc:\n    str(exc)\n\n\"Invalid value 'asdf' (type 'str') for member 'numbers.2', expected type 'int'\"\n~~~\n\nValidation also fails if a member constraint is violated:\n\n~~~ python\ntry:\n    validate_type(model_types, 'Aggregation', {'numbers': []})\nexcept ValidationError as exc:\n    str(exc)\n\n\"Invalid value [] (type 'list') for member 'numbers', expected type 'array' [len > 0]\"\n~~~\n\n\n## Document a Schema\n\nTo document the schema, download the\n[documentation application](https://github.com/craigahobbs/schema-markdown-doc#the-schema-markdown-documentation-viewer)\nstub and save the type model as JSON:\n\n~~~ sh\ncurl -O https://craigahobbs.github.io/schema-markdown-doc/extra/index.html\npython3 \\\n    -c 'from model import model_types; import json; print(json.dumps(model_types))' \\\n    > model.json\n~~~\n\nTo host locally, start a local static web server:\n\n~~~ sh\npython3 -m http.server\n~~~\n\n\n## Development\n\nThis package is developed using [python-build](https://github.com/craigahobbs/python-build#readme).\nIt was started using [python-template](https://github.com/craigahobbs/python-template#readme) as follows:\n\n~~~ sh\ntemplate-specialize python-template/template/ schema-markdown/ -k package schema-markdown -k name 'Craig A. Hobbs' -k email 'craigahobbs@gmail.com' -k github 'craigahobbs' -k nomain 1\n~~~\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A schema definition and validation library",
    "version": "1.2.7",
    "project_urls": {
        "Homepage": "https://github.com/craigahobbs/schema-markdown"
    },
    "split_keywords": [
        "schema",
        " validate",
        " json"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "73ea9e3a62ec9cd2b6b59c025fefa69f9ea4231773d0e4d456002fe371ac5a69",
                "md5": "310a4ed2860bc22d29e214f95e09a486",
                "sha256": "5fd64af3374393b4617a205d8382a571445998fb2e78be495e418845cae78c63"
            },
            "downloads": -1,
            "filename": "schema_markdown-1.2.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "310a4ed2860bc22d29e214f95e09a486",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 17578,
            "upload_time": "2024-04-03T22:47:33",
            "upload_time_iso_8601": "2024-04-03T22:47:33.631839Z",
            "url": "https://files.pythonhosted.org/packages/73/ea/9e3a62ec9cd2b6b59c025fefa69f9ea4231773d0e4d456002fe371ac5a69/schema_markdown-1.2.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5a4e838716efa189d10ab6f87c4ae197a14b71f4465b8b36712161cadb7878cc",
                "md5": "115cb063e13eae1d3ade93a33540cef2",
                "sha256": "5e229b238c1951309e55ee16342962611e052657b7e6c4c10918bbbc7140e7df"
            },
            "downloads": -1,
            "filename": "schema-markdown-1.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "115cb063e13eae1d3ade93a33540cef2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 16171,
            "upload_time": "2024-04-03T22:47:35",
            "upload_time_iso_8601": "2024-04-03T22:47:35.551506Z",
            "url": "https://files.pythonhosted.org/packages/5a/4e/838716efa189d10ab6f87c4ae197a14b71f4465b8b36712161cadb7878cc/schema-markdown-1.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-03 22:47:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "craigahobbs",
    "github_project": "schema-markdown",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "schema-markdown"
}
        
Elapsed time: 0.26915s