$ show apify/crawlee-python
Crawlee is a production-grade Python web scraping and browser automation framework developed by Apify. It provides a unified async API for both static HTTP crawling (BeautifulSoup, Parsel, raw HTTP) and headless browser automation (Playwright, Stagehand), with an adaptive mode that dynamically chooses between them based on page characteristics. The architecture is modular: a context pipeline chains pre-navigation hooks, HTTP execution (via pluggable clients like httpx, curl-impersonate, or impit), parsing, and post-processing before dispatching to user-defined router handlers. Storage is abstracted behind Dataset, KeyValueStore, and RequestQueue interfaces with multiple backends (memory, filesystem, SQL, Redis). The framework includes autoscaling, session management, proxy rotation, browser fingerprint generation for anti-blocking, OpenTelemetry instrumentation, and a CLI for project scaffolding. It is designed for large-scale crawling with state persistence across runs and supports deployment on Apify, AWS Lambda, and Google Cloud Run.
The LLM identified 5 files worth highlighting for reuse:
Implements a composable middleware chain using async generators for initialization and cleanup. Each middleware step yields control to the next, with proper resource management via try/finally. This pattern is reusable for any request-processing pipeline and demonstrates clean separation of concerns.
A generic class that persists any Pydantic model to a key-value store with event-driven saving, explicit-only mode, and deep-copy defaults. Used by SessionPool, RequestList, and RenderingTypePredictor. Can be extracted for any project needing crash-recoverable state without coupling to the rest of Crawlee.
Wraps any RequestManager with per-domain delay tracking, HTTP 429 backoff, crawl-delay respect, and domain stall detection. Routes requests to sub-managers based on domain. Demonstrates robust rate-limit handling that can be reused in any web crawling or API client project.
Streaming SAX-based sitemap parser that handles XML, TXT, gzipped, and nested sitemaps with size caps, robots.txt discovery, and cross-origin filtering. Handles real-world quirks like CDATA, malformed XML, and gzip bombs. The streaming approach avoids loading entire files into memory, making it suitable for large sitemaps.
Dynamically adjusts concurrency based on CPU, memory, event loop, and client load snapshots. Uses a weighted overload ratio to decide whether to scale up or down. Reusable for any async system needing adaptive concurrency without hardcoding limits.