Package: bstk-datatables
Datatables - structured data library based on schemashomepageDevpoetry installpoetry shell-- Make changes --poetry run pytestpoetry run black bstk_datatablespoetry run flake8 bstk_datatables-- Commit & Push --Installpip install bstk-datatablesOverviewDatatables act as an intermediary betweenMarshmallow structuresand 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.SchemaSchema 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 validationThese schemas and fields are mapped to equivalentMarshmallow structureswhich provide the entry value validation mechanisms.. ref:Schema.check_values()EntryAnEntryis 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 schemataTableATablecorrals one or moreEntryand shapes them towards one or moreSchema..schematais a list ofSchema.code's that all entriesmustinherit.referencesand.connectorsare unrestricted containers. Two containers are provided to seperate "core" references from "free-form" references (and allows correlation with table entries).Marshalling and PersistenceAll core classes (andEnum) expose anexportmethod which return a dict.The result of anexport()can be unpacked and provided to its constructor.deftest_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)assertexported==dataThe simplest way to handle data persistence is to encapsulate class instanciation and theexportmethod of the relevant class into an ORM or ODM framework.MergeSchemado not provide an export mechanism because they are not first-class citizens and are designed to work with establishedSchemastructures.This test provides an example of how to implement persistence with flat files.ExtrasMergedSchemaTables and Entries support more than a single schema reference.MergedSchemaexists to facilitate mutli-schema validation and field ordering.ProvideDict[Schema.Code: Schema]asschematawhen initialising aMergedSchemaand it will:Process the schema in orderDe-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 entriesEnumEnum are used within schemas as de-duped lookups. Multiple schema fields can use the same Enum for shaping values.Usage:Provide anEnum.codeas alookupinstead of avalueslist when supplyingSchemaFieldFormatto a schemafield.Provide the instanciatedEnumtoSchema.attach_lookupon a compiledSchemaorMergedSchema.orProvide an instanciatedEnumas alookupinstead of avalueslist when supplyingSchemaFieldFormatto a schemafield.