# Crawlee for Python

> A Python web scraping and browser automation library for building reliable crawlers

- Category: Data & Labeling / Web Scraping & Crawling
- Language: Python
- Repository: https://github.com/apify/crawlee-python
- Website: https://crawlee.dev/python
- Canonical page: https://ai-tldr.dev/tools/crawlee-for-python/

## In short

Crawlee for Python is the Python version of the Crawlee library from Apify. It sits in the Web Scraping & Crawling category of the Data & Labeling tools and is open-source, written in Python. To get started: install Crawlee.

## Overview

Crawlee for Python is the Python version of the Crawlee library from Apify. It handles crawling and scraping end-to-end: following links, extracting data, and storing it in machine-readable formats, so you can focus on what data you want instead of the plumbing around it.

It is aimed at Python developers who need to collect web data at scale, including data for AI, LLMs, and RAG pipelines. It offers both an HTTP-based crawler that parses HTML with BeautifulSoup and a Playwright-based crawler for sites that need client-side JavaScript, with default settings tuned so crawlers blend in and avoid common bot protections.

Within the web scraping and crawling space, Crawlee sits as a full framework rather than a single-purpose tool. It manages the request queue, link enqueuing, retries, and persistent storage for you, and exposes rich configuration when the defaults are not enough. A TypeScript implementation is also available for JavaScript projects.

## What it does

- Two crawler types: BeautifulSoupCrawler for fast HTTP-based HTML scraping, and PlaywrightCrawler for JavaScript-heavy sites
- Default configuration makes crawlers appear human-like to reduce blocking by modern bot protections
- Built-in link enqueuing with context.enqueue_links() to crawl a site by following discovered links
- Persistent storage via context.push_data() that writes scraped data to a local storage/ directory
- Crawlee CLI with ready-made project templates to scaffold a new crawler quickly
- Modular install: a small core package plus optional extras like beautifulsoup and all to keep dependencies minimal

## Getting started

Crawlee is published on PyPI as the crawlee package. Install it, set up Playwright, then run a minimal crawler.

1. Install Crawlee

   Install the package with all features, then install the Playwright browser dependencies.

```bash
python -m pip install 'crawlee[all]'
playwright install
```

2. Verify the installation

   Confirm Crawlee is importable and print its version.

```bash
python -c 'import crawlee; print(crawlee.__version__)'
```

3. Scaffold a project with the CLI (optional)

   The quickest start is the Crawlee CLI, which offers prepared templates. It requires uv.

```bash
uvx 'crawlee[cli]' create my-crawler
```

4. Write a minimal crawler

   This BeautifulSoupCrawler fetches pages over HTTP, extracts the title, stores the data, and follows links. A run creates a storage/ directory in your working directory.

```python
import asyncio

from crawlee.crawlers import BeautifulSoupCrawler, BeautifulSoupCrawlingContext

async def main() -> None:
    crawler = BeautifulSoupCrawler(
        # Limit the crawl to max requests. Remove or increase it for crawling all links.
        max_requests_per_crawl=10,
    )

    # Define the default request handler, which will be called for every request.
    @crawler.router.default_handler
    async def request_handler(context: BeautifulSoupCrawlingContext) -> None:
        context.log.info(f'Processing {context.request.url} ...')

        # Extract data from the page.
        data = {
            'url': context.request.url,
            'title': context.soup.title.string if context.soup.title else None,
        }

        # Push the extracted data to the default dataset.
        await context.push_data(data)

        # Enqueue all links found on the page.
        await context.enqueue_links()

    # Run the crawler with the initial list of URLs.
    await crawler.run(['https://crawlee.dev'])

if __name__ == '__main__':
    asyncio.run(main())
```

## When to use it

- Collecting web data to feed AI, LLM, and RAG pipelines
- Scraping structured data from static HTML pages at scale using the HTTP-based BeautifulSoupCrawler
- Crawling JavaScript-heavy sites that need a real browser via the PlaywrightCrawler
- Building a site crawler that follows links and persists results to local storage for later processing
