Skip to main content

Schema Annotations for Linked Avro Data (SALAD)

Project description

Linux Build Status Code coverage CII Best Practices

Schema Salad

Salad is a schema language for describing JSON or YAML structured linked data documents. Salad schema describes rules for preprocessing, structural validation, and hyperlink checking for documents described by a Salad schema. Salad supports rich data modeling with inheritance, template specialization, object identifiers, object references, documentation generation, code generation, and transformation to RDF. Salad provides a bridge between document and record oriented data modeling and the Semantic Web.

The Schema Salad library is Python 3.6+ only.

Usage

$ pip install schema_salad

To install from source:

git clone https://github.com/common-workflow-language/schema_salad
cd schema_salad
python3 setup.py install

Commands

Schema salad can be used as a command line tool or imported as a Python module:

$ schema-salad-tool
usage: schema-salad-tool [-h] [--rdf-serializer RDF_SERIALIZER]
                      [--print-jsonld-context | --print-rdfs | --print-avro
                      | --print-rdf | --print-pre | --print-index
                      | --print-metadata | --print-inheritance-dot
                      | --print-fieldrefs-dot | --codegen language
                      | --print-oneline]
                      [--strict | --non-strict] [--verbose | --quiet
                      | --debug]
                      [--version]
                      [schema] [document]

$ python
>>> import schema_salad

Validate a schema:

$ schema-salad-tool myschema.yml

Validate a document using a schema:

$ schema-salad-tool myschema.yml mydocument.yml

Generate HTML documentation:

$ schema-salad-tool myschema.yml > myschema.html

Get JSON-LD context:

$ schema-salad-tool --print-jsonld-context myschema.yml mydocument.yml

Convert a document to JSON-LD:

$ schema-salad-tool --print-pre myschema.yml mydocument.yml > mydocument.jsonld

Generate Python classes for loading/generating documents described by the schema:

$ schema-salad-tool --codegen=python myschema.yml > myschema.py

Display inheritance relationship between classes as a graphviz ‘dot’ file and render as SVG:

$ schema-salad-tool --print-inheritance-dot myschema.yml | dot -Tsvg > myschema.svg

Quick Start

Let’s say you have a ‘basket’ record that can contain items measured either by weight or by count. Here’s an example:

basket:
  - product: bananas
    price: 0.39
    per: pound
    weight: 1
  - product: cucumbers
    price: 0.79
    per: item
    count: 3

We want to validate that all the expected fields are present, the measurement is known, and that “count” cannot be a fractional value. Here is an example schema to do that:

- name: Product
  doc: |
    The base type for a product.  This is an abstract type, so it
    can't be used directly, but can be used to define other types.
  type: record
  abstract: true
  fields:
    product: string
    price: float

- name: ByWeight
  doc: |
    A product, sold by weight.  Products may be sold by pound or by
    kilogram.  Weights may be fractional.
  type: record
  extends: Product
  fields:
    per:
      type:
        type: enum
        symbols:
          - pound
          - kilogram
      jsonldPredicate: '#per'
    weight: float

- name: ByCount
  doc: |
    A product, sold by count.  The count must be a integer value.
  type: record
  extends: Product
  fields:
    per:
      type:
        type: enum
        symbols:
          - item
      jsonldPredicate: '#per'
    count: int

- name: Basket
  doc: |
    A basket of products.  The 'documentRoot' field indicates it is a
    valid starting point for a document.  The 'basket' field will
    validate subtypes of 'Product' (ByWeight and ByCount).
  type: record
  documentRoot: true
  fields:
    basket:
      type:
        type: array
        items: Product

You can check the schema and document in schema_salad/tests/basket_schema.yml and schema_salad/tests/basket.yml:

$ schema-salad-tool basket_schema.yml basket.yml
Document `basket.yml` is valid

Documentation

See the specification and the metaschema (salad schema for itself). For an example application of Schema Salad see the Common Workflow Language.

Rationale

The JSON data model is an popular way to represent structured data. It is attractive because of it’s relative simplicity and is a natural fit with the standard types of many programming languages. However, this simplicity comes at the cost that basic JSON lacks expressive features useful for working with complex data structures and document formats, such as schemas, object references, and namespaces.

JSON-LD is a W3C standard providing a way to describe how to interpret a JSON document as Linked Data by means of a “context”. JSON-LD provides a powerful solution for representing object references and namespaces in JSON based on standard web URIs, but is not itself a schema language. Without a schema providing a well defined structure, it is difficult to process an arbitrary JSON-LD document as idiomatic JSON because there are many ways to express the same data that are logically equivalent but structurally distinct.

Several schema languages exist for describing and validating JSON data, such as JSON Schema and Apache Avro data serialization system, however none understand linked data. As a result, to fully take advantage of JSON-LD to build the next generation of linked data applications, one must maintain separate JSON schema, JSON-LD context, RDF schema, and human documentation, despite significant overlap of content and obvious need for these documents to stay synchronized.

Schema Salad is designed to address this gap. It provides a schema language and processing rules for describing structured JSON content permitting URI resolution and strict document validation. The schema language supports linked data through annotations that describe the linked data interpretation of the content, enables generation of JSON-LD context and RDF schema, and production of RDF triples by applying the JSON-LD context. The schema language also provides for robust support of inline documentation.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

schema-salad-8.2.20211014150008.tar.gz (455.9 kB view details)

Uploaded Source

Built Distributions

schema_salad-8.2.20211014150008-py3-none-any.whl (477.1 kB view details)

Uploaded Python 3

schema_salad-8.2.20211014150008-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

schema_salad-8.2.20211014150008-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

schema_salad-8.2.20211014150008-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

schema_salad-8.2.20211014150008-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

schema_salad-8.2.20211014150008-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

schema_salad-8.2.20211014150008-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

schema_salad-8.2.20211014150008-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

schema_salad-8.2.20211014150008-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

schema_salad-8.2.20211014150008-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

schema_salad-8.2.20211014150008-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

schema_salad-8.2.20211014150008-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

schema_salad-8.2.20211014150008-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

schema_salad-8.2.20211014150008-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.1 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

schema_salad-8.2.20211014150008-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

schema_salad-8.2.20211014150008-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

File details

Details for the file schema-salad-8.2.20211014150008.tar.gz.

File metadata

  • Download URL: schema-salad-8.2.20211014150008.tar.gz
  • Upload date:
  • Size: 455.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for schema-salad-8.2.20211014150008.tar.gz
Algorithm Hash digest
SHA256 9d6340138c262530295a7927c6b75a2407a2d54b361b2f4437dd3be4a73aa2a1
MD5 c5743ffdee198f6094dec4532d67692a
BLAKE2b-256 46044bd93283487336106b67091388d603da5434bacb63f220c466b0f8b2709c

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-py3-none-any.whl.

File metadata

  • Download URL: schema_salad-8.2.20211014150008-py3-none-any.whl
  • Upload date:
  • Size: 477.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for schema_salad-8.2.20211014150008-py3-none-any.whl
Algorithm Hash digest
SHA256 d66e9ba3d9853ba067a6c9e5757bbee259443c6a7bab2a249dda2985e168e934
MD5 941b8fc05cef8eff522938f9643ab86c
BLAKE2b-256 c2c35142deba30cefc21f962d802343c4658323675375c8df259d03f682f5eb8

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f03df1e33312aa14435b34ec7f21b210447e530bded3390dc25dad13708f8063
MD5 e01e16edc951f33e3e48f163304950ca
BLAKE2b-256 90f2e757e4c30fc235771a05aa506618dcf7935528931760c0b22a5f56c46c98

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 56c384e405adbf6b66192526ab277b6da4921ceab579a7a197d0500088549790
MD5 ee97bb09189985ab90cdbacab6cdb2f0
BLAKE2b-256 34027c2e6d51ff41c1634c135b9c3fedb416856b6529611f3a45e6bed07ec31a

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 eeaacc26dbc7c49208574dfdcc9e6c18429e51d6d084f1b14e39f065ef8d715e
MD5 0a2b785cdd1f86e278b28b3d4aaab852
BLAKE2b-256 69dd77e43f3fd283ff5fa075782c32ff0b6807f2fd045bc5574c4d0dda726d4e

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f644b77e11221f352647876bfa2c8a8c9c893b3be59df445dccbccc6f59417aa
MD5 c4dfe0907e6972aebe90a8d963306cee
BLAKE2b-256 fd38232942f4ea1226fd39142913d22c2dfbe42efb321ee71bf69cd8a922a9b2

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 818e5aee75649c458ccb38e186b69b6a07b81c4dc5f4fcdd2bb13ae6a6a23e55
MD5 435ce4cded71cad71325045f76676c03
BLAKE2b-256 bd6e54f998b879555b0660e3936b95817e6de0bee42cdddc3ae6169d7a1ae57c

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f92eec46ae8349d388c581b0930677d9e3644f740ff73b185a2f298d5418b98e
MD5 5ac0a5f1305f8c4a01aa93b716117ccb
BLAKE2b-256 cf98a746dacce31d7acd7e78fc5ea9eae4243aafeff9ebb50def77de7ddd4fd5

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 425edafe606409eb5fadaf9f2a586482db40f7a3c5ba42b35f31aec08671a914
MD5 7703ec2b722118255c0366feb75d5327
BLAKE2b-256 8eb0faa15897af227d7ceb59a910f439ce2a63b7794d3258e5161715591da23f

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 03871ca767183a4619ec4edc9c2b46be0b57b0ceb9c7accca2b41a9350655335
MD5 e966d67f5b76ac5efafad9c8362b7928
BLAKE2b-256 16d91f0768eb4e3eb4443da94498d09e22f5c629fd36a315efe712c7631566c2

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f1faf4f35d3787c4a43b42b907e82063a206ce65811546fc8a1f54f124f823f0
MD5 7254d4cd559790c653ecd267c9a932fd
BLAKE2b-256 6e2df1a495c99d4a9da30cf8e61c0a6cbc2cc6680667c7b512ffced242123bc4

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a00bf223db321b69b92e36ddbf935af1bad59d983686904b5c6e68b3a4f3d13f
MD5 dcf26d325bc5bff5a2ffc8df24bfb02f
BLAKE2b-256 25abdc920abd1445ea18dafb5b88f2298a3c3175a9c6e1bdc3bcd915d1ad70df

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d971059386833d1003af6c78967e15154b3ef9a8d4abf2ef988dd74a0f8b0488
MD5 926a4cf0b68930d60b14d1e673eea394
BLAKE2b-256 6a22173e9796b9d19e7a34992c3b83fe9f7f14337a0fdb64849d1fca2b32c6f3

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 109aa065bc172e4a9741cc6e666cad82be7124143cbf2d1d0e58be1d764a138b
MD5 dd1de6a63643c850ca9c1e888b5476a6
BLAKE2b-256 f42dc1d49ff295ab2d22113f4f4e99d7b3a690660824e2353b6e3ee93e4dbd67

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2c2c6d44b4d154620893192998b67c9b93464b33ba209020a3895c2805351165
MD5 cb6267d1f7bc497b676e16b557cb2200
BLAKE2b-256 1a944d74061cd073fd38374cba3d769d5c46bdeee14e6469da14b7e2c57f0a65

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7da19901458cb1ff1409d8eab3e13b0f9d3ae6aa55d38ec1ae0210c20128966e
MD5 45b1aa5c892a5977be59c20b89d0b07d
BLAKE2b-256 5d6be20ba8a2b14a7dc6893f8a333377bfda7080140533c694fa52edb397a1f9

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20211014150008-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for schema_salad-8.2.20211014150008-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 57b839a77e224314a688302a200363c6d634a8c3399c41d54329422515782403
MD5 f7df704580cb1976f150786a308b3bb7
BLAKE2b-256 9e3abc6e282bea12d49700012d84ec7751b5b60e74a5079cd9205c079f8c1d44

See more details on using hashes here.

Supported by

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