A polymorphic schema managed semi structured crosslinked data dictionary builder.. BINGO!
Project description
Datatables - structured data library based on schemas
Dev
poetry installpoetry shell
-- Make changes --poetry run pytestpoetry run black bstk_datatablespoetry 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 entrySchemaField: A basic instruction container representing a single valueSchemaFieldFormat: The specific instructions for how the field should be collected, represented, formatted and storedSchemaValuesError: 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.
.schematais a list ofSchema.code's.table_idis a link back to aTable.uuid.referencesand.connector_referencesare unrestricted containers. Two containers are provided to seperate "core" references from "free-form" references..valuesis a dict ofField.code=>valuethat conform to the listed schemata
Table
A Table corrals one or more Entry and shapes them towards one or more Schema.
.schematais a list ofSchema.code's that all entries must inherit.referencesand.connectorsare 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:
- Process the schema in order
- 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)
- 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:
- Provide an
Enum.codeas alookupinstead of avalueslist when supplyingSchemaFieldFormatto a schemafield. - Provide the instanciated
EnumtoSchema.attach_lookupon a compiledSchemaorMergedSchema.
or
- Provide an instanciated
Enumas alookupinstead of avalueslist when supplyingSchemaFieldFormatto a schemafield.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bstk_datatables-0.3.1.tar.gz.
File metadata
- Download URL: bstk_datatables-0.3.1.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c125dd9ce4d9d4474916580ac8e7fdce6c83501a4a0aed2a20227d1fad95dce9
|
|
| MD5 |
b2c02326f2adbbeb7a113a81e911d334
|
|
| BLAKE2b-256 |
28cc8ba0d45889c6dbda234ed19c33465fb2b379d7b349123325e901c28a4c00
|
File details
Details for the file bstk_datatables-0.3.1-py3-none-any.whl.
File metadata
- Download URL: bstk_datatables-0.3.1-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbee268627d16683349fbd57420d7ec76219250140d298977e59c9225a17b934
|
|
| MD5 |
973838cb2b9274217ac28c32d52de296
|
|
| BLAKE2b-256 |
ab9ffec762359c5a5dc227fcad9b1c5c6977461b016e419cc7451a8fe49bd100
|