singer_sdk.singerlib.schema.Schema

class singer_sdk.singerlib.schema.Schema[source]

Object model for JSON Schema.

Tap and Target authors may find this to be more convenient than working directly with JSON Schema data structures.

This is based on, and overwrites https://github.com/transferwise/pipelinewise-singer-python/blob/master/singer/schema.py. This is because we wanted to expand it with extra STANDARD_KEYS.

classmethod from_dict(data, **schema_defaults)[source]

Initialize a Schema object based on the JSON Schema structure.

Parameters:
  • data (dict) – The JSON Schema structure.

  • schema_defaults (Any) – Default values for the schema.

Returns:

The initialized Schema object.

Return type:

Schema

Example

>>> data = {
...     "$id": "https://example.com/person.schema.json",
...     "$schema": "http://json-schema.org/draft/2020-12/schema",
...     "title": "Person",
...     "type": "object",
...     "properties": {
...         "firstName": {
...             "type": "string",
...             "description": "The person's first name.",
...         },
...         "lastName": {
...             "type": "string",
...             "description": "The person's last name.",
...         },
...         "age": {
...             "description": "Age in years which must be equal to or greater than zero.",
...             "type": "integer",
...             "minimum": 0,
...             "x-sql-datatype": "smallint",
...         },
...         "deprecatedField": {
...             "type": "string",
...             "deprecated": True,
...         },
...         "price": {
...             "oneOf": [
...                 {"type": "number", "deprecated": True},
...                 {"type": "null"},
...             ],
...         },
...     },
...     "required": ["firstName", "lastName"],
... }
>>> schema = Schema.from_dict(data)
>>> schema.schema
'http://json-schema.org/draft/2020-12/schema'
>>> schema.title
'Person'
>>> schema.properties["firstName"].description
"The person's first name."
>>> schema.properties["age"].minimum
0
>>> schema.properties["age"].x_sql_datatype
'smallint'
>>> schema.properties["deprecatedField"].deprecated
True
>>> schema.properties["price"].oneOf[0]["deprecated"]
True
__init__(id=None, schema=None, type=None, default=None, properties=None, items=None, description=None, minimum=None, maximum=None, exclusiveMinimum=None, exclusiveMaximum=None, multipleOf=None, maxLength=None, minLength=None, anyOf=None, allOf=None, format=None, additionalProperties=None, patternProperties=None, required=None, enum=None, title=None, pattern=None, contentMediaType=None, contentEncoding=None, x_sql_datatype=None, x_sql_datatype_properties=None, deprecated=None, oneOf=None)[source]
Parameters:
  • id (str | None)

  • schema (str | None)

  • type (str | list[str] | None)

  • default (Any | None)

  • properties (dict | None)

  • items (Any | None)

  • description (str | None)

  • minimum (float | None)

  • maximum (float | None)

  • exclusiveMinimum (float | None)

  • exclusiveMaximum (float | None)

  • multipleOf (float | None)

  • maxLength (int | None)

  • minLength (int | None)

  • anyOf (Any | None)

  • allOf (Any | None)

  • format (str | None)

  • additionalProperties (Any | None)

  • patternProperties (Any | None)

  • required (list[str] | None)

  • enum (list[Any] | None)

  • title (str | None)

  • pattern (str | None)

  • contentMediaType (str | None)

  • contentEncoding (str | None)

  • x_sql_datatype (str | None)

  • x_sql_datatype_properties (dict[str, Any] | None)

  • deprecated (bool | None)

  • oneOf (Any | None)

Return type:

None

to_dict()[source]

Return the raw JSON Schema as a (possibly nested) dict.

Returns:

The raw JSON Schema as a (possibly nested) dict.

Return type:

dict[str, Any]