Skip to content

API Reference parrot_tools.scraping.extraction_registry

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

parrot_tools.scraping.extraction_registry

View source

ExtractionPlanRegistry — Disk-backed registry for ExtractionPlans.

Extends BasePlanRegistry with extraction-specific lifecycle management:

  • success/failure tracking with automatic invalidation after 3 consecutive failures; counts are persisted in the registry index so they survive process restarts
  • per-fingerprint JSON file storage
  • pre-built plan loading from a developer-curated directory
  • lazy load: index + pre-built plans are loaded on first lookup_plan() call so the async-incompatible __init__ stays sync

Alias BasePlanRegistry

Re-exported from parrot_tools.scraping.base_registry.BasePlanRegistry.

Alias ExtractionPlan

Re-exported from parrot_tools.scraping.extraction_models.ExtractionPlan.

Class ExtractionPlanRegistry

Disk-backed registry for ExtractionPlans with cache lifecycle management.

Extends BasePlanRegistry with extraction-specific features:

  • success/failure tracking persisted to the registry index JSON so failure counts survive service restarts
  • automatic invalidation after FAILURE_THRESHOLD consecutive failures
  • pre-built plan loading from a developer-curated directory
  • lazy initialisation: load() and load_prebuilt() are called on the first lookup_plan() call, keeping the sync __init__ clean
Parameter Type Default Description
plans_dir Optional[Path] None Directory for plan files and the extraction_registry.json index. Defaults to scraping_plans in the current working directory.
prebuilt_dir Optional[Path] None Directory containing pre-built plan JSON files. Defaults to DEFAULT_PREBUILT_DIR (the _prebuilt/ sub-directory shipped with this package).

Attributes:

Attribute Type Description
FAILURE_THRESHOLD int
DEFAULT_PREBUILT_DIR Path

Method ExtractionPlanRegistry.load_with_prebuilt

Load the registry index and all pre-built plans from disk.

Safe to call multiple times — subsequent calls are no-ops. Pre-built plans are only registered if they are not already in the index (identified by fingerprint) to avoid overwriting cached plans.

load_with_prebuilt() -> None

Method ExtractionPlanRegistry.register_extraction_plan

Register an ExtractionPlan in the registry.

Saves the plan as a JSON file named <fingerprint>.json and registers it in the index.

register_extraction_plan(plan: ExtractionPlan) -> None

Parameter Type Default Description
plan ExtractionPlan The ExtractionPlan to register.

Method ExtractionPlanRegistry.load_plan

Load an ExtractionPlan from disk by fingerprint.

load_plan(fingerprint: str) -> Optional[ExtractionPlan]

Parameter Type Default Description
fingerprint str The fingerprint of the plan to load.

Returns: Optional[ExtractionPlan] — The ExtractionPlan if found, None otherwise.

Method ExtractionPlanRegistry.lookup_plan

Look up and load an ExtractionPlan for a URL.

Performs lazy initialisation on the first call: loads the registry index and all pre-built plans from disk. Uses the 3-tier URL lookup from BasePlanRegistry to find a matching registry entry, then loads the plan JSON from disk.

lookup_plan(url: str) -> Optional[ExtractionPlan]

Parameter Type Default Description
url str URL to look up.

Returns: Optional[ExtractionPlan] — ExtractionPlan if found in registry or pre-built plans, None otherwise.

Method ExtractionPlanRegistry.record_success

Record a successful extraction and reset the consecutive failure count.

Also updates last_used_at and increments use_count in the registry index.

record_success(fingerprint: str) -> None

Parameter Type Default Description
fingerprint str The plan fingerprint.

Method ExtractionPlanRegistry.record_failure

Record a failed extraction. Invalidates after FAILURE_THRESHOLD failures.

The failure count is persisted in the registry index so that consecutive failures are counted correctly across process restarts. When the count reaches FAILURE_THRESHOLD, the plan is removed from the registry so that fresh LLM recon can regenerate it.

record_failure(fingerprint: str) -> None

Parameter Type Default Description
fingerprint str The plan fingerprint.

Method ExtractionPlanRegistry.load_prebuilt

Load pre-built ExtractionPlan JSON files from a directory.

Each JSON file must be parseable as an ExtractionPlan. The source field is overridden to "developer" to mark these as developer-curated plans. Plans whose fingerprint is already in the registry are skipped so cached plans are not overwritten.

load_prebuilt(directory: Path) -> int

Parameter Type Default Description
directory Path Path to directory containing JSON ExtractionPlan files.

Returns: int — Count of plans successfully loaded.

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