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.20210918131710.tar.gz (454.6 kB view details)

Uploaded Source

Built Distributions

schema_salad-8.2.20210918131710-py3-none-any.whl (476.4 kB view details)

Uploaded Python 3

schema_salad-8.2.20210918131710-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.20210918131710-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.20210918131710-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.20210918131710-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.20210918131710-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

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

schema_salad-8.2.20210918131710-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.20210918131710-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.20210918131710-cp37-cp37m-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.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

schema_salad-8.2.20210918131710-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.20210918131710-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.20210918131710-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.20210918131710-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.20210918131710.tar.gz.

File metadata

  • Download URL: schema-salad-8.2.20210918131710.tar.gz
  • Upload date:
  • Size: 454.6 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.2 CPython/3.9.7

File hashes

Hashes for schema-salad-8.2.20210918131710.tar.gz
Algorithm Hash digest
SHA256 464180407f49a3533cd5a5bc7db9254769bc77595ea00562bbe4a50493f7f445
MD5 a5866659ca0d1ba796373f3b9f37b5c0
BLAKE2b-256 f8a6b17b537a857b35124da515f5844ee5c34aafcf29d8bc5b6ee29cbb4ba7e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: schema_salad-8.2.20210918131710-py3-none-any.whl
  • Upload date:
  • Size: 476.4 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.2 CPython/3.9.7

File hashes

Hashes for schema_salad-8.2.20210918131710-py3-none-any.whl
Algorithm Hash digest
SHA256 c6eab5fd4c0fa5aabf95d5b7ee093e53bc2197dcf58d1d4967023cf3b3bae4e5
MD5 b913e5b2736687a057dd39b36f40f253
BLAKE2b-256 1da29df0dfb7b19a8d788556f9d99d84d373f0f60fa595ad4466d64a9ea7367a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for schema_salad-8.2.20210918131710-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7edd240b64d3d26bd5276c709e47f848612a5bd37c964962ecdf20edbd8a75be
MD5 14fcd763cd3ff995a3fedb8970a97ac5
BLAKE2b-256 7d69c9b45d0b8ef5e6271212c137d867bd57fc30bc5d915f2213cf5a3a50957b

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20210918131710-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.20210918131710-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ca2f4c0a97df7ddd24e9985a53850863ef1554be8cc4a413e427a8ae2d293a64
MD5 608f75150631b1e2237316504c01a231
BLAKE2b-256 50c3f937c37a478b3cfe58f9bdc4aad80b6961561cdfa85699118f838cffefd0

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20210918131710-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.20210918131710-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 4f7cfe19a7864cb0fb3bbf367a8b430752b9d65c9b87e25eaee2773242a73f28
MD5 da5d89c0cc031d620b528f9173f0e704
BLAKE2b-256 73f856ae8ca45e388cf979378fb4c930767885832f20d186856625b6de22778e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for schema_salad-8.2.20210918131710-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 19feb2e2168979c56a92a44038d33bbe3cc70d62b585b70049fcddcfd76ad9ad
MD5 c675c65d2e32725dc900cdffac61d67d
BLAKE2b-256 30c535104ad323ebff3e86ad3f10cd6b804b07413d6f84e2f3fe96c592ed211a

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20210918131710-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.20210918131710-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 58a8bfec05abdaf96be82306a6107789c9fdef79bf55c8d397d02c285f9beef3
MD5 99bf40ad077d1adab9fa53a5cbe025e4
BLAKE2b-256 f6a7fcca17e104b237ed7c70c83a13a62a1e811a807d67553c5f881251ee6a2a

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20210918131710-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.20210918131710-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b56a42df3bcfa8cadc88c8b6898ca2691602e702bd1ce7acb670d9f2a2d0001e
MD5 8df2a880748fae02ef52de596f774efd
BLAKE2b-256 16ab7c44fc142de79461cd3bacdc17f4feb5cda7bf6289878ef6cb666d659f11

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for schema_salad-8.2.20210918131710-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 772cf819a3b818bcd9e4dcf480935fd9802895374dea28368d3d0c308b8be15b
MD5 d04bfd14ed6db6b0e277cb431965991e
BLAKE2b-256 4742a80d65278ebe05faa82510af64f6f62dcee429631f13e2f36cb422e668b4

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20210918131710-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.20210918131710-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bd70da20d103ca4495a38f47ec2b8bf4fa8d6160676a073661f649efe8ad48e4
MD5 c3f1354c0210e3df776723bf8980ad19
BLAKE2b-256 160eb3f4c883caa89d44787e8bf60fe91eb3abd730dd661dcafe7e2544d482b7

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20210918131710-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.20210918131710-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3df32abede39bd56cd27800216f199e6c37eeedf42d31aa9b5b776f9a5e7a86b
MD5 4dbed38ca913cde65086cdf6d8c9cc62
BLAKE2b-256 5bf8b6030c15f0f866bc0a9faed495a574e5c47a9b6f59ab2dfc4ec8b82df52b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for schema_salad-8.2.20210918131710-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0986b0d2a774fd880c4230fcca1776136a3c7ecc0e238eb92731223a2240734d
MD5 6b8f879c0b0c14e1f2aab832f4688664
BLAKE2b-256 1c606dad7b38369d77d0e14d8922e2cca14a7c90be5d92cd2c7d0f1bad4d9e95

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20210918131710-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.20210918131710-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc73f284a930e352e131c633c71df5a75ecd525538c8bb4310befdfbe31e6a3c
MD5 50a87f2d8047f5508c437fd7b42d5efb
BLAKE2b-256 5d17c9b22973f9ab892fd003fc938aba490e56ccf5d22893812a0871c32f75ec

See more details on using hashes here.

File details

Details for the file schema_salad-8.2.20210918131710-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.20210918131710-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 343f06000bc2ce66f9812b279f3455a809d827085db00c89457cca3b54e988dd
MD5 75118fabb3226ccab3a18bd8ab97b8ce
BLAKE2b-256 8e02d896bcd2ad09d38bb7bdf0a7b1d1cf0691c4d2f2f2c3f53f7f673f7106b7

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