Skip to content

API Reference parrot_formdesigner.services.options_loader

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

parrot_formdesigner.services.options_loader

View source

OptionsLoader service for dynamic field option fetching.

Fetches FieldOption lists from remote OptionsSource endpoints using aiohttp.ClientSession. Features:

  • In-memory TTL cache (keyed by (source_ref, auth_ref))
  • Single-flight per cache key — concurrent calls share one in-flight request
  • Failure-safe — returns [] and logs a warning on any error, never raises

Pattern mirrors SubmissionForwarder for session lifecycle.

Alias AuthContext

Re-exported from parrot_formdesigner.services.auth_context.AuthContext.

Alias FieldOption

Re-exported from parrot_formdesigner.core.options.FieldOption.

Class OptionsLoader

Async service that fetches and caches FieldOption lists.

Uses aiohttp.ClientSession for all HTTP requests. Auth headers are resolved via AuthContext.resolve_for(source.auth_ref) if an auth context is provided.

Caching: in-memory dict keyed by (source_ref, auth_ref) with per-entry expiry timestamps derived from OptionsSource.cache_ttl_seconds.

Single-flight: concurrent calls for the same cache key share exactly one in-flight HTTP request via asyncio.Event + result sharing.

Parameter Type Default Description
timeout int DEFAULT_TIMEOUT Request timeout in seconds. Defaults to DEFAULT_TIMEOUT.

Attributes:

Attribute Type Description
DEFAULT_TIMEOUT int

Method OptionsLoader.fetch

Fetch and normalise options from the given OptionsSource.

Cache hit within TTL returns the cached list immediately. Cache miss triggers a single HTTP request; concurrent callers for the same key wait for that single request to complete.

On any error (timeout, HTTP 4xx/5xx, parse failure), logs a warning and returns [] — never raises.

fetch(source: OptionsSource, *, auth_context: AuthContext | None = None) -> list[FieldOption]

Parameter Type Default Description
source OptionsSource The OptionsSource describing the remote endpoint.
auth_context AuthContext | None None Optional runtime auth context for header resolution.

Returns: list[FieldOption] — List of FieldOption parsed from the response, or [] on error.

Method OptionsLoader.invalidate

Remove a specific cache entry.

invalidate(source_ref: str, auth_ref: str | None = None) -> None

Parameter Type Default Description
source_ref str The endpoint URL to invalidate.
auth_ref str | None None The auth reference to invalidate (or None).

Method OptionsLoader.clear_cache

Clear all cached option lists.

clear_cache() -> None

Alias OptionsSource

Re-exported from parrot_formdesigner.core.options.OptionsSource.

Attribute logger

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