Skip to main content

Core Object Model

Project description

object-model

Table of Contents

  1. Overview
  2. Pydantic and dataclasses
  3. Persistence

[WORK IN PROGRESS]

Overview

For creating a data model in python, dataclasses and pydantic model-based classes provide a solid foundation. However, they lack important features, mostly related to persistence. object-model provides these enhancements.

Pydantic and dataclasses

Pydantic and dataclasses both provide ways to define data objects. dataclasses are attractive in that they are part of the standard python library. Pydantic provides useful extra functionality such as:

  • converting types to JSON Schema
  • serialisation to/from json
  • validation of inputs when constructing objects

the above features can (mostly) also be used with dataclasses. object-model provides a simple API for handling both styles.

Input validation only truly works on pydantic objects but all else works on both.

Serialising Subclasses

The Base and BaseModel types automatically add the object's name to the serialised output. The name can be overridden to avoid collisions. Type names are registered in the project's entry points under the group object-store. This serves as a registry of types and allows the implementation to be moved without needing to load and re-write persisted objects.

Pydantic's json serialisation does not natively provide a mechanism to serialise a member whose type is a subclass of the specified type. object-model provides a Subclass type, which expands to a discriminated union, with this type field as the discriminator.

This is represented in JSON Schema as a OneOf and allows such subclasses to be validated against the schema.

Persistence

Data model objects need to be persistable. object-model provides:

  • a bi-temporal schema with JSON/JSONB-based serialisation of the objects
  • partitioning of objects by type (where the DB supports it), allowing each type to be indexed appropriately
  • a simple mechanism for defining object IDs
  • SQL and REST implementations of an object store

ID

Id is a descriptor field applied as a ClassVar. At class-level it specifies the fields (or properties) which form a unique Id (when combined with the type). When called on an object instance, it returns a tuple of the values of those fields - the object's persisted Id. In the simplest case, object can just be a field called name.

Hierarchies of objects share the same Id. Thus, if you have a base class, the subclasses may not override the Id.

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

py_object_model-1.0.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_object_model-1.0.0-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file py_object_model-1.0.0.tar.gz.

File metadata

  • Download URL: py_object_model-1.0.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for py_object_model-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7eb3a0989bade24c96d577aa4eab2ac6233e24c0397dcb005c66feec32bbeb4d
MD5 4d06a035b358deb08211e310b77fee58
BLAKE2b-256 913c3436d5efb3087ef146761abab14dbb3ff19700011f42a5af1aa7531ab752

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_object_model-1.0.0.tar.gz:

Publisher: python-publish.yml on nickyoung-github/object-model

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_object_model-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_object_model-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 265939a39638ad62b4f5025701dcdb4fb99958a2b9bf4808986156053ea32682
MD5 2761307e98e33e077165ecf2cc38b5f8
BLAKE2b-256 69f30f8c9d53b7a29d5b145f575c3a8540630964288aaf70ebc8a8b8b252393c

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_object_model-1.0.0-py3-none-any.whl:

Publisher: python-publish.yml on nickyoung-github/object-model

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page