Skip to content

API Reference parrot_tools.scraping.crawl_graph

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

parrot_tools.scraping.crawl_graph

View source

CrawlGraph & CrawlNode for the CrawlEngine.

Provides the in-memory graph structure that tracks which URLs have been visited, which are pending in the frontier queue, and the results of each scrape operation. CrawlGraph implements a BFS traversal strategy using a FIFO frontier (collections.deque).

Class CrawlGraph

BFS-based crawl graph that manages the frontier and visited set.

The graph stores CrawlNode instances keyed by their normalized URL and exposes a FIFO frontier for breadth-first traversal.

Attributes:

Attribute Type Description
nodes Dict[str, CrawlNode]
visited_count int Return the number of unique URLs that have been visited.
done_nodes List[CrawlNode] Return all nodes whose status is 'done'.
failed_nodes List[CrawlNode] Return all nodes whose status is 'failed'.

Method CrawlGraph.add_root

Create the root node at depth 0 and seed the frontier.

add_root(url: str) -> CrawlNode

Parameter Type Default Description
url str The starting URL for the crawl.

Returns: CrawlNode — The newly created root CrawlNode.

Method CrawlGraph.enqueue

Add a node to the frontier if its URL has not been visited.

enqueue(node: CrawlNode) -> bool

Parameter Type Default Description
node CrawlNode The CrawlNode to enqueue.

Returns: bool — True if the node was added, False if the URL was already visited.

Method CrawlGraph.next

Pop the next node from the frontier (FIFO / BFS order).

next() -> Optional[CrawlNode]

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

Method CrawlGraph.mark_done

Transition a node to 'done' and attach its result.

mark_done(node: CrawlNode, result: Any) -> None

Parameter Type Default Description
node CrawlNode The CrawlNode that finished successfully.
result Any Arbitrary scrape result to store on the node.

Method CrawlGraph.mark_failed

Transition a node to 'failed' and record the error.

mark_failed(node: CrawlNode, error: str) -> None

Parameter Type Default Description
node CrawlNode The CrawlNode that failed.
error str Human-readable error description.

Method CrawlGraph.is_visited

Check whether a normalized URL has already been visited.

is_visited(normalized_url: str) -> bool

Parameter Type Default Description
normalized_url str The canonical URL to check.

Returns: bool — True if the URL is in the visited set.

Class CrawlNode

A single node in the crawl graph representing one URL to visit.

Parameter Type Default Description
url str
normalized_url str
depth int
parent_url Optional[str] None
status str 'pending'
result Optional[Any] None
discovered_links list list()
started_at Optional[datetime] None
finished_at Optional[datetime] None
error Optional[str] None

Fields:

Field Type Default Description
url str The original (un-normalized) URL.
normalized_url str The canonical form used for deduplication.
depth int BFS depth from the root URL (root = 0).
parent_url Optional[str] None Normalized URL of the page that linked to this one.
status str 'pending' Lifecycle state — pending | scraping | done | failed | skipped.
result Optional[Any] None Arbitrary scrape payload stored after successful processing.
discovered_links list field(default_factory=list) Raw URLs found on this page during scraping.
started_at Optional[datetime] None Timestamp when scraping began.
finished_at Optional[datetime] None Timestamp when scraping completed (success or failure).
error Optional[str] None Human-readable error message if status is 'failed'.

Class CrawlResult

Summary of a completed crawl session.

Parameter Type Default Description
start_url str
depth int
pages List[Any]
visited_urls List[str]
failed_urls List[str]
total_pages int
total_elapsed_seconds float
plan_used Optional[str] None

Fields:

Field Type Default Description
start_url str The seed URL that initiated the crawl.
depth int Maximum BFS depth that was configured.
pages List[Any] Collected page data from all successfully scraped nodes.
visited_urls List[str] List of all normalized URLs that were visited.
failed_urls List[str] List of normalized URLs that failed during scraping.
total_pages int Count of successfully scraped pages.
total_elapsed_seconds float Wall-clock time for the entire crawl.
plan_used Optional[str] None Optional identifier of the scraping plan used.

Alias normalize_url

Re-exported from parrot_tools.scraping.url_utils.normalize_url.

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