Metadata-Version: 2.4
Name: spydra
Version: 2.0.0
Summary: Spydra — Undetectable AI-native web scraping. Distributed crawling, advanced anti-bot bypass, LLM-powered extraction.
Home-page: https://github.com/D4Vinci/Spydra
Author: Karim Shoair
Author-email: YukiStackAI <vishwakarmashubham.2503@gmail.com>
License: BSD 3-Clause License
        
        Copyright (c) 2024, Karim shoair
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Homepage, https://github.com/YukiStackAI/spydra
Project-URL: Documentation, https://spydra.readthedocs.io
Project-URL: Repository, https://github.com/YukiStackAI/spydra
Project-URL: Bug Tracker, https://github.com/YukiStackAI/spydra/issues
Keywords: web-scraping,ai,llm,playwright,anti-bot,fingerprint,distributed,crawler,captcha,cloudflare,stealth
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: lxml>=6.0.3
Requires-Dist: cssselect>=1.4.0
Requires-Dist: orjson>=3.11.8
Requires-Dist: tld>=0.13.2
Requires-Dist: w3lib>=2.4.1
Requires-Dist: typing_extensions
Provides-Extra: fetchers
Requires-Dist: click>=8.3.0; extra == "fetchers"
Requires-Dist: curl_cffi>=0.15.0; extra == "fetchers"
Requires-Dist: playwright==1.58.0; extra == "fetchers"
Requires-Dist: patchright==1.58.2; extra == "fetchers"
Requires-Dist: browserforge>=1.2.4; extra == "fetchers"
Requires-Dist: apify-fingerprint-datapoints>=0.12.0; extra == "fetchers"
Requires-Dist: msgspec>=0.21.1; extra == "fetchers"
Requires-Dist: anyio>=4.13.0; extra == "fetchers"
Requires-Dist: protego>=0.6.0; extra == "fetchers"
Provides-Extra: ai
Requires-Dist: mcp>=1.27.0; extra == "ai"
Requires-Dist: markdownify>=1.2.0; extra == "ai"
Requires-Dist: spydra[fetchers]; extra == "ai"
Provides-Extra: shell
Requires-Dist: IPython>=8.37; extra == "shell"
Requires-Dist: markdownify>=1.2.0; extra == "shell"
Requires-Dist: spydra[fetchers]; extra == "shell"
Provides-Extra: ai-extract
Requires-Dist: openai>=1.0.0; extra == "ai-extract"
Requires-Dist: anthropic>=0.25.0; extra == "ai-extract"
Requires-Dist: pydantic>=2.0.0; extra == "ai-extract"
Requires-Dist: spydra[fetchers]; extra == "ai-extract"
Provides-Extra: antibot
Requires-Dist: requests>=2.31.0; extra == "antibot"
Requires-Dist: spydra[fetchers]; extra == "antibot"
Provides-Extra: distributed
Requires-Dist: redis>=5.0.0; extra == "distributed"
Requires-Dist: httpx>=0.27.0; extra == "distributed"
Requires-Dist: spydra[fetchers]; extra == "distributed"
Provides-Extra: all
Requires-Dist: spydra[ai,ai-extract,antibot,distributed,shell]; extra == "all"
Dynamic: license-file

<div align="center">

<img src="docs/assets/logo.png" width="180" alt="Spydra Logo"/>

# 🕷 Spydra

**Undetectable AI-native web scraping framework**

*Distributed crawling · Advanced anti-bot bypass · LLM-powered extraction*

[![PyPI](https://img.shields.io/pypi/v/spydra.svg?color=brightgreen&label=pypi)](https://pypi.org/project/spydra/)
[![Python](https://img.shields.io/pypi/pyversions/spydra)](https://pypi.org/project/spydra/)
[![License: BSD](https://img.shields.io/badge/license-BSD-blue.svg)](LICENSE)
[![Stars](https://img.shields.io/github/stars/YukiStackAI/spydra?style=social)](https://github.com/YukiStackAI/spydra)

</div>

---

## Install from GitHub

```bash
# Latest stable
pip install git+https://github.com/YukiStackAI/spydra.git

# With browser engines (recommended)
pip install "git+https://github.com/YukiStackAI/spydra.git#egg=spydra[fetchers]"

# AI-native extraction
pip install "git+https://github.com/YukiStackAI/spydra.git#egg=spydra[ai-extract]"

# Anti-bot bypass
pip install "git+https://github.com/YukiStackAI/spydra.git#egg=spydra[antibot]"

# Distributed crawling
pip install "git+https://github.com/YukiStackAI/spydra.git#egg=spydra[distributed]"

# Everything
pip install "git+https://github.com/YukiStackAI/spydra.git#egg=spydra[all]"
```

Or clone and install locally:
```bash
git clone https://github.com/YukiStackAI/spydra.git
cd spydra
pip install -e ".[all]"
```

---

## What is Spydra?

Spydra is a Python web scraping framework with three new superpowers on top of a battle-tested core:

| | Feature | What it does |
|---|---|---|
| 🤖 | **AI-native extraction** | Describe data in English — Spydra extracts it using an LLM |
| 🛡 | **Advanced anti-bot bypass** | Dynamic JS fingerprints, human behavior emulation, CAPTCHA solving |
| ⚡ | **Distributed crawling** | Redis-backed worker pools, stream results to JSON / CSV / webhooks |

---

## Core features (original)

### Fast HTTP scraping

```python
from spydra import Fetcher

page = Fetcher.get("https://quotes.toscrape.com/")
for quote in page.css(".quote"):
    print(quote.css("span.text::text").get())
    print(quote.css("small.author::text").get())
```

### Cloudflare / bot-protected sites

```python
from spydra import StealthyFetcher

page = StealthyFetcher.fetch("https://protected-site.com")
print(page.status)  # 200
```

### JavaScript-rendered pages

```python
from spydra import DynamicFetcher

page = DynamicFetcher.fetch("https://spa-site.com", wait_selector=".results")
data = page.css(".product-title::text").getall()
```

### Full spider with auto-pagination

```python
from spydra.spiders.spider import Spider
from spydra.spiders.request import Request

class QuoteSpider(Spider):
    name = "quotes"
    start_urls = ["https://quotes.toscrape.com/"]

    async def parse(self, response):
        for quote in response.css(".quote"):
            yield {
                "text":   quote.css("span.text::text").get(),
                "author": quote.css("small.author::text").get(),
                "tags":   quote.css("a.tag::text").getall(),
            }
        next_page = response.css("li.next a::attr(href)").get()
        if next_page:
            yield Request(response.urljoin(next_page))

result = QuoteSpider().start()
print(f"Scraped {len(result.items)} quotes")
```

---

## 🤖 Feature 1 — AI-native extraction

```python
from spydra.ai import LLMExtractor

# Works with OpenAI, Anthropic, or local Ollama
extractor = LLMExtractor(provider="openai", model="gpt-4o-mini")

result = extractor.extract(
    url="https://quotes.toscrape.com/",
    instruction="Get all quotes with author name and tags",
)
for item in result.items:
    print(item)
# → [{"quote": "...", "author": "Einstein", "tags": [...]}, ...]

result.to_json("quotes.json")
```

**Auto-generate a Pydantic schema from any URL:**

```python
from spydra.ai import SchemaInferrer

schema = SchemaInferrer(provider="openai").infer("https://books.toscrape.com/")
print(schema.json_schema())      # → {"type": "object", "properties": {...}}
BookModel = schema.to_pydantic() # → live Pydantic v2 model
```

**Natural-language CSS selectors:**

```python
from spydra.ai import AISelector
from spydra import Fetcher

page     = Fetcher.get("https://quotes.toscrape.com/")
elements = AISelector(provider="openai").select(page, "all author names")
```

Supported providers: `openai` · `anthropic` · `ollama`

---

## 🛡 Feature 2 — Advanced anti-bot bypass

```python
from spydra.antibot import FingerprintRotator, BehaviorEmulator, BehaviorProfile, CaptchaSolver

# 1. Rotate JS fingerprint (Canvas, WebGL, AudioContext, screen, platform)
rotator = FingerprintRotator(strategy="random")
profile  = rotator.generate()
page = StealthyFetcher.fetch(url, extra_headers=profile.extra_headers)

# Inject into Playwright page
rotator.patch_playwright_page(playwright_page, profile)

# 2. Human behavioral emulation
emulator = BehaviorEmulator(BehaviorProfile(scroll=True, mouse_jitter=True, typing_wpm=52))
emulator.goto(playwright_page, "https://example.com/login")
emulator.type_text(playwright_page, "input#email", "user@example.com")
emulator.click(playwright_page, "button[type=submit]")

# 3. CAPTCHA solving
solver = CaptchaSolver(provider="2captcha", api_key="YOUR_KEY")
solver.auto_solve(playwright_page)             # auto-detect any CAPTCHA
solver.solve_recaptcha_v2("6Le-...", page_url) # explicit
solver.solve_hcaptcha("sitekey", page_url)
solver.solve_turnstile("sitekey", page_url)
```

---

## ⚡ Feature 3 — Distributed crawling

```python
from spydra.distributed import DistSpider, JsonSink
from spydra.spiders.request import Request

class QuoteSpider(DistSpider):
    name       = "quotes"
    start_urls = ["https://quotes.toscrape.com/"]
    redis_url  = "redis://localhost:6379/0"
    workers    = 4                          # parallel worker processes
    sink       = JsonSink("quotes.jsonl")   # real-time streaming output

    async def parse(self, response):
        for quote in response.css(".quote"):
            yield {
                "text":   quote.css("span.text::text").get(),
                "author": quote.css("small.author::text").get(),
            }
        nxt = response.css("li.next a::attr(href)").get()
        if nxt:
            yield Request(response.urljoin(nxt))

QuoteSpider().start()
```

**Multi-machine crawl:**

```bash
# Start Redis first
docker run -d -p 6379:6379 redis

# Machine A — seeds queue + 2 workers
python -m spydra.distributed.worker myspider:QuoteSpider --workers 2 --redis redis://HOST:6379

# Machine B — joins same queue
python -m spydra.distributed.worker myspider:QuoteSpider --workers 2 --redis redis://HOST:6379
```

**Available sinks:**

```python
from spydra.distributed import JsonSink, CsvSink, WebhookSink

JsonSink("out.jsonl")                              # streaming JSON Lines
JsonSink("out.json", format="json", indent=True)  # pretty JSON array
CsvSink("out.csv")                                 # CSV (headers auto-detected)
WebhookSink("https://api.example.com/ingest",
            batch_size=50,
            headers={"Authorization": "Bearer TOKEN"})
```

---

## Install options

| Command | What you get |
|---|---|
| `pip install "git+https://github.com/YukiStackAI/spydra.git"` | Core only |
| `pip install "git+...#egg=spydra[fetchers]"` | + all fetchers + Spider |
| `pip install "git+...#egg=spydra[ai-extract]"` | + LLM extraction |
| `pip install "git+...#egg=spydra[antibot]"` | + fingerprint + CAPTCHA |
| `pip install "git+...#egg=spydra[distributed]"` | + Redis workers + sinks |
| `pip install "git+...#egg=spydra[all]"` | Everything |

---

## Requirements

- Python 3.10+
- Redis *(distributed feature only)* — `docker run -d -p 6379:6379 redis`

## License

BSD License — see [LICENSE](LICENSE)
