metricengine.registry

Registry for financial calculations with dependency tracking.

metricengine.registry.calc(name, *, depends_on=())[source]

Decorator to register a calculation function with its dependencies.

Parameters:
  • name (str) – Unique name for the calculation

  • depends_on (tuple[str, ...]) – Tuple of calculation names this function depends on

Raises:

CalculationError – If the name is invalid, already registered, or self-dependent.

Return type:

Callable[[Callable[..., Any]], Callable[..., Any]]

metricengine.registry.get(name)[source]

Get a registered calculation function by name.

Return type:

Callable[..., Any]

metricengine.registry.deps(name)[source]

Get dependencies for a calculation (copy).

Return type:

set[str]

metricengine.registry.list_calculations()[source]

List all registered calculations and their dependencies (copies).

Return type:

dict[str, set[str]]

metricengine.registry.clear_registry()[source]

Clear all registered calculations. Primarily for testing.

Return type:

None

metricengine.registry.is_registered(name)[source]

Check if a calculation is registered.

Return type:

bool

metricengine.registry.unregister(name)[source]

Remove a calculation from the registry (and its edges).

Return type:

None

metricengine.registry.dependency_graph()[source]

Get a read-only view of the dependency graph (copies of sets).

Return type:

Mapping[str, set[str]]

metricengine.registry.detect_cycles()[source]

Return a set of cycles detected in the dependency graph (as tuples). Simple DFS; fine for small graphs.

Return type:

set[tuple[str, ...]]

Registry Class

Registry Functions

Global Registry