Skip to main content

Installation

To install the Firecrawl Python SDK, you can use pip:
Python

Usage

  1. Get an API key from firecrawl.dev
  2. Set the API key as an environment variable named FIRECRAWL_API_KEY or pass it as a parameter to the Firecrawl class.
Here’s an example of how to use the SDK:
Python

Scraping a URL

To scrape a single URL, use the scrape method. It takes the URL as a parameter and returns the scraped document.
Python
The Python SDK converts all response field names from camelCase to snake_case. For example, metadata fields like ogImage, ogTitle, and sourceURL from the API become og_image, og_title, and source_url in the SDK response.

Crawl a Website

To crawl a website, use the crawl method. It takes the starting URL and optional options as arguments. The options allow you to specify additional settings for the crawl job, such as the maximum number of pages to crawl, allowed domains, and the output format. See Pagination for auto/manual pagination and limiting.
Python

Sitemap-Only Crawl

Use sitemap="only" to crawl sitemap URLs only (the start URL is always included, and HTML link discovery is skipped).
Python

Start a Crawl

Prefer non-blocking? Check out the Async Class section below.
Start a job without waiting using start_crawl. It returns a job ID you can use to check status. Use crawl when you want a waiter that blocks until completion. See Pagination for paging behavior and limits.
Python

Checking Crawl Status

To check the status of a crawl job, use the get_crawl_status method. It takes the job ID as a parameter and returns the current status of the crawl job.
Python

Cancelling a Crawl

To cancel an crawl job, use the cancel_crawl method. It takes the job ID of the start_crawl as a parameter and returns the cancellation status.
Python

Map a Website

Use map to generate a list of URLs from a website. The options let you customize the mapping process, including excluding subdomains or utilizing the sitemap.
Python

Crawling a Website with WebSockets

To crawl a website with WebSockets, start the job with start_crawl and subscribe using the watcher helper. Create a watcher with the job ID and attach handlers (e.g., for page, completed, failed) before calling start().
Python

Pagination

Firecrawl endpoints for crawl and batch scrape return a next URL when more data is available. The Python SDK auto-paginates by default and aggregates all documents; in that case next will be None. You can disable auto-pagination or set limits to control pagination behavior.

PaginationConfig

Use PaginationConfig to control pagination behavior when calling get_crawl_status or get_batch_scrape_status:
Python

Manual Pagination Helpers

When auto_paginate=False, the response includes a next URL if more data is available. Use these helper methods to fetch subsequent pages:
  • get_crawl_status_page(next_url) - Fetch the next page of crawl results using the opaque next URL from a previous response.
  • get_batch_scrape_status_page(next_url) - Fetch the next page of batch scrape results using the opaque next URL from a previous response.
These methods return the same response type as the original status call, including a new next URL if more pages remain.

Crawl

Use the waiter method crawl for the simplest experience, or start a job and page manually.
Simple crawl (auto-pagination, default)
Manual crawl with pagination control
Start a job, then fetch one page at a time with auto_paginate=False. Use get_crawl_status_page to fetch subsequent pages:
Python
Manual crawl with limits (auto-pagination + early stop)
Keep auto-pagination on but stop early with max_pages, max_results, or max_wait_time:
Python

Batch Scrape

Use the waiter method batch_scrape, or start a job and page manually.
Simple batch scrape (auto-pagination, default)
Manual batch scrape with pagination control
Start a job, then fetch one page at a time with auto_paginate=False. Use get_batch_scrape_status_page to fetch subsequent pages:
Python
Manual batch scrape with limits (auto-pagination + early stop)
Keep auto-pagination on but stop early with max_pages, max_results, or max_wait_time:
Python

Error Handling

The SDK handles errors returned by the Firecrawl API and raises appropriate exceptions. If an error occurs during a request, an exception will be raised with a descriptive error message.

Async Class

For async operations, use the AsyncFirecrawl class. Its methods mirror Firecrawl, but they don’t block the main thread.
Python

Browser

Launch cloud browser sessions and execute code remotely.

Create a Session

Python

Execute Code

Python
Execute JavaScript instead of Python:
Python

Profiles

Save and reuse browser state (cookies, localStorage, etc.) across sessions:
Python

Connect via CDP

For full Playwright control, connect directly using the CDP URL:
Python

List & Close Sessions

Python