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.

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 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

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

Uploaded Source

Built Distributions

schema_salad-8.2.20211015115235-py3-none-any.whl (477.3 kB view details)

Uploaded Python 3

schema_salad-8.2.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235-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.20211015115235.tar.gz.

File metadata

  • Download URL: schema-salad-8.2.20211015115235.tar.gz
  • Upload date:
  • Size: 456.4 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.9.7

File hashes

Hashes for schema-salad-8.2.20211015115235.tar.gz
Algorithm Hash digest
SHA256 270c4e90e19b1a02cef7d72689c6a19e2e56489f3863253b53f30eddb11cce17
MD5 5fd384d30af6abf26af6adfcae504ef1
BLAKE2b-256 5c07c7c609a8dd8630d00622ea2454aa55dbc05fd692f70d931cf8e5c39d0786

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: schema_salad-8.2.20211015115235-py3-none-any.whl
  • Upload date:
  • Size: 477.3 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.9.7

File hashes

Hashes for schema_salad-8.2.20211015115235-py3-none-any.whl
Algorithm Hash digest
SHA256 4512b95ea4e30055714eae121b3f846ec434b21905d196f2a82e7c36a5564f88
MD5 08d77ed875a0c4a7991c56eae014895e
BLAKE2b-256 05c0f138a78d0dc81fc061db54b171de61dd20fe980b131f35bc050ae287d7f2

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for schema_salad-8.2.20211015115235-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 05c5d6714d733c2e447c3a6331bed5f4c49c0ef41c65c6facdfdd3a52de89695
MD5 eec401ec4aaa9f2b8bb401fba468cb46
BLAKE2b-256 dcc01389ebe5041f9f006384d0f9ab03f49f4b996ee5372559746892eb5a39ce

See more details on using hashes here.

Provenance

File details

Details for the file schema_salad-8.2.20211015115235-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.20211015115235-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fa48d923d03b38bc09ecfedbda1d012b6677a81b4cdf3964e74f600097722a90
MD5 28a16937450448d551ca6fa7412a74f9
BLAKE2b-256 05eff14a7d3fe850d0886dc643eea80e2f33830d0b1d7e626aeda01a5adeac83

See more details on using hashes here.

Provenance

File details

Details for the file schema_salad-8.2.20211015115235-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.20211015115235-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 96a4aa5c374912add81a8ba4ed2923c9ef06346c22a4af2cb131416b63147a46
MD5 17a478b18a4e9db3cd5f11ab9a9b6b15
BLAKE2b-256 85f01b4dc7f427c787448a01042b145d770941e794f8a3b74fda272f4400b5bb

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for schema_salad-8.2.20211015115235-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f13171e5bbe98adabf89a782a4a73554e5cb6b23fef9e7986f09e6d11549093e
MD5 b5ce1331d9e93acd375a32f6ac600245
BLAKE2b-256 70ba23abfbfc427c1387646a57f7b53ddb2c4ea14d4db58c8e27d3ffe340492c

See more details on using hashes here.

Provenance

File details

Details for the file schema_salad-8.2.20211015115235-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.20211015115235-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 11d2a937285302d960ada64b2077d7cdfada9cacfba7ca3d6adb71dec7709bc3
MD5 edc427cc0037ee6e9f7f5c56d1a323c7
BLAKE2b-256 743f726f21e530903ff2b67fbe9f1c3a5ea1a1d5696ad1e1b676e03df5ffbd99

See more details on using hashes here.

Provenance

File details

Details for the file schema_salad-8.2.20211015115235-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.20211015115235-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 cee8b7815b42736df6d382b859580f89e32cc57d5da52a186dd279629968c64b
MD5 f380e261422aa5a41ff71efe83facc69
BLAKE2b-256 eca70db17a0f69d51afc8bd5a0f8244a00abe87164e848dd786ea137e64898d5

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for schema_salad-8.2.20211015115235-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 67c45130184426ffeea4d5d5c806a3adc1ff1ee511276200eeb09e7fc402c6ae
MD5 4d039117e820635612c47bc71c4f97fc
BLAKE2b-256 88e7206e6736e2da18d0740ff964b2fb3b89fc75abd6e79f91203c8543fb28b8

See more details on using hashes here.

Provenance

File details

Details for the file schema_salad-8.2.20211015115235-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.20211015115235-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 07a1bc2f5e8448c80e78eb189a9087518c5719ad9c169b25717d4e141477482a
MD5 f0554bd78a45417e54335ce4f4b4074b
BLAKE2b-256 876d37530c6cd7c262529fcde79503a1944c57598f6109b9643bcc15ef3e515b

See more details on using hashes here.

Provenance

File details

Details for the file schema_salad-8.2.20211015115235-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.20211015115235-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 96ef79137ff1334d119434726c1290ee903a5c77e778b7b48dfc85f0f56ca183
MD5 56e3a8aad0547ef1ca76b78378089c73
BLAKE2b-256 7c95c13ffd22150e80b193925dd6cab309e2cc6156e665845dd07473bb3c1b0b

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for schema_salad-8.2.20211015115235-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 70a51289f1ebeaf7ed1d5283e57b28ab749158564e326da5d175fbc86444e607
MD5 6399fcbbe8825bfcc64cc293787de33b
BLAKE2b-256 ebb2d6054ee9ff5134ef98215d73632f425668229c08097da578e5ba6beea95a

See more details on using hashes here.

Provenance

File details

Details for the file schema_salad-8.2.20211015115235-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.20211015115235-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 81027a74ca9f3a60fd8493c33dc9d1c75fb59f16410a0cee40f69192f6d4bf4a
MD5 f13b05cc9814b112b0ba28edf900a7a6
BLAKE2b-256 1bb3bf17e1c114a64b2d2a4851a59262e7e387bdfd76a9597c33fb7bc8a0cb5d

See more details on using hashes here.

Provenance

File details

Details for the file schema_salad-8.2.20211015115235-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.20211015115235-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f6c511f6c5bfc6731fa93b8276a9b9b031d1957470308c702b71b8a9ac046d3c
MD5 bb7912ca745b0b69813ab26f9902f2d9
BLAKE2b-256 1b942fe50347ee08ce9d22e4fb3a41f0665456c17b51ed92527327246557f433

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for schema_salad-8.2.20211015115235-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2a54e90e772341261c012d6efc4393e7ae5c35ffffc87df5a8063399679b429f
MD5 8e4c41f6e7c97c99edb1a555ec0e867e
BLAKE2b-256 548c7a438f514a974ecb2c2d196ab6a20f7a6ea27c56aac1e2412b747b3c7bad

See more details on using hashes here.

Provenance

File details

Details for the file schema_salad-8.2.20211015115235-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.20211015115235-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ee69ce31d05fe5a881352d963756e7f0bf272502e50e7d88daffad7634cebbb0
MD5 15590c09f565063506fd1e5fbad48cff
BLAKE2b-256 c9516907afc4d13e6fcfafd6e2a2a97e33335ecf4d8c830abf40e0c8e2300b1e

See more details on using hashes here.

Provenance

File details

Details for the file schema_salad-8.2.20211015115235-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.20211015115235-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3278dae8f86f99e44fed883c295ffc84716cfdd9d9ae96640fa9b9b1c27a6dfc
MD5 19409b51b4099e6f6f29e7d571e61262
BLAKE2b-256 aeeafb779196d50fcf06f8cc03ba07f31f62bb260b1a5e1dda1942fcadc5afb3

See more details on using hashes here.

Provenance

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