Skip to main content

ScraperLib

Python Ray License


📚 Documentation

   _____                                 _      _ _     
  / ____|                               | |    (_) |    
 | (___   ___ _ __ __ _ _ __   ___ _ __ | |     _| |__  
  \___ \ / __| '__/ _` | '_ \ / _ \ '__|| |    | | '_ \ 
  ____) | (__| | | (_| | |_) |  __/ |   | |____| | |_) |
 |_____/ \___|_|  \__,_| .__/ \___|_|   |______|_|_.__/ 
                      | |                               
                      |_|                               

==============================================================                                  
         Starting download of ScraperLib
==============================================================                                  

✨ Features

  • Parallel Downloads: Uses Ray to download multiple files simultaneously, maximizing bandwidth and efficiency.
  • 403 Avoidance: Rotates user-agents, sets referer headers, and uses session management to avoid being blocked.
  • Incremental Mode: Optionally skip files already downloaded.
  • Robust State Management: Tracks completed, failed, and skipped downloads with atomic file operations.
  • Progress Visualization: Uses tqdm for beautiful progress bars.
  • Comprehensive Reporting: Generates JSON reports and visualizations (if matplotlib is installed) of download delays and errors.
  • Colorful Console Output: Uses colorama for clear, color-coded logs.
  • Dual Logging: Terminal shows only relevant events (e.g., [DONE] for successful downloads), while the log file contains all attempts, retries, and errors for full traceability.
  • Highly Configurable CLI: All parameters (parallelism, chunk size, retry/backoff, output dirs, etc.) can be set via command line.

📦 Installation

Requires Python 3.12+.

  1. Clone the repository:

    git clone https://github.com/rmonteiro-pereira/Scraper-Lib.git
    cd Scraper-Lib
    
  2. Install dependencies — the project uses uv and ships a committed uv.lock, so this reproduces the exact resolved set:

    uv sync
    

    Or with pip, installing the package itself in editable mode:

    pip install -e .
    

    Main dependencies:

    • ray
    • requests
    • tqdm
    • colorama
    • beautifulsoup4
    • matplotlib
    • numpy
    • portalocker

🚀 Usage

CLI

python -m scraper_lib.cli --url <URL> --patterns .csv .zip --dir data --max-files 10

Main CLI options:

  • --url: Base URL to scrape for files.
  • --patterns: List of file patterns to match (e.g. .csv .zip).
  • --dir: Download directory.
  • --incremental: Enable incremental download state.
  • --max-files: Limit number of files to download.
  • --max-concurrent: Max parallel downloads.
  • --chunk-size: Chunk size for downloads (e.g. 1gb, 10mb, 8 bytes).
  • --initial-delay: Initial delay between retries (seconds).
  • --max-delay: Maximum delay between retries (seconds).
  • --max-retries: Maximum number of download retries.
  • --state-file: Path for download state file.
  • --log-file: Path for main log file.
  • --report-prefix: Prefix for report files.
  • --headers: Path to JSON file with custom headers.
  • --user-agents: Path to text file with custom user agents (one per line).
  • --disable-logging: Disable all logging for production pipelines.
  • --disable-terminal-logging: Disable terminal logging.
  • --dataset-name: Dataset name for banner.
  • --disable-progress-bar: Disable tqdm progress bar.
  • --output-dir: Directory for report PNGs and JSON.
  • --max-old-logs: Max old log files to keep (default: 25, None disables rotation).
  • --max-old-runs: Max old report/png runs to keep (default: 25, None disables rotation).

See all options with:

python -m scraper_lib --help

Programmatic Usage

from ScraperLib import ScraperLib

scraper = ScraperLib(
    base_url: str = "https://example.com/data",
    file_patterns: List[str] = [".csv", ".parquet", ".zip"],
    download_dir: str = "data",
    incremental: bool = True,
    max_files: Optional[int] = 2,
    max_concurrent: Optional[int] = 16,
    chunk_size: Union[str, int] = "10mb",
    initial_delay: float = 1.0,
    max_delay: float = 60.0,
    max_retries: int = 5,
    dataset_name: Optional[str] = "MY DATASET"
)
scraper.run()

🛡️ Anti-Blocking Protocols

  • User-Agent Rotation: Randomizes user-agent strings on each request and after 403 errors.
  • Referer Header: Sets a realistic referer to mimic browser behavior.
  • Session Management: Uses a new HTTP session for each attempt.
  • Exponential Backoff: Waits longer between retries to avoid rate-limiting.

📊 Reporting

After execution, a summary is printed to the console and a detailed report is saved as a JSON file. If matplotlib is installed, visualizations of download delays are also generated.


🧪 Testing

To run all tests:

pytest tests

📝 Project Structure

.
├── src/
│   ├── __init__.py             # Makes src a package
│   ├── scraper_lib.py          # Main library
│   ├── DownloadState.py        # Download state management
│   ├── CustomLogger.py         # Custom logger
├── example.py                  # Example usage (runnable from root)
├── pyproject.toml              # Project metadata and dependencies
├── uv.lock                     # Locked, reproducible dependency set
├── output/
│   ├── pngs/                   # Download delay analysis PNGs
│   └── reports/                # Download reports (JSON)
├── data/                       # Downloaded files
├── logs/                       # Log files
├── state/                      # Download state (auto-generated)
├── tests/                      # Unit tests

🤝 Contributing

Pull requests and suggestions are welcome! Please open an issue or submit a PR.


📄 License

This project is licensed under the MIT License.


📬 Contact

Questions or suggestions? Open an issue or contact rmonteiropereira1@gmail.com.


Happy data hunting with ScraperLib! 🚀

Metadata

Release files for Scraper-Lib-RMP 0.2.314

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Scraper-Lib-RMP 0.2.314
File Size Uploaded
scraper_lib_rmp-0.2.314.tar.gz 25.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Scraper-Lib-RMP 0.2.314
File Interpreter ABI Platform
scraper_lib_rmp-0.2.314-py3-none-any.whl Python 3 none any Details

Total release size: 46.7 kB

Release files / scraper_lib_rmp-0.2.314.tar.gz

Download URL scraper_lib_rmp-0.2.314.tar.gz
Size 25.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8c02fda8604405abd49215e90a0de3d14b20c643ec1787622617f707d3aad6ac
BLAKE2b-256 checksum
How to use checksums
d7282f3e50fb4207892a7015e3a7c738128c9bd768e101037d40815920a0c2ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.

Transparency log

Release files / scraper_lib_rmp-0.2.314-py3-none-any.whl

Download URL scraper_lib_rmp-0.2.314-py3-none-any.whl
Size 21.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67ff76b5698022413aa11654ce98179a78b74d8e94ba4def0f2c1a348a942b23
BLAKE2b-256 checksum
How to use checksums
38e2f06f298d59db4bb1930e4d77afb9c961047837486c7586ee77c30c6817e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.314 This release

2 release files

0.2.99

2 release files

0.2.98

2 release files

0.2.97

2 release files

0.2.96

2 release files

0.2.95

2 release files

0.2.94

2 release files

0.2.93

2 release files

0.2.92

2 release files

0.2.91

2 release files

0.2.90

2 release files

0.2.89

2 release files

0.2.88

2 release files

0.2.87

2 release files

0.2.86

2 release files

0.2.85

2 release files

0.2.84

2 release files

0.2.83

2 release files

0.2.82

2 release files

0.2.81

2 release files

0.2.80

2 release files

0.2.79

2 release files

0.2.78

2 release files

0.2.77

2 release files

0.2.76

2 release files

0.2.75

2 release files

0.2.74

2 release files

0.2.73

2 release files

0.2.72

2 release files

0.2.71

2 release files

0.2.70

2 release files

0.2.69

2 release files

0.2.68

2 release files

0.2.67

2 release files

0.2.66

2 release files

0.2.65

2 release files

0.2.64

2 release files

0.2.63

2 release files

0.2.62

2 release files

0.2.61

2 release files

0.2.60

2 release files

0.2.59

2 release files

0.2.58

2 release files

0.2.57

2 release files

0.2.56

2 release files

0.2.55

2 release files

0.2.54

2 release files

0.2.53

2 release files

0.2.52

2 release files

0.2.51

2 release files

0.2.50

2 release files

0.2.49

2 release files

0.2.48

2 release files

0.2.47

2 release files

0.2.46

2 release files

0.2.45

2 release files

0.2.44

2 release files

0.2.43

2 release files

0.2.42

2 release files

0.2.41

2 release files

0.2.40

2 release files

0.2.39

2 release files

0.2.38

2 release files

0.2.37

2 release files

0.2.36

2 release files

0.2.35

2 release files

0.2.34

2 release files

0.2.33

2 release files

0.2.32

2 release files

0.2.31

2 release files

0.2.30

2 release files

0.2.29

2 release files

0.2.28

2 release files

0.2.27

2 release files

0.2.26

2 release files

0.2.25

2 release files

0.2.24

2 release files

0.2.23

2 release files

0.2.22

2 release files

0.2.21

2 release files

0.2.20

2 release files

0.2.19

2 release files

0.2.18

2 release files

0.2.17

2 release files

0.2.16

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page