Skip to main content

An intuitive web scraping toolkit with intelligent templates and interactive workflows

Project description

Quarry ๐Ÿชจโ›๏ธ

A modern Python toolkit for web data extraction with robust support for React, Vue, and other JavaScript frameworks.

Python 3.11+ PyPI version Tests License: MIT Code style: ruff


๐ŸŒŸ What is Quarry?

Quarry provides two powerful approaches for web scraping:

  1. โš’๏ธ Quarry Tools - Interactive CLI pipeline for building extraction workflows
  2. โ›๏ธ Miner Mode - Interactive pipeline assistant with Scout recommendations and templates

Key Feature: Resilient selectors that survive CSS framework updates (React CSS-in-JS, Vue scoped styles, etc.)


๐Ÿš€ Quick Start

Installation

pip install py-quarry

Requirements: Python 3.11+

New to Quarry? Try the Guided Tutorial

quarry foreman

The Foreman walks you through the complete 5-tool pipeline in ~2-3 minutes using Hacker News as a demo.

Your First Extraction

# Analyze a webpage
quarry scout https://example.com

# Extract data
quarry excavate schema.yml --url https://example.com

# Export results
quarry ship output.jsonl results.csv

๐Ÿ“– Full guide: USAGE_GUIDE.md | INSTALLATION.md


โš’๏ธ Quarry Tools

5 integrated tools for complete extraction pipelines:

Tool Purpose Example
๐Ÿ“ก Scout Analyze HTML & detect patterns quarry scout <url>
๐Ÿ“ Survey Design extraction schemas quarry survey create schema.yml
๐Ÿ”จ Excavate Execute data extraction quarry excavate schema.yml --url <url>
โœจ Polish Transform & clean data quarry polish data.jsonl --dedupe
๐Ÿ“ฆ Ship Export to CSV/JSON/SQLite/PostgreSQL quarry ship data.jsonl output.csv

Complete pipeline:

quarry scout <url> | quarry excavate | quarry polish --dedupe | quarry ship results.csv

๐Ÿ“š Detailed docs: docs/QUARRY_COMPLETE.md


โ›๏ธ Miner Mode

Guided extraction pipeline with intelligent recommendations:

# Launch interactive miner
quarry miner

# Miner will:
# 1. Analyze page with Scout
# 2. Recommend selectors or offer templates  
# 3. Extract data with pagination
# 4. Clean and deduplicate
# 5. Export to your format (CSV, PostgreSQL, etc.)

Choose your approach: Scout recommendations (fastest), templates (guided), or custom selectors (full control)

๐Ÿ“š Miner guide: USAGE_GUIDE.md


๐ŸŽฏ Modern Framework Support

The Problem: React/Vue sites use dynamic CSS classes (.css-17p10p8) that change with every build.

Quarry's Solution: Structural selectors that survive CSS changes:

# โŒ Brittle - breaks on rebuild
title: h3.css-17p10p8 a

# โœ… Resilient - structural hierarchy
title: h3 a

Tools for Modern Sites

1. Selector Audit Tool

python scripts/audit_schema_selectors.py my_schema.yml
# Detects brittle selectors, suggests fixes

2. Selector Utilities

from quarry.lib.selectors import build_robust_selector

robust = build_robust_selector('h3.css-xyz a', ['tag'])
# Returns: 'h3 a'

3. Framework Detection

from quarry.framework_profiles import detect_framework

framework = detect_framework(html, soup, url)
# Automatically detects React, Vue, WordPress, etc.

๐Ÿ“š Complete guide: docs/MODERN_FRAMEWORKS.md


๐Ÿ“Š Features

  • โœ… Framework Detection - Automatic detection of 9+ frameworks
  • โœ… Resilient Selectors - Survive CSS framework updates
  • โœ… Rate Limiting - Token bucket with exponential backoff
  • โœ… Robots.txt - Automatic parsing and compliance
  • โœ… State Management - SQLite-based deduplication
  • โœ… Multiple Exports - CSV, JSON, SQLite, Parquet, PostgreSQL
  • โœ… Validation - Schema validation with Pydantic
  • โœ… Guided Tutorial - quarry foreman for interactive learning
  • โœ… Testing - 217 tests, 100% passing

๐Ÿ“ Project Structure

quarry/
โ”œโ”€โ”€ lib/                 # Core utilities
โ”‚   โ”œโ”€โ”€ selectors.py    # CSS selector utilities
โ”‚   โ”œโ”€โ”€ http.py         # HTTP client with rate limiting
โ”‚   โ””โ”€โ”€ robots.py       # Robots.txt parser
โ”œโ”€โ”€ tools/              # Quarry suite
โ”‚   โ”œโ”€โ”€ scout/          # HTML analysis
โ”‚   โ”œโ”€โ”€ survey/         # Schema designer
โ”‚   โ”œโ”€โ”€ excavate/       # Extraction engine
โ”‚   โ”œโ”€โ”€ polish/         # Data transformation
โ”‚   โ””โ”€โ”€ ship/           # Data export
โ”œโ”€โ”€ framework_profiles/ # Framework detection
โ”œโ”€โ”€ connectors/         # Data source connectors
โ”œโ”€โ”€ transforms/         # Data transformations
โ””โ”€โ”€ sinks/              # Output writers

๐Ÿ“– Documentation


โš™๏ธ Configuration

The CLI and HTTP client can be tuned via environment variables:

Logging & HTTP:

  • QUARRY_LOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR). Default INFO.
  • QUARRY_LOG_JSON: Set to 1 to emit JSON logs to stderr.
  • QUARRY_OUTPUT_DIR: Base directory for schemas, extraction output, caches, and the Foreman tutorial. Defaults to the current working directory. When set, Quarry skips save-location prompts and writes all artifacts inside this directory.
  • QUARRY_DEFAULT_RPS: Default requests-per-second per domain (float). Default 1.0.
  • QUARRY_HTTP_TIMEOUT: Default request timeout in seconds (int). Default 30.
  • QUARRY_HTTP_MAX_RETRIES: Default HTTP retries (int). Default 3.
  • PROXY_URL: HTTP/HTTPS proxy URL (also honors standard HTTP(S)_PROXY).
  • QUARRY_MAX_CONTENT_MB: Max response size in MB (int). Rejects larger payloads.
  • QUARRY_INTERACTIVE: 1 to prompt when robots.txt blocks (ethical default is non-interactive).
  • QUARRY_IGNORE_ROBOTS: 1 to ignore robots.txt (testing only).

Database Exports:

  • QUARRY_POSTGRES_URL: PostgreSQL connection URL for database exports.

Examples:

export QUARRY_LOG_LEVEL=INFO
export QUARRY_DEFAULT_RPS=0.5
export QUARRY_HTTP_TIMEOUT=60
export QUARRY_HTTP_MAX_RETRIES=5
export QUARRY_MAX_CONTENT_MB=10
export PROXY_URL=http://proxy.internal:8080
export QUARRY_OUTPUT_DIR=/tmp/quarry_outputs
export QUARRY_POSTGRES_URL=postgresql://user:pass@localhost:5432/extractions

quarry excavate schemas/example.yml --url https://example.com -o out.jsonl
quarry ship out.jsonl postgresql://localhost/db  # Export to PostgreSQL

๐Ÿงช Development

# Run tests
pytest                          # All tests
pytest tests/test_scout.py -v   # Specific tool

# Code quality
ruff format .                   # Format code
ruff check .                    # Lint code

# Quick commands
make test                       # Run tests
make format                     # Format code
make check                      # Lint code

๐Ÿค Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

To add a new framework profile:

# quarry/framework_profiles/frameworks/my_framework.py
class MyFrameworkProfile(FrameworkProfile):
    name = "MyFramework"
    
    def detect(self, html: str, soup: BeautifulSoup, url: str) -> int:
        score = 0
        if 'framework-marker' in html:
            score += 50
        return score

๐Ÿ“„ License

MIT License - see LICENSE


๐Ÿ™ Acknowledgments


Happy Scraping! ๐ŸŽ‰

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

py_quarry-2.0.9.tar.gz (189.4 kB view details)

Uploaded Source

Built Distribution

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

py_quarry-2.0.9-py3-none-any.whl (158.0 kB view details)

Uploaded Python 3

File details

Details for the file py_quarry-2.0.9.tar.gz.

File metadata

  • Download URL: py_quarry-2.0.9.tar.gz
  • Upload date:
  • Size: 189.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py_quarry-2.0.9.tar.gz
Algorithm Hash digest
SHA256 589f90c3880e49bf1709bf0f862cd1b66f19f011d4d205b9a701baadd7193a19
MD5 67b30648bf17c4c60fe577c45cd21e2d
BLAKE2b-256 243f989ef3efaa6185e2b94e039969b04bbbe672b2f583ba540758736c82d59d

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_quarry-2.0.9.tar.gz:

Publisher: pypi-publish.yml on russellbomer/quarry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_quarry-2.0.9-py3-none-any.whl.

File metadata

  • Download URL: py_quarry-2.0.9-py3-none-any.whl
  • Upload date:
  • Size: 158.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py_quarry-2.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 1921705561b06dc54ec8192409bac6e0e4a90d8cfbe6673e88411deb58087f5c
MD5 8d11524dff80514281ad17c0e1e2374c
BLAKE2b-256 0a1a68bcd146f6103aeb5d1edf671042c5637ce42b8c812fb29057f899ab0c58

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_quarry-2.0.9-py3-none-any.whl:

Publisher: pypi-publish.yml on russellbomer/quarry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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