capturegraph
capturegraph
#
CaptureGraph — the single authoring surface (import capturegraph as cg).
Bundles three layers under one namespace:
- the type system (
cg.Struct,cg.Image,cg.Map,cg.Date,cg.Path,cg.schema, ...), - the authoring layer (
@cg.procedure+cg.do(step)): constructing a node records it; cache with|=/&=, add side-effect steps withcg.do(step), and reach forwith cg.when(...)/cg.optional()/cg.procedure_set()/cg.while_repeat(...)blocks for control flow, and - the node constructors (
cg.CaptureImage,cg.ConvertImageToThumbnail, ...), wrapped so they acceptPathpositions and raw scalars and lower to the pure node IR.
import capturegraph as cg
class Session(cg.Struct):
photo: cg.Image
class Target(cg.Struct):
reference: cg.Image
sessions: cg.Map[cg.Date, Session]
@cg.procedure(Target)
def capture(root: cg.Procedure[cg.Path[Target]]):
root.reference |= cg.CaptureImage(label="Reference") # cache, skip if exists
session = root.sessions[cg.CaptureTime()] # a new session
session.photo &= cg.CaptureImage(label="Photo") # cache, overwrite
json_str = capture.to_json()