Skip to content

Extend utilities consistently

Utilities simplify repeated API work while keeping values and failures aligned. They should make a script shorter without taking over its project selection, business rules, or execution policy.

What belongs in utilities

  • Helpers that combine repeated API steps, such as resolving properties and reading them for a list of elements.
  • Identifier normalization, request-payload builders, and response unwrapping.
  • Batch result containers that preserve values, failures, and original positions.
  • Passive population reports and explicit relationships between result sets.
  • Small resource-handling helpers when they simplify an API workflow.

API-dependent work belongs in a bound namespace such as api.utilities.property. Identifier conversion and payload construction should be pure helpers that can work without a running Archicad instance.

What does not belong in utilities

  • Thin wrappers that only forward an unchanged request to one generated command. Call the generated client directly instead.
  • Company-specific naming rules, property mappings, or business decisions.
  • Script execution, project selection/switching, retries, progress reporting, or UI state. These belong in the application shell or runner.
  • A cache of live BIM data. The application owns caches and their invalidation.
  • Heavy geometry engines, polygon clipping, or application-specific spatial matching. Keep those algorithms and dependencies in a dedicated package or consuming application.

Keep API access explicit

Bound namespaces retain their UnifiedApi reference. They do not cache project data. Pass shared execution data explicitly to query evaluation; let an application own its caches and clear them when project context changes.

Prefer one batch request over a request per element. Do not add a stateful element wrapper whose field access hides repeated HTTP calls.

Accept useful inputs without modifying them

Use the identifier aliases and normalizers in utilities.identifiers for supported official/Tapir models, GUID strings, and UUIDs. Use Sequence or Mapping for read-only collection inputs. Never reorder or mutate a caller's elements, properties, or values in place.

Return concrete collections for ordinary reads and concrete result containers for diagnostics. Keep shared payload builders independent of the client so their behavior can be checked offline.

This is a focused use of Postel's law: accept the supported forms of an identifier, normalize them, and return predictable types. It does not mean silently accepting malformed values, ambiguous input shapes, or unknown states. Report those problems rather than guessing what the caller intended.

Keep results stable

Transformations should produce new result containers rather than changing the input's positions or states. Recording another step must not change an earlier report snapshot. This makes failures easier to trace through a pipeline.

Result records use frozen containers, but their values can include mutable Pydantic objects. A stable container is not a deep freeze of every payload. Do not treat ordinary generated models as immutable; applications can opt into the frozen model configuration when appropriate.

Provide diagnostics where they help

For operations over supplied items, offer an ordinary method and an _result variant when per-item failures matter:

  • The ordinary method returns usable data or raises on the failures its policy treats as fatal.
  • The _result variant returns an aligned container with individual values, errors, and skipped states. Transport/setup exceptions can still propagate.

Simple discovery helpers can return a list and raise for a failed request; they do not need a diagnostic variant merely to follow a naming pattern.

Use BatchResult for one outcome per item, BatchGrid for a rectangular grid, and RaggedBatchResult when row lengths differ. Keep original input positions when filtering, projecting, or reporting failures. Success-only lists lose that alignment; expose coordinates when a caller needs to map back to inputs.

The four slot states distinguish success, direct error, upstream failure, and intentional filtering. For sparse writes, omit filtered cells and preserve upstream-failed positions. Do not replace missing values with empty strings or defaults without an explicit task policy. Writes are not automatically atomic.

Keep reports passive

PopulationResults records steps against the original ordered items. MultiPopulationResults and PopulationRelation connect populations through explicit index pairs. They do not execute commands, infer relationships, stop work, retry, or roll back changes.

Completion comes from the caller. A completed workflow can contain failures; an interrupted snapshot can contain incomplete items. Later recording must not change earlier snapshots. Keep a direct failure attached to its original population and coordinates rather than duplicating it across related targets.

See the batch guide and pipeline cookbook for user-facing examples.

Extend queries through their public contracts

Predicates own their validation, references, preparation requirements, candidate bounds, and evaluation. Groups compose child behavior; avoid adding a new central dispatch branch for each property family. Keep metadata reads in bound utilities or context sources and pure evaluation on supplied data.

Field descriptors, catalogues, and editable rows serve consumers without reading UI controls. Preserve complete-tree validation, diagnostics, input ordering, and the current floor-plan default when changing candidate collection. Read the query reference and editor integration guide before extending their public models.

Check behavior with realistic data shapes

Use real official/Tapir Pydantic records with mocked transport. Check empty inputs, duplicates, row/cell failures, filtered/upstream states, shape mismatches, projection alignment, and unchanged snapshots where the change can affect them. Use existing focused suites under utility tests, including the batch, population, multiple-population, and property tests.

Import public utility groups and result containers from multiconn_archicad.utilities. Import payload helpers from their defining namespace modules. Avoid requiring consumers to reach into query source storage or other internal implementation objects.