Skip to main content

Schema Annotations for Linked Avro Data (SALAD)

Project description

Linux Build Status Code coverage Documentation Status 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.8+ only.

Installation

pip3 install schema_salad

If you intend to use the schema-salad-tool –codegen=python feature, please include the [pycodegen] extra:

pip3 install schema_salad[pycodegen]

To install from source:

git clone https://github.com/common-workflow-language/schema_salad
cd schema_salad
pip3 install .
# or pip3 install .[pycodegen] if needed

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] [--skip-schemas]
                      [--strict-foreign-properties] [--print-jsonld-context]
                      [--print-rdfs] [--print-avro] [--print-rdf] [--print-pre]
                      [--print-index] [--print-metadata] [--print-inheritance-dot]
                      [--print-fieldrefs-dot] [--codegen language] [--codegen-target CODEGEN_TARGET]
                      [--codegen-examples directory] [--codegen-package dotted.package]
                      [--codegen-copyright copyright_string] [--print-oneline]
                      [--print-doc] [--strict | --non-strict]
                      [--verbose | --quiet | --debug] [--only ONLY] [--redirect REDIRECT]
                      [--brand BRAND] [--brandlink BRANDLINK] [--brandstyle BRANDSTYLE]
                      [--brandinverse] [--primtype PRIMTYPE] [--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 --print-doc myschema.yml > myschema.html
$ # or
$ schema-salad-doc 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 (Requires the [pycodegen] extra):

$ 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

Codegen Examples

These are helpful to see how to use the output of schema-salad-tool –codegen in different languages for loading and/or creating/editing/saving objects, using the CWL v1.2 schema as an example.

Language

Repository

Serialization Example | Deserialization Example

Python

https://github.com/common-workflow-language/cwl-utils/

create_cwl_from_objects.py

load_document()

Java

https://github.com/common-workflow-language/cwljava/

(Not yet implemented)

PackedWorkflowClassTest.java

TypeScript

https://github.com/common-workflow-lab/cwl-ts-auto

Creating, editing, and saving CWL docs with TypeScript

Loading CWL documents with TypeScript

.Net

https://github.com/common-workflow-lab/CWLDotNet

Creating, editing, and saving CWL docs with .Net

Loading CWL documents with .Net

C++

https://github.com/common-workflow-lab/cwl-cpp-auto

cwl_output_example.cpp

cwl_input_example.cpp

D

https://github.com/common-workflow-lab/cwl-d-auto

How to use

How to use

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

Uploaded Source

Built Distributions

schema_salad-8.4.20231024070348-py3-none-any.whl (615.5 kB view details)

Uploaded Python 3

schema_salad-8.4.20231024070348-cp311-cp311-musllinux_1_1_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

schema_salad-8.4.20231024070348-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

schema_salad-8.4.20231024070348-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.28+ ARM64

schema_salad-8.4.20231024070348-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.24+ ARM64

schema_salad-8.4.20231024070348-cp310-cp310-musllinux_1_1_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

schema_salad-8.4.20231024070348-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

schema_salad-8.4.20231024070348-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.28+ ARM64

schema_salad-8.4.20231024070348-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.24+ ARM64

schema_salad-8.4.20231024070348-cp39-cp39-musllinux_1_1_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

schema_salad-8.4.20231024070348-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

schema_salad-8.4.20231024070348-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.28+ ARM64

schema_salad-8.4.20231024070348-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.24+ ARM64

schema_salad-8.4.20231024070348-cp38-cp38-musllinux_1_1_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

schema_salad-8.4.20231024070348-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

schema_salad-8.4.20231024070348-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.28+ ARM64

schema_salad-8.4.20231024070348-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.24+ ARM64

File details

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

File metadata

File hashes

Hashes for schema-salad-8.4.20231024070348.tar.gz
Algorithm Hash digest
SHA256 a7cdd70f75a67f08ca5068cc4c4b6b266358953435d8519d6ae22458a0c53984
MD5 e47650aa0e2ab2ceb826cba883657385
BLAKE2b-256 6820fbb299fa0052784a2239b1ab4221f2518ab78d4f7030a48e951c9f188169

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-py3-none-any.whl
Algorithm Hash digest
SHA256 4b8887c7bc4a6b98d4fa9f77b8881b79ba7e66acbfd3029d9e14e76be75f6530
MD5 21209148179e87234d6fe049944fc686
BLAKE2b-256 e16c4c65f94d1a0bbfa1a9113dfe83e6f7a92a651af38b19f3e9c8eca85f175c

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp311-cp311-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 a653d95a4da422d7ed1ee5c2d7b6cdc10e1a76569db8d69a609b917dfc1be477
MD5 eafd234d011b2028408ddcddfcd1721e
BLAKE2b-256 c0c0a6f2951d90b5f93ddd744dbe2e5423623c249598151da0df387b3fdb112d

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2949fbbb387fa681a217695178e37a842dc7cdb517ceb12b261ca1e78428d419
MD5 8c6183e98c10d424376c343c4e663fa9
BLAKE2b-256 ae979dea5c8fc78d0639514bdf72dc53feaa63da7628de660b2e929ee45f20c8

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 395f628d7c557f9834e481260ea8fa72c77e88c2be86fe947b0e1f7e2e174370
MD5 7a84160092cc44619f6b311d0f24e545
BLAKE2b-256 bf3e394623557f6f0c8586fd1d13a06f430f83cfd01b2c02ad20472fae7130c1

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 137a5263f8e00aa267c45bd39b9765eda5fd6fa46ef5632737d6bb1d73d9671b
MD5 a94409ba9105442da4d89667445d8d3a
BLAKE2b-256 88e3cd4dca7655a7b0ecd260d2a727b8fa719dfa6c5abba1b091c17ca15a5836

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp310-cp310-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 06db542a956ea36afc8b441502bfe63cdcef5d8bb387e5269b2244f1e7dcb7d8
MD5 3af498039f7af0725dce1d7f452285a2
BLAKE2b-256 b0ebfa83d0a168e17b78aee33a1bc1cf1f2a7798f3b918109f4c2bed2923573e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cba554b693cc1858a7f7865e706efd728c8c5cbfc87cf242e141ba7d5941d494
MD5 4d491f3e6e16eed80557941403956392
BLAKE2b-256 fce8d07eede88b761f2aff317aae172461cf48ad50e01102116cc544f5239f83

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 77264c362c38b74ad7048da573825464e1e86cc3e634b567fee0b164dd2c9797
MD5 5e60cdae9c3f2a555877a6a0424c918d
BLAKE2b-256 4a2538ddb7d806c6584593d68802503bdde7bd5dba07ada18b3df897a4fe8156

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 b9c9b8576bcaaf8fcfbead0845c220bcb9646b3f143a4708ffe8f3c2cbc7252a
MD5 2f40c408cd432e11bd5dcf5295b402ac
BLAKE2b-256 67a27fd54d0c2ca68f347d8ea7b3d8fb5792ccec25ded7dfdeffed892d729f9d

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp39-cp39-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 9110fd06dfc524927f97e248bfb1a8700b7f787732aef23b491103bfed2a55ee
MD5 552eaf0427ee53f8282b277ff5e4da6d
BLAKE2b-256 ac886d2a13daef15df81a773fcbd07b72385a1de81e18d75b4fb3ae1f2a406e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ce81a09c8ab755286193eb8a620246c1187042535b0a12c2892f8ad5f5e1f953
MD5 b64f6cf0e6101de1da77d042d60618ab
BLAKE2b-256 f6735e4353a38cdff4477ad23e5d3a9db592eb9bb7653e6447756dc54097d41d

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c422abcb0ad3e3056ac9b0b676287fadf243b3367d1fa11ff8a345e57cd199f2
MD5 87353fed3f3b0e5364955fe2171a26b3
BLAKE2b-256 210b90d47ffa5f673d5c5b677e9c174a44c69fa3f212e7eb98e611c01f1ececf

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 cf56650dc78198a59cf8d8f1fa89f8c2576eaa3e72c70d63b61cdde41303ca44
MD5 312d51360a561aef874d7fff3eff63f2
BLAKE2b-256 56f371b9ca5d423ec360c5699b07b49e93a84285ce6287ab604726e916377c05

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp38-cp38-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 a7a4173b41d4842ac6ce0ef9f9e9df093a1ccea9e0f357d6c467fe373c01b23c
MD5 f8399d748755ef723466612d96f1d277
BLAKE2b-256 467cc51e64697e9ca77bf8074eac052eadb2513b28c69ede11d55306bfc60431

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6a37dcbda10370fd57d0566313a4896f7bc2f49f6ae554f765184934093acf8a
MD5 e4004a4d0406e450ecd3428a79a2bc1a
BLAKE2b-256 b15cc89966ddb13fd20110b1d28ce32a71e2a718ebd6fb691f02ef8cedc1a9d3

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 548163bc9a9cfb7bdf3fdc6566a4c304d0ae0fb8ce10292905a2165f2f2c0a1b
MD5 6cb65541cd18a19cbfc0358e1f495f78
BLAKE2b-256 1b242b8e0ff6a02512dd6581fd242f97838b0c240c9ce9ee1413cb59bed17047

See more details on using hashes here.

File details

Details for the file schema_salad-8.4.20231024070348-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for schema_salad-8.4.20231024070348-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 874a47e2ffa942baad8c07abb4231de2cfb8b4dcc704b0dd1669b5ade791180d
MD5 d1fd0c53a93f5d12b1dc5635b534061e
BLAKE2b-256 876bef00d45c4286dc34a8ec97f871f885f840711ea5e8127ba118447a10cb55

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