Skip to content

Python SDK

Updated Feb 2026

The official Python SDK for Firecrawl. Supports both synchronous and asynchronous usage, all v2 API features, and auto-pagination out of the box.

Packagefirecrawl-py
PyPIpypi.org/project/firecrawl-py
API Versionsv1, v2
Sourcegithub.com/mendableai/firecrawl

Installation

bash
pip install firecrawl-py

Initialization

python
from firecrawl import Firecrawl

firecrawl = Firecrawl(api_key="fc-YOUR-API-KEY")

The API key can also be set via the FIRECRAWL_API_KEY environment variable, in which case the api_key parameter can be omitted.


Methods

scrape()

Scrapes a single URL and returns the content in the requested formats. See Scrape feature docs for full parameter details.

Signature:

python
firecrawl.scrape(url, formats=["markdown"], **kwargs)

Parameters:

ParameterTypeRequiredDescription
urlstrYesThe URL to scrape
formatslist[str]NoOutput formats: "markdown", "html", "rawHtml", "links", "screenshot", "json"

Example:

python
result = firecrawl.scrape("https://firecrawl.dev", formats=["markdown", "html"])
print(result["markdown"])
print(result["html"])

Performs a web search and optionally scrapes the results. See Search feature docs for full parameter details.

Signature:

python
firecrawl.search(query, limit=5, scrape_options=None, **kwargs)

Parameters:

ParameterTypeRequiredDescription
querystrYesSearch query string
limitintNoMaximum number of results (default: 5)
scrape_optionsdictNoOptions for scraping results, e.g., {"formats": ["markdown"]}
sourcesstrNoResult types: "web", "news", "images"
categoriesstrNoFilter: "github", "research", "pdf"
locationstrNoGeographic targeting, e.g., "Germany"
tbsstrNoTime filter: "qdr:h" (hour), "qdr:d" (day), "qdr:w" (week), "qdr:m" (month)
timeoutintNoTimeout in milliseconds

Example:

python
results = firecrawl.search(
    "firecrawl web scraping",
    limit=3,
    scrape_options={"formats": ["markdown", "links"]}
)

for result in results.get("web", []):
    print(result["title"], result["url"])

crawl()

Crawls a website starting from a URL. This is a blocking call that waits for the crawl to complete. Auto-paginates results by default. See Crawl feature docs for full parameter details.

Signature:

python
firecrawl.crawl(url, limit=100, poll_interval=5, timeout=300, scrape_options=None, sitemap=None, **kwargs)

Parameters:

ParameterTypeRequiredDescription
urlstrYesStarting URL
limitintNoMaximum pages to crawl
poll_intervalintNoPolling interval in seconds
timeoutintNoMaximum wait time in seconds
scrape_optionsdictNoScrape settings, e.g., {"formats": ["markdown"]}
sitemapstrNoSitemap mode: "only" to crawl sitemap URLs exclusively
pagination_configPaginationConfigNoControls auto-pagination behavior

Example:

python
job = firecrawl.crawl(
    url="https://docs.firecrawl.dev",
    limit=5,
    poll_interval=1,
    timeout=120
)
print(job.status)
for doc in job.data:
    print(doc.metadata.source_url)

Sitemap-only crawl:

python
job = firecrawl.crawl(
    url="https://docs.firecrawl.dev",
    sitemap="only",
    limit=25
)
print(job.status, len(job.data))

start_crawl()

Initiates a non-blocking crawl and returns a job ID for status polling.

Signature:

python
firecrawl.start_crawl(url, limit=100, **kwargs)

Parameters:

ParameterTypeRequiredDescription
urlstrYesStarting URL
limitintNoMaximum pages to crawl

Example:

python
job = firecrawl.start_crawl(url="https://docs.firecrawl.dev", limit=10)
print(job.id)  # Use this ID to check status

get_crawl_status()

Retrieves the current status and results of a crawl job.

Signature:

python
firecrawl.get_crawl_status(crawl_id, pagination_config=None)

Parameters:

ParameterTypeRequiredDescription
crawl_idstrYesJob ID from start_crawl()
pagination_configPaginationConfigNoControls pagination behavior

Example:

python
status = firecrawl.get_crawl_status("<crawl-id>")
print(status.status)
print(status.completed, "/", status.total)

get_crawl_status_page()

Fetches the next page of results using the opaque next URL from a previous response. Used for manual pagination.

Signature:

python
firecrawl.get_crawl_status_page(next_url)

Example:

python
while status.next:
    status = firecrawl.get_crawl_status_page(status.next)
    print("Next page:", len(status.data), "docs")

cancel_crawl()

Cancels an active crawl job.

Signature:

python
firecrawl.cancel_crawl(crawl_id)

Example:

python
ok = firecrawl.cancel_crawl("<crawl-id>")
print("Cancelled:", ok)

map()

Discovers all URLs on a website without scraping their content. See Map feature docs for full parameter details.

Signature:

python
firecrawl.map(url, limit=None)

Parameters:

ParameterTypeRequiredDescription
urlstrYesTarget URL
limitintNoMaximum URLs to discover

Example:

python
res = firecrawl.map(url="https://firecrawl.dev", limit=10)
for link in res.links:
    print(link)

batch_scrape()

Scrapes multiple URLs in a single batch operation. Blocking -- waits for all URLs to complete. Auto-paginates results by default.

Signature:

python
firecrawl.batch_scrape(urls, formats=["markdown"], poll_interval=1, timeout=60, pagination_config=None)

Parameters:

ParameterTypeRequiredDescription
urlslist[str]YesURLs to scrape
formatslist[str]NoOutput formats
poll_intervalintNoPolling interval in seconds
timeoutintNoMaximum wait time in seconds
pagination_configPaginationConfigNoControls pagination

Example:

python
job = firecrawl.batch_scrape(
    [
        "https://firecrawl.dev",
        "https://docs.firecrawl.dev",
    ],
    formats=["markdown"],
    poll_interval=1,
    timeout=60
)
print(job.status, job.completed, job.total)

start_batch_scrape()

Initiates a non-blocking batch scrape and returns a job ID.

Signature:

python
firecrawl.start_batch_scrape(urls, **kwargs)

Example:

python
batch_job = firecrawl.start_batch_scrape([
    "https://firecrawl.dev",
    "https://docs.firecrawl.dev",
])
print(batch_job.id)

get_batch_scrape_status()

Checks the status of a batch scrape job.

Signature:

python
firecrawl.get_batch_scrape_status(job_id, pagination_config=None)

Example:

python
from firecrawl.v2.types import PaginationConfig

status = firecrawl.get_batch_scrape_status(
    batch_job.id,
    pagination_config=PaginationConfig(auto_paginate=False)
)
print(status.status, status.completed, status.total)

extract()

Extracts structured data from one or more URLs using a schema or natural language prompt. Supports wildcard URL patterns. See Extract feature docs for full parameter details.

Signature:

python
firecrawl.extract(urls, prompt=None, schema=None, enable_web_search=False)

Parameters:

ParameterTypeRequiredDescription
urlslist[str]YesURLs to extract from (supports wildcards like example.com/*)
promptstrNoNatural language description of the data to extract
schemadictNoJSON Schema defining the output structure
enable_web_searchboolNoAllow extraction to follow external links

Example:

python
result = firecrawl.extract(
    urls=["https://firecrawl.dev/*"],
    prompt="Extract the company name, description, and pricing plans",
    schema={
        "type": "object",
        "properties": {
            "company": {"type": "string"},
            "description": {"type": "string"},
            "pricing_plans": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "name": {"type": "string"},
                        "price": {"type": "string"}
                    }
                }
            }
        }
    }
)
print(result)

agent()

Autonomous web data gathering agent that searches, navigates, and extracts data without requiring specific URLs. See Agent feature docs for full parameter details.

Signature:

python
firecrawl.agent(prompt, model="spark-1-mini", urls=None, schema=None, max_credits=2500)

Parameters:

ParameterTypeRequiredDescription
promptstrYesNatural language description of the data to gather (max 10,000 chars)
modelstrNo"spark-1-mini" (default, 60% cheaper) or "spark-1-pro"
urlslist[str]NoOptional URLs to focus extraction scope
schemaBaseModel or dictNoPydantic model or JSON Schema for structured output
max_creditsintNoCredit spending limit (default: 2,500)

Example with Pydantic schema:

python
from pydantic import BaseModel, Field
from typing import List, Optional

class Founder(BaseModel):
    name: str = Field(description="Full name of the founder")
    role: Optional[str] = Field(None, description="Role or position")

class FoundersSchema(BaseModel):
    founders: List[Founder]

result = firecrawl.agent(
    prompt="Find the founders of Firecrawl",
    schema=FoundersSchema,
    model="spark-1-mini",
    max_credits=100
)
print(result)

watcher()

Subscribes to real-time crawl updates via an async generator. Must be used with AsyncFirecrawl.

Signature:

python
async for snapshot in firecrawl.watcher(job_id, kind="crawl", poll_interval=2, timeout=120):
    ...

Parameters:

ParameterTypeRequiredDescription
job_idstrYesCrawl job ID
kindstrNoJob type, e.g., "crawl"
poll_intervalintNoPolling interval in seconds
timeoutintNoMaximum wait time in seconds

Example:

python
async for snapshot in firecrawl.watcher(started.id, kind="crawl", poll_interval=2, timeout=120):
    if snapshot.status == "completed":
        print("DONE", snapshot.status)
        for doc in snapshot.data:
            print("DOC", doc.metadata.source_url if doc.metadata else None)

Browser Methods

Firecrawl provides cloud browser sessions that you can control programmatically. See Browser feature docs for full details.

browser()

Creates a cloud browser session.

Parameters:

ParameterTypeRequiredDescription
ttlintNoSession time-to-live in seconds
profiledictNoBrowser profile with name and save_changes keys

Example:

python
session = firecrawl.browser(
    ttl=300,
    profile={
        "name": "my-profile",
        "save_changes": True,
    }
)
print(session.id)
print(session.cdp_url)
print(session.live_view_url)

browser_execute()

Executes code within a browser session.

Parameters:

ParameterTypeRequiredDescription
session_idstrYesSession ID
codestrYesCode to execute
languagestrNo"python" or "node"

Python example:

python
result = firecrawl.browser_execute(
    session.id,
    code='await page.goto("https://news.ycombinator.com")\ntitle = await page.title()\nprint(title)',
    language="python",
)
print(result.result)  # "Hacker News"

JavaScript example:

python
result = firecrawl.browser_execute(
    session.id,
    code='await page.goto("https://example.com"); const t = await page.title(); console.log(t);',
    language="node",
)

list_browsers()

Lists active browser sessions.

python
sessions = firecrawl.list_browsers(status="active")
for s in sessions.sessions:
    print(s.id, s.status, s.created_at)

delete_browser()

Closes a browser session.

python
firecrawl.delete_browser(session.id)

Playwright CDP Integration

You can connect to a Firecrawl browser session using Playwright's CDP support:

python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(session.cdp_url)
    context = browser.contexts[0]
    page = context.pages[0] if context.pages else context.new_page()
    page.goto("https://example.com")
    print(page.title())
    browser.close()

PaginationConfig

Controls how auto-pagination works for crawl and batch scrape operations.

Import:

python
from firecrawl.v2.types import PaginationConfig

Options:

OptionTypeDefaultDescription
auto_paginateboolTrueAutomatically fetch all pages and aggregate results
max_pagesintNoneStop after this many pages (requires auto_paginate=True)
max_resultsintNoneStop after collecting this many documents
max_wait_timeintNoneStop after this many seconds

Example:

python
status = firecrawl.get_crawl_status(
    crawl_job.id,
    pagination_config=PaginationConfig(
        max_pages=2,
        max_results=50,
        max_wait_time=15
    )
)

Async Support

The AsyncFirecrawl class mirrors the synchronous Firecrawl class with non-blocking async methods. All methods return awaitables.

Import and initialization:

python
import asyncio
from firecrawl import AsyncFirecrawl

async def main():
    firecrawl = AsyncFirecrawl(api_key="fc-YOUR-API-KEY")

    # Scrape
    doc = await firecrawl.scrape("https://firecrawl.dev", formats=["markdown"])
    print(doc.get("markdown"))

    # Search
    results = await firecrawl.search("firecrawl", limit=2)
    print(results.get("web", []))

    # Crawl
    started = await firecrawl.start_crawl("https://docs.firecrawl.dev", limit=3)
    status = await firecrawl.get_crawl_status(started.id)
    print(status.status)

    # Batch scrape
    job = await firecrawl.batch_scrape(
        ["https://firecrawl.dev", "https://docs.firecrawl.dev"],
        formats=["markdown"],
        poll_interval=1,
        timeout=60
    )
    print(job.status)

asyncio.run(main())

Async Watcher

The watcher() method works as an async generator for real-time updates:

python
async for snapshot in firecrawl.watcher(started.id, kind="crawl", poll_interval=2, timeout=120):
    if snapshot.status == "completed":
        for doc in snapshot.data:
            print(doc.metadata.source_url)
        break

Error Handling

The SDK raises descriptive exceptions for API errors. Wrap calls in try/except blocks to handle failures gracefully:

python
try:
    result = firecrawl.scrape("https://example.com", formats=["markdown"])
except Exception as e:
    print(f"Firecrawl error: {e}")

Common error scenarios:

ScenarioCause
Invalid API keyKey is missing, expired, or malformed
Rate limit exceededToo many requests in a short period
URL not reachableTarget URL is down or blocked
TimeoutOperation exceeded the configured timeout
Credit limit reachedAccount or job credit limit exceeded

Response Structures

Scrape Response

A dictionary with keys matching the requested formats:

python
{
    "markdown": "# Page Title\n...",
    "html": "<h1>Page Title</h1>...",
    "metadata": {
        "title": "Page Title",
        "source_url": "https://example.com",
        ...
    }
}

Crawl Job Response

An object with the following attributes:

AttributeTypeDescription
statusstrJob status: "completed", "failed", "scraping"
datalistList of scraped documents
completedintNumber of pages completed
totalintTotal pages to crawl
nextstrPagination URL (if more data available)

Browser Session Response

AttributeTypeDescription
idstrSession identifier
cdp_urlstrChrome DevTools Protocol WebSocket URL
live_view_urlstrURL for live monitoring