Skip to main content

An asyncio-style web scraping framework inspired by Scrapy, powered by curl_cffi.

Project description

scrapy_cffi

An asyncio-style web scraping framework inspired by Scrapy, powered by curl_cffi.

scrapy_cffi is a lightweight Python crawler framework that mimics the Scrapy architecture while replacing Twisted with curl_cffi as the underlying HTTP/WebSocket client.

It is designed to be efficient, modular, and suitable for both simple tasks and large-scale distributed crawlers.


✨ Features

  • Scrapy-style architecture: spiders, items, interceptors, pipelines, signals

  • Fully asyncio-based engine for maximum concurrency

  • HTTP & WebSocket support: built-in asynchronous clients

  • Flexible DB integration: Redis, MySQL, PostgreSQL, MongoDB with async retry & reconnect

  • Message queue support: RabbitMQ & Kafka (single / cluster)

  • Configurable deployment: settings system supporting .env, single-instance, sentinel, and cluster mode

  • scrapy-cffi geninfra: generate local Docker Compose templates for Redis / RabbitMQ / Kafka topologies

  • Redis Stream ingress: RedisSpider consumer groups (XREADGROUP / XACK), configurable via spider attrs or settings.REDIS_STREAM_INFO

  • Lightweight middleware & interceptor system for easy extensions

  • High-performance C-extension hooks for CPU-intensive tasks

  • Redis-compatible scheduler (optional) for distributed crawling

  • Designed for high-concurrency, high-availability crawling


📦 Installation

Note (≥ 0.3.0): Core framework changes from 0.3.0 onward are developed with AIGC-assisted workflows. For the latest features and fixes before they land on PyPI, install from GitHub or source.

From PyPI

pip install scrapy_cffi

From GitHub (latest main)

python -m pip install "scrapy_cffi @ git+https://github.com/aFunnyStrange/scrapy_cffi.git"

From source (unstable)

git clone https://github.com/aFunnyStrange/scrapy_cffi.git

cd scrapy_cffi

pip install -e .

🚀 Quick Start

scrapy-cffi startproject <project_name>

cd <project_name>

scrapy-cffi genspider <spider_name> <domain>

python runner.py

Notes:

The CLI command is scrapy_cffi in versions ≤0.1.4 and scrapy-cffi in versions >0.1.4 for improved usability.

Starting from scrapy-cffi >= 0.2.5, RedisScheduler and RabbitMqScheduler no longer automatically terminate when the queue is empty. For finite/terminable spiders, use SCHEDULER_LOOP_END to specify the number of scheduler loops before automatic exit. For continuous-listening spiders (RedisSpider, RabbitMqSpider, or custom persistent spiders), leave SCHEDULER_LOOP_END as None. This change only affects automatic termination; task scheduling remains fully functional.


⚙️ Settings & Deployment

scrapy_cffi now fully supports a flexible settings system:

  • Load configuration from Python files or .env files

  • Choose between single-instance, cluster, or sentinel mode

  • Configure databases, message queues, and concurrency limits in one place

  • Seamless integration with async Redis / MySQL / PostgreSQL / MongoDB managers

Generate local infra templates (optional):

scrapy-cffi geninfra
scrapy-cffi geninfra --redis cluster --rabbitmq cluster --kafka cluster

Example settings.py snippet (Redis Sentinel):

settings.REDIS_INFO.MODE = "sentinel"

settings.REDIS_INFO.SENTINELS = [("<sentinel_host1>", "int(sentinel_port1)"), ("<sentinel_host2>", "int(sentinel_port2)"), ("<sentinel_host3>", "int(sentinel_port3)")]

settings.REDIS_INFO.MASTER_NAME = "<master_name>"

settings.REDIS_INFO.SENTINEL_OVERRIDE_MASTER = ("master_host", "int(master_port)")

Optional Redis Stream consumer-group defaults (spider attrs override):

from scrapy_cffi.models import RedisStreamConsumerInfo, RedisIngressMode

settings.REDIS_STREAM_INFO = RedisStreamConsumerInfo(
    MODE=RedisIngressMode.STREAM,
    STREAM_KEY="tasks:ingress",
    GROUP_NAME="scrapy-workers",
)

📖 Documentation

Full technical documentation and module-level guides are available in the docs/usage/ directory.

Release history: CHANGELOG.md · Architecture: docs/ARCHITECTURE-ROADMAP.md · 0.3.2: docs/RELEASE-0.3.2.md · 0.3.1 tools: docs/RELEASE-0.3.1.md.


📄 License

BSD 3-Clause License. See LICENSE for details.


🛠 Community Highlights

Inspired by the challenges of async Python crawling:

  • Blocking requests and slow DB integration

  • Complex deployment for distributed crawlers

  • Need for fully concurrent HTTP & WebSocket requests

scrapy_cffi addresses these with a modular, high-performance framework that is async-first, extensible, and deployment-ready.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapy_cffi-0.3.2.tar.gz (207.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scrapy_cffi-0.3.2-py3-none-any.whl (249.3 kB view details)

Uploaded Python 3

File details

Details for the file scrapy_cffi-0.3.2.tar.gz.

File metadata

  • Download URL: scrapy_cffi-0.3.2.tar.gz
  • Upload date:
  • Size: 207.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for scrapy_cffi-0.3.2.tar.gz
Algorithm Hash digest
SHA256 e55563e357b37247d3f4195f8a7783d352bfed584894c0b225da6a4d6c580e6f
MD5 84673271655ac526f026e2fbe189357a
BLAKE2b-256 341dd5d07d281d5c87f1fec2e3a5125bdaae4002cbbb9c5cd4cf71bf11f9838f

See more details on using hashes here.

File details

Details for the file scrapy_cffi-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: scrapy_cffi-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 249.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for scrapy_cffi-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 28d4ee8a96c3aaed5cc6a9b42994e89c0a2f64faccbcdcd8cca6c396b9f006bc
MD5 c60207d215e97743b27f381b57829d7e
BLAKE2b-256 100cbe4b54cdeffcaa44936a95e688dcf5a446b1cb1f0aeb9f6905371adc5ce2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page