Skip to main content

Programmatically define TetraScience Intermediate Data Schema (IDS).

Project description

Welcome to ts-ids-core's documentation!

ts-ids-core provides a programmatic way of defining TetraScience Intermediate Data Schema (IDS). An IDS defined using the ts-ids-core framework can be exported to IDS JSON (jsonschema v7) and is thus compatible with the Tetra Data Platform (TDP).

Install

pip install ts-ids-core

Quickstart

To define your own Programmatic IDS (PIDS), inherit from classes in ts_ids_core.schema; ts_ids_core.schema.IdsSchema contains the IDS metadata fields, e.g. IDS version, and should be the parent class to your top-level IDS class.

In addition to defining IDS metadata fields, in the example below we add a field named "samples" that conforms to the predefined component, Schema.

from typing import List

from ts_ids_core.schema import IdsSchema, Sample
from ts_ids_core.base.ids_field import IdsField
from ts_ids_core.base.ids_element import SchemaExtraMetadataType


class DemoIdsSchema(IdsSchema):
    #: The type hint `SchemaExtraMetadataType` is required.
    schema_extra_metadata: SchemaExtraMetadataType = {
        "$id": "https://ids.tetrascience.com/my_namespace/demo_ids/v1.0.0/schema.json",
        "$schema": "http://json-schema.org/draft-07/schema#",
    }

    ids_namespace: str = IdsField('my_namespace', const=True)
    ids_type: str = IdsField('my_unique_ids_name', const=True)
    ids_version: str = IdsField('v1.0.0', const=True)

    samples: List[Sample] = IdsField()

That's it! You just defined an IDS class. To export the IDS to JSON Schema used by the TDP, run the following code:

ids_json_schema = DemoIdsSchema.schema_json(indent=2)

When printed, output will look like this:

Expand to show output
{
  "$id": "https://ids.tetrascience.com/my_namespace/my_unique_ids_name/v1.0.0/schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "Top-level schema.",
  "type": "object",
  "properties": {
    "ids_type": {
      "const": "my_unique_ids_name",
      "type": "string"
    },
    "ids_version": {
      "const": "v1.0.0",
      "type": "string"
    },
    "@idsConventionVersion": {
      "const": "v1.0.0",
      "type": "string"
    },
    "ids_namespace": {
      "const": "my_namespace",
      "type": "string"
    },
    "samples": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/Sample"
      }
    }
  },
  "additionalProperties": false,
  "definitions": {
    "Batch": {
      "type": "object",
      "properties": {
        "id": {
          "type": [
            "string",
            "null"
          ]
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "barcode": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "additionalProperties": false
    },
    "Set": {
      "type": "object",
      "properties": {
        "id": {
          "type": [
            "string",
            "null"
          ]
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "additionalProperties": false
    },
    "Lot": {
      "type": "object",
      "properties": {
        "id": {
          "type": [
            "string",
            "null"
          ]
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "additionalProperties": false
    },
    "Holder": {
      "type": "object",
      "properties": {
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "type": [
            "string",
            "null"
          ]
        },
        "barcode": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "additionalProperties": false
    },
    "Location": {
      "type": "object",
      "properties": {
        "position": {
          "type": [
            "string",
            "null"
          ]
        },
        "row": {
          "type": [
            "number",
            "null"
          ]
        },
        "column": {
          "type": [
            "number",
            "null"
          ]
        },
        "index": {
          "type": [
            "number",
            "null"
          ]
        },
        "holder": {
          "$ref": "#/definitions/Holder"
        }
      },
      "additionalProperties": false
    },
    "Source": {
      "type": "object",
      "properties": {
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "name",
        "type"
      ],
      "additionalProperties": false
    },
    "ValueDataType": {
      "title": "ValueDataType",
      "description": "An enumeration.",
      "enum": [
        "string",
        "number",
        "boolean"
      ],
      "type": "string"
    },
    "RawSampleTime": {
      "type": "object",
      "properties": {
        "start": {
          "type": [
            "string",
            "null"
          ]
        },
        "created": {
          "type": [
            "string",
            "null"
          ]
        },
        "stop": {
          "type": [
            "string",
            "null"
          ]
        },
        "duration": {
          "type": [
            "string",
            "null"
          ]
        },
        "last_updated": {
          "type": [
            "string",
            "null"
          ]
        },
        "acquired": {
          "type": [
            "string",
            "null"
          ]
        },
        "modified": {
          "type": [
            "string",
            "null"
          ]
        },
        "lookup": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "lookup"
      ],
      "additionalProperties": false
    },
    "SampleTime": {
      "type": "object",
      "properties": {
        "start": {
          "type": [
            "string",
            "null"
          ]
        },
        "created": {
          "type": [
            "string",
            "null"
          ]
        },
        "stop": {
          "type": [
            "string",
            "null"
          ]
        },
        "duration": {
          "type": [
            "string",
            "null"
          ]
        },
        "last_updated": {
          "type": [
            "string",
            "null"
          ]
        },
        "acquired": {
          "type": [
            "string",
            "null"
          ]
        },
        "modified": {
          "type": [
            "string",
            "null"
          ]
        },
        "lookup": {
          "type": [
            "string",
            "null"
          ]
        },
        "raw": {
          "$ref": "#/definitions/RawSampleTime"
        }
      },
      "required": [
        "lookup"
      ],
      "additionalProperties": false
    },
    "Property": {
      "type": "object",
      "properties": {
        "source": {
          "$ref": "#/definitions/Source"
        },
        "name": {
          "description": "This is the property name",
          "type": "string"
        },
        "value": {
          "description": "The original string value of the parameter",
          "type": "string"
        },
        "value_data_type": {
          "description": "This is the type of the original value",
          "$ref": "#/definitions/ValueDataType"
        },
        "string_value": {
          "description": "If string_value has a value, then numerical_value,\nnumerical_value_unit, and boolean_value all have to be null",
          "type": [
            "string",
            "null"
          ]
        },
        "numerical_value": {
          "description": "If numerical_value has a value, then string_value and\nboolean_value both have to be null",
          "type": [
            "number",
            "null"
          ]
        },
        "numerical_value_unit": {
          "type": [
            "string",
            "null"
          ]
        },
        "boolean_value": {
          "description": "If boolean_value has a value, then numerical_value, numerical_value_unit,\nand string_value all have to be null",
          "type": [
            "boolean",
            "null"
          ]
        },
        "time": {
          "$ref": "#/definitions/SampleTime"
        }
      },
      "required": [
        "source",
        "name",
        "value",
        "value_data_type",
        "string_value",
        "numerical_value",
        "numerical_value_unit",
        "boolean_value",
        "time"
      ],
      "additionalProperties": false
    },
    "Label": {
      "type": "object",
      "properties": {
        "source": {
          "$ref": "#/definitions/Source"
        },
        "name": {
          "type": "string"
        },
        "value": {
          "type": "string"
        },
        "time": {
          "$ref": "#/definitions/SampleTime"
        }
      },
      "required": [
        "source",
        "name",
        "value",
        "time"
      ],
      "additionalProperties": false
    },
    "Sample": {
      "description": "See [here](https://developers.tetrascience.com/docs/ids-design-conventions-schema-templates#samples)\nfor specification of \"samples\". An instance of this class is one item in the\n`samples` array.",
      "type": "object",
      "properties": {
        "id": {
          "type": [
            "string",
            "null"
          ]
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "barcode": {
          "type": [
            "string",
            "null"
          ]
        },
        "batch": {
          "$ref": "#/definitions/Batch"
        },
        "set": {
          "$ref": "#/definitions/Set"
        },
        "lot": {
          "$ref": "#/definitions/Lot"
        },
        "location": {
          "$ref": "#/definitions/Location"
        },
        "properties": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Property"
          }
        },
        "labels": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Label"
          }
        }
      },
      "additionalProperties": false
    }
  }
}

Project details


Download files

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

Source Distribution

ts-ids-core-0.1.0a4.tar.gz (23.8 kB view hashes)

Uploaded Source

Built Distribution

ts_ids_core-0.1.0a4-py3-none-any.whl (25.3 kB view hashes)

Uploaded Python 3

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