Skip to content

API Reference parrot_tools.scraping.crawl_strategy

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

parrot_tools.scraping.crawl_strategy

View source

Pluggable crawl traversal strategies for the CrawlEngine.

Defines the CrawlStrategy protocol and two built-in implementations:

  • BFSStrategy — breadth-first (default): visits all nodes at depth N before any node at depth N+1.
  • DFSStrategy — depth-first: follows links deep into a branch before backtracking to siblings.

Custom strategies can be created by implementing the CrawlStrategy protocol (structural subtyping — no inheritance required).

Class BFSStrategy

Breadth-first strategy: visits all nodes at depth N before depth N+1.

Uses deque.popleft() (FIFO) for next() and deque.extend() for enqueue().

Method BFSStrategy.next

Pop the oldest node from the frontier (FIFO).

next(graph: CrawlGraph) -> Optional[CrawlNode]

Parameter Type Default Description
graph CrawlGraph

Returns: Optional[CrawlNode]

Method BFSStrategy.enqueue

Append nodes to the end of the frontier.

enqueue(graph: CrawlGraph, nodes: List[CrawlNode]) -> None

Parameter Type Default Description
graph CrawlGraph
nodes List[CrawlNode]

Alias CrawlGraph

Re-exported from parrot_tools.scraping.crawl_graph.CrawlGraph.

Alias CrawlNode

Re-exported from parrot_tools.scraping.crawl_graph.CrawlNode.

Class CrawlStrategy

Protocol that determines traversal order for the CrawlEngine.

Implementations receive the current CrawlGraph and manipulate its _frontier deque to control which URLs are visited next.

Method CrawlStrategy.next

Pop and return the next node to process.

next(graph: CrawlGraph) -> Optional[CrawlNode]

Parameter Type Default Description
graph CrawlGraph

Returns: Optional[CrawlNode] — The next CrawlNode, or None if the frontier is empty.

Method CrawlStrategy.enqueue

Add newly discovered nodes to the traversal frontier.

enqueue(graph: CrawlGraph, nodes: List[CrawlNode]) -> None

Parameter Type Default Description
graph CrawlGraph The crawl graph whose frontier should be extended.
nodes List[CrawlNode] Newly discovered nodes to add.

Class DFSStrategy

Depth-first strategy: follows links deep before backtracking.

Uses deque.pop() (LIFO) for next() and deque.extend() for enqueue().

Method DFSStrategy.next

Pop the newest node from the frontier (LIFO).

next(graph: CrawlGraph) -> Optional[CrawlNode]

Parameter Type Default Description
graph CrawlGraph

Returns: Optional[CrawlNode]

Method DFSStrategy.enqueue

Append nodes to the end of the frontier.

enqueue(graph: CrawlGraph, nodes: List[CrawlNode]) -> None

Parameter Type Default Description
graph CrawlGraph
nodes List[CrawlNode]

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