Skip to content

API Reference parrot.handlers.models.metric_definitions

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.handlers.models.metric_definitions

View source

Postgres store for FEAT-756 metric definitions (navigator.metric_definitions).

Mirrors PgUISurfaceStore (handlers/models/ui_surfaces.py:457): fresh AsyncDB per call, idempotent DDL with race tolerance, JSONB params passed as native objects.

Alias MetricDefinition

Re-exported from parrot.metrics.MetricDefinition.

Class MetricVersionConflict

The stored row's version no longer matches the version the caller read (lost-update guard).

Class PgMetricDefinitionStore

Postgres MetricStore (PgUISurfaceStore idiom — handlers/models/ui_surfaces.py:457).

Parameter Type Default Description
dsn str | None None Postgres DSN; defaults to parrot.conf.default_dsn.

Method PgMetricDefinitionStore.ensure_schema

Idempotent DDL; tolerates "already exists" races (ui_surfaces.py:483-501).

ensure_schema() -> None

Method PgMetricDefinitionStore.get

Return one definition in exactly that namespace, or None.

get(metric_id: str, *, tenant: str | None) -> MetricDefinition | None

Parameter Type Default Description
metric_id str Metric identifier.
tenant str | None Namespace tenant; None selects the global namespace.

Returns: MetricDefinition | None

Method PgMetricDefinitionStore.list

Every definition of one namespace (no visibility filtering), ordered by metric_id.

list(*, tenant: str | None, program: str | None = None) -> list[MetricDefinition]

Parameter Type Default Description
tenant str | None Namespace tenant; None selects the global namespace.
program str | None None Optional program filter.

Returns: list[MetricDefinition]

Method PgMetricDefinitionStore.save

INSERT … ON CONFLICT DO NOTHING / DO UPDATE; returns definition.id.

save(definition: MetricDefinition, *, overwrite: bool = False, expected_version: int | None = None) -> str

Parameter Type Default Description
definition MetricDefinition Definition to persist.
overwrite bool False Replace an existing row instead of failing.
expected_version int | None None With overwrite, only replace the row when its stored version still equals this value (atomic compare-and-set; guards concurrent PUTs against lost updates).

Returns: str

Raises:

  • MetricVersionConflict — expected_version no longer matches the stored row.
  • ValueError — the definition already exists and overwrite is False.

Method PgMetricDefinitionStore.delete

Remove one definition; True when a row was removed.

delete(metric_id: str, *, tenant: str | None) -> bool

Parameter Type Default Description
metric_id str
tenant str | None

Returns: bool

Method PgMetricDefinitionStore.list_visible

Global public rows plus scope.tenant rows the scope grants.

Tenant rows are kept when the scope owns them or scope_grants allows them; other tenants' rows are never selected.

list_visible(scope: RequestScope, *, program: str | None = None) -> list[MetricDefinition]

Parameter Type Default Description
scope RequestScope
program str | None None

Returns: list[MetricDefinition]

Alias RequestScope

Re-exported from parrot.handlers.scope.RequestScope.

Alias default_dsn

Re-exported from parrot.conf.default_dsn.

Attribute logger

Alias scope_grants

Re-exported from parrot.handlers.scope.scope_grants.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally