Skip to main content

Datatables - structured data library based on schemas

homepage

Dev

  1. poetry install
  2. poetry shell
    -- Make changes --
  3. poetry run pytest
  4. poetry run black bstk_datatables
  5. poetry run flake8 bstk_datatables
    -- Commit & Push --

Install

pip install bstk-datatables

Overview

Datatables act as an intermediary between Marshmallow structures and user defined data storage structures.
It is designed to provide "just enough" sidechannel structure to facilitate building a dynamic schema, (and connecting with "other" interfaces), without losing the advantages afforded by static Marshmallow schemas.

Schema

Schema models are;

  • Schema: A collection of fields and references that make up a partial or complete entry
  • SchemaField: A basic instruction container representing a single value
  • SchemaFieldFormat: The specific instructions for how the field should be collected, represented, formatted and stored
  • SchemaValuesError: The only type of exception raised during schema validation

These schemas and fields are mapped to equivalent Marshmallow structures which provide the entry value validation mechanisms.. ref: Schema.check_values()

Entry

An Entry is a collection of field values, references data, connector references and schema links.

  • .schemata is a list of Schema.code's
  • .table_id is a link back to a Table.uuid
  • .references and .connector_references are unrestricted containers. Two containers are provided to seperate "core" references from "free-form" references.
  • .values is a dict of Field.code => value that conform to the listed schemata

Table

A Table corrals one or more Entry and shapes them towards one or more Schema.

  • .schemata is a list of Schema.code's that all entries must inherit
  • .references and .connectors are unrestricted containers. Two containers are provided to seperate "core" references from "free-form" references (and allows correlation with table entries).

Marshalling and Persistence

All core classes (and Enum) expose an export method which return a dict.
The result of an export() can be unpacked and provided to its constructor.

def test_entry_export():
    data = {
        "uuid": str(uuid4()),
        "table_id": str(uuid4()),
        "name": "Data Entry",
        "references": {"entity_uuid": str(uuid4())},
        "connector_references": {"connector1": "connector_ref"},
        "schemata": ["base"],
        "values": {"base/value1": "XG230"},
    }
    entry = Entry(**data)
    exported = export(entry)
    assert exported == data

The simplest way to handle data persistence is to encapsulate class instanciation and the export method of the relevant class into an ORM or ODM framework.
MergeSchema do not provide an export mechanism because they are not first-class citizens and are designed to work with established Schema structures.

This test provides an example of how to implement persistence with flat files.

Extras

MergedSchema

Tables and Entries support more than a single schema reference.
MergedSchema exists to facilitate mutli-schema validation and field ordering.

Provide Dict[Schema.Code: Schema] as schemata when initialising a MergedSchema and it will:

  1. Process the schema in order
  2. De-dupe fields with the same code (If a later schema includes a field with the same code as a previously loaded schema - that field will be skipped)
  3. Provide a validation mechanism for entries

Enum

Enum are used within schemas as de-duped lookups. Multiple schema fields can use the same Enum for shaping values.

Usage:

  1. Provide an Enum.code as a lookup instead of a values list when supplying SchemaFieldFormat to a schemafield.
  2. Provide the instanciated Enum to Schema.attach_lookup on a compiled Schema or MergedSchema.

or

  1. Provide an instanciated Enum as a lookup instead of a values list when supplying SchemaFieldFormat to a schemafield.

Metadata

Release files for bstk-datatables 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bstk-datatables 0.3.3
File Size Uploaded Provenance Actions
bstk_datatables-0.3.3.tar.gz 9.2 kB Without provenance Details for bstk_datatables-0.3.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bstk-datatables 0.3.3
File Interpreter ABI Platform Actions
bstk_datatables-0.3.3-py3-none-any.whl Python 3 none any Details for bstk_datatables-0.3.3-py3-none-any.whl

Total release size: 19.0 kB

Release files / bstk_datatables-0.3.3.tar.gz

Download URL bstk_datatables-0.3.3.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
66149e65dd949fdd56009ab683cadcd0524067542ace232612619245a371940d
BLAKE2b-256 checksum
How to use checksums
8e65156b22eb191d06de5f4a44fb81cea303f9f2dd57f8ac03cc996299cedc26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / bstk_datatables-0.3.3-py3-none-any.whl

Download URL bstk_datatables-0.3.3-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f1af556cf8504aae17941e3ebe30c1a325872cef4e6ef3295dcbf00211feb91
BLAKE2b-256 checksum
How to use checksums
6a8a9a63d89ace99ffc5fe2c92e05e2fa3e5b1fea6438d01cac535ca6be93fd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for bstk-datatables 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page