Skip to content

types

types #

The CaptureGraph type system.

Four structural forms — Scalar, Array, Struct, Map — describe the shape of captured data, and every type knows how to load/store its values on disk. The class is the type and, instantiated, is the loaded value: a loaded Array broadcasts attribute access, a loaded struct carries its fields as attributes.

Every type is defined by subclassing — leaves included. A struct names its fields; a leaf passes its wire name (and a file leaf its extensions) as class keywords. Composites are built by parameterization — Array[Image], Map[Date, Entry] by subscript:

import capturegraph as cg


class Session(cg.Struct):
    photo: cg.Image
    location: cg.Location
    secondaries: cg.Array[cg.Image]


class Schema(cg.Struct):
    reference_photo: cg.Image
    timelapse: cg.Map[cg.Date, Session]

A schema is serialized type-first with cg.schema / cg.from_schema, and two types are interchangeable when cg.structural_eq holds. A Map key is a keyable scalar (Date/Time, String, UserID, Bool); Date and Participant are readable aliases of Time and UserID. Path[T] (an address into a schema) and Void (a side effect) are the two non-storable types.

The type surface is aggregated at the capturegraph root (import capturegraph as cg), which imports each name directly from the leaf modules here. This __init__ carries no re-exports of its own — the layout puts the vocabulary up front and the machinery in core/:

  • cgtypeCGType, the base of every type.
  • containers/ — the composite types Array, Map, Struct.
  • scalars/ — the concrete scalar leaves, grouped by domain (primitives, time, position, geometry, imaging, identity, environment), one per module.
  • compositions/ — the built-in composite shapes, one per module.
  • special/ — the non-storable Path and Void.
  • io — the disk verbs (load / commit / copy).
  • core/ — the machinery beneath the vocabulary (registry, scalar/, container/).
  • schema/ — the tools above it (serialize, resolve, codegen).