halldyll-core 0.1.0

Core scraping engine for Halldyll - high-performance async web scraper for AI agents
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# ๐Ÿ•ท๏ธ Halldyll


[![Crates.io](https://img.shields.io/crates/v/halldyll-core.svg)](https://crates.io/crates/halldyll-core)
[![Documentation](https://docs.rs/halldyll-core/badge.svg)](https://docs.rs/halldyll-core)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Tests](https://img.shields.io/badge/tests-452%20passing-brightgreen.svg)]()

> **High-performance async web scraper written in Rust with Python bindings, designed for AI agents and cloud deployments.**

## โœจ Features


- ๐Ÿš€ **Blazing Fast** - Async Tokio runtime, connection pooling, 3-6x faster than Python alternatives
- ๐Ÿ”’ **Memory Safe** - Zero unsafe code, guaranteed by Rust's ownership model  
- โš–๏ธ **Polite Crawling** - RFC 9309 robots.txt compliance, adaptive rate limiting per domain
- ๐Ÿ“„ **Smart Extraction** - Main text, JSON-LD, OpenGraph, media assets, outbound links
- ๐Ÿ”„ **Content Dedup** - URL normalization and SimHash-based content deduplication
- ๐ŸŒ **JS Rendering** - Optional Chromium pool for JavaScript-heavy pages
- โ˜๏ธ **Cloud Native** - Kubernetes health probes, Prometheus metrics, graceful shutdown
- ๐Ÿ›ก๏ธ **Resilient** - Circuit breakers per domain, exponential backoff with jitter
- ๐Ÿ **Python Bindings** - Native PyO3 bindings with typed exceptions

## ๐Ÿ“ฆ Architecture


```
halldyll/
โ”œโ”€โ”€ halldyll-core      โ†’ Orchestration, HTTP client, rate limiting, storage (63 tests)
โ”œโ”€โ”€ halldyll-parser    โ†’ HTML parsing, text/link/metadata extraction (220 tests)
โ”œโ”€โ”€ halldyll-media     โ†’ Image, video, audio, document extraction (118 tests)
โ”œโ”€โ”€ halldyll-robots    โ†’ robots.txt parsing and caching (45 tests)
โ””โ”€โ”€ halldyll-python    โ†’ Python bindings via PyO3 (8 tests)
```

**Total: 452 tests passing โœ…**

## ๐Ÿš€ Quick Start


### Rust


Add to your `Cargo.toml`:

```toml
[dependencies]
halldyll-core = "0.1"
tokio = { version = "1", features = ["full"] }
```

```rust
use halldyll_core::{Orchestrator, Config};
use url::Url;

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Use cloud-optimized config (polite, production-ready)
    let config = Config::cloud();
    let orchestrator = Orchestrator::new(config)?;
    
    let url = Url::parse("https://example.com")?;
    let result = orchestrator.scrape(&url).await?;
    
    println!("Title: {:?}", result.document.title);
    println!("Text: {} chars", result.document.main_text.len());
    println!("Links found: {}", result.discovered_links.len());
    
    Ok(())
}
```

### Python


```bash
pip install halldyll
```

```python
from halldyll import scrape, HalldyllScraper, ScraperConfig

# Simple one-liner

result = scrape("https://example.com")
print(result.title, result.text[:200])

# With configuration

config = ScraperConfig.cloud()  # Production-ready settings
with HalldyllScraper(config) as scraper:
    results = scraper.scrape_batch([
        "https://example.com",
        "https://rust-lang.org",
        "https://python.org"
    ])
    
    for r in results:
        if r.success:
            print(f"{r.url}: {r.word_count} words")
        else:
            print(f"{r.url}: Error - {r.error}")
```

## โš™๏ธ Configuration Presets


| Preset | Use Case | Settings |
|--------|----------|----------|
| `Config::default()` | General use | 2 concurrent/domain, 100ms delay, robots.txt on |
| `Config::cloud()` | Production/AI agents | 1 concurrent/domain, 1s delay, 30s timeout, metrics on |
| `Config::polite()` | Sensitive targets | 1 concurrent/domain, 3s delay, strict limits |
| `Config::fast()` | Dev/testing only | 10 concurrent/domain, no robots.txt โš ๏ธ |

### Custom Configuration (Rust)


```rust
use halldyll_core::Config;

let mut config = Config::default();

// HTTP settings
config.fetch.user_agent = "MyBot/1.0".to_string();
config.fetch.total_timeout_ms = 30000;
config.fetch.max_retries = 3;

// Politeness
config.politeness.respect_robots_txt = true;
config.politeness.default_delay_ms = 1000;
config.politeness.max_concurrent_per_domain = 2;

// Extraction
config.parse.extract_json_ld = true;
config.parse.extract_images = true;
config.parse.segment_text = true;
config.parse.chunk_size = 1000;

// Security
config.security.block_private_ips = true;
config.security.max_response_size = 10 * 1024 * 1024; // 10MB
```

### Custom Configuration (Python)


```python
from halldyll import ScraperConfig

config = ScraperConfig(
    user_agent="MyBot/1.0",
    connect_timeout_ms=5000,
    max_concurrent=2,
    respect_robots=True,
    max_depth=5
)
```

## ๐Ÿค– AI Agent Integration


### With LangChain


```python
from langchain.tools import Tool
from halldyll import scrape

def scrape_url(url: str) -> str:
    """Scrape a webpage and return its content."""
    result = scrape(url)
    if result.success:
        return f"Title: {result.title}\n\nContent:\n{result.text[:5000]}"
    return f"Error: {result.error}"

scrape_tool = Tool(
    name="web_scraper",
    description="Scrape a webpage to get its text content. Input: URL",
    func=scrape_url
)

# Use in your agent

agent.tools.append(scrape_tool)
```

### With CrewAI


```python
from crewai import Agent, Task
from halldyll import HalldyllScraper, ScraperConfig

config = ScraperConfig.cloud()
scraper = HalldyllScraper(config)

researcher = Agent(
    role="Web Researcher",
    goal="Extract information from websites",
    tools=[scraper]
)

task = Task(
    description="Research the latest Rust features from rust-lang.org",
    agent=researcher
)
```

### With Azure Agent Framework


```python
from agent_framework import Agent, tool
from halldyll import scrape, HalldyllScraper, ScraperConfig

@tool
def web_scrape(url: str) -> dict:
    """Scrape a webpage and extract its content."""
    result = scrape(url)
    return {
        "title": result.title,
        "text": result.text[:3000],
        "links": result.links[:10],
        "images": result.images[:5]
    }

agent = Agent(
    name="research_agent",
    tools=[web_scrape],
    model="gpt-4o"
)

response = await agent.run("Research and summarize https://example.com")
```

### Batch Processing for RAG


```python
from halldyll import HalldyllScraper, ScraperConfig

config = ScraperConfig.cloud()

with HalldyllScraper(config) as scraper:
    urls = [
        "https://docs.python.org/3/tutorial/",
        "https://doc.rust-lang.org/book/",
        # ... more URLs
    ]
    
    results = scraper.scrape_batch(urls)
    
    # Prepare for vector database
    documents = []
    for r in results:
        if r.has_content:
            documents.append({
                "url": r.url,
                "title": r.title,
                "text": r.text,
                "metadata": r.to_dict()
            })
    
    # Insert into your vector DB (Pinecone, Weaviate, Qdrant, etc.)
    vector_db.upsert(documents)
```

## โ˜๏ธ Cloud Deployment


### Kubernetes


```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: halldyll-scraper
spec:
  replicas: 3
  template:
    spec:
      containers:
      - name: scraper
        image: your-registry/halldyll:latest
        ports:
        - containerPort: 8080
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /readyz
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 5
        resources:
          requests:
            memory: "64Mi"
            cpu: "100m"
          limits:
            memory: "256Mi"
            cpu: "500m"
```

### Health & Metrics Endpoints (Rust)


```rust
use halldyll_core::{
    HealthChecker, HealthMetrics, PrometheusExporter,
    MetricsCollector, GracefulShutdown,
};
use std::sync::Arc;

// Health checker
let health = HealthChecker::default_config();

// GET /healthz - Liveness probe
let liveness = health.liveness();
// Returns: {"status": "healthy", "uptime_secs": 3600, ...}

// GET /readyz - Readiness probe  
let metrics = HealthMetrics {
    success_rate: 0.98,
    avg_latency_ms: 150.0,
    open_circuits: 0,
    memory_mb: Some(128),
    active_requests: 5,
};
let readiness = health.readiness(&metrics);

// GET /metrics - Prometheus format
let collector = MetricsCollector::new();
let exporter = PrometheusExporter::new(&collector);
let prometheus_output = exporter.export();
// Returns: halldyll_requests_total 1234
//          halldyll_success_rate 0.98
//          ...

// Graceful shutdown
let shutdown = Arc::new(GracefulShutdown::default_timeout());
// On SIGTERM: shutdown.wait_for_completion().await
```

### Circuit Breaker


```rust
use halldyll_core::{CircuitBreaker, CircuitBreakerConfig};

// Production config: tolerant, slow recovery
let breaker = CircuitBreaker::new(CircuitBreakerConfig::production());

// Before each request
if !breaker.allow_request("example.com") {
    // Domain circuit is open, skip or queue for later
    continue;
}

// After request
match result {
    Ok(_) => breaker.record_success("example.com"),
    Err(e) if e.is_timeout() => breaker.record_timeout("example.com"),
    Err(e) if e.is_server_error() => breaker.record_server_error("example.com"),
    Err(_) => breaker.record_failure("example.com"),
}

// Monitor open circuits
let open = breaker.get_open_circuits();
println!("Failing domains: {:?}", open);
```

## ๐Ÿ Python Exception Handling


```python
from halldyll import (
    scrape,
    HalldyllError,      # Base exception
    NetworkError,       # Connection, timeout, DNS
    HttpError,          # 4xx, 5xx status codes
    ParseError,         # HTML parsing failures
    RateLimitError,     # 429 Too Many Requests
    RobotsError,        # Blocked by robots.txt
    ValidationError,    # Invalid URL
)

try:
    result = scrape("https://example.com")
except NetworkError as e:
    print(f"Network issue: {e}")
    # Retry with backoff
except RateLimitError as e:
    print(f"Rate limited: {e}")
    # Wait and retry
except RobotsError as e:
    print(f"Blocked by robots.txt: {e}")
    # Skip this URL
except HalldyllError as e:
    print(f"Scraper error: {e}")
```

## ๐Ÿ“Š Extraction Capabilities


| Feature | Description |
|---------|-------------|
| **Main Text** | Boilerplate removal, clean content extraction |
| **Title** | Page title with fallbacks (og:title, h1) |
| **Description** | Meta description, og:description |
| **JSON-LD** | Structured data (Schema.org) |
| **OpenGraph** | Social media metadata |
| **Images** | URLs, dimensions, alt text, lazy-load resolution |
| **Videos** | YouTube, Vimeo, embedded videos |
| **Audio** | Podcast feeds, audio embeds |
| **Links** | Internal/external classification, anchor text |
| **Canonical URL** | Resolved canonical URL |
| **Pagination** | Next/prev page detection |

## ๐Ÿ”ง Advanced Usage


### Standalone Crates


Each crate can be used independently:

```toml
# Just the parser

[dependencies]
halldyll-parser = "0.1"

# Just robots.txt

[dependencies]
halldyll-robots = "0.1"

# Just media extraction

[dependencies]
halldyll-media = "0.1"
```

```rust
// Use parser standalone
use halldyll_parser::HtmlParser;

let html = r#"<html><body><h1>Hello</h1><p>World</p></body></html>"#;
let parser = HtmlParser::new(html);
let text = parser.extract_text();
let links = parser.extract_links("https://example.com");
```

### Custom User Agent Rotation


```rust
let agents = vec![
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Safari/17.0",
    "Mozilla/5.0 (X11; Linux x86_64) Firefox/121.0",
];

for (i, url) in urls.iter().enumerate() {
    config.fetch.user_agent = agents[i % agents.len()].to_string();
    // ...
}
```

## ๐Ÿ“ˆ Performance


| Metric | Halldyll | Scrapy | Playwright |
|--------|----------|--------|------------|
| Speed (pages/min) | ~500 | ~150 | ~50 |
| Memory (10K pages) | ~50 MB | ~300 MB | ~800 MB |
| Startup time | <100ms | ~2s | ~5s |

## ๐Ÿงช Testing


```bash
# Run all tests (452 tests)

cargo test --workspace

# Run with output

cargo test --workspace -- --nocapture

# Run specific crate

cargo test -p halldyll-parser
cargo test -p halldyll-media
cargo test -p halldyll-robots
```

## ๐Ÿ“ Project Structure


```
halldyll-scrapper/
โ”œโ”€โ”€ Cargo.toml              # Rust workspace
โ”œโ”€โ”€ crates/
โ”‚   โ”œโ”€โ”€ halldyll-core/      # Core scraping engine
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ”œโ”€โ”€ fetch/      # HTTP client, circuit breaker
โ”‚   โ”‚       โ”œโ”€โ”€ observe/    # Metrics, health, shutdown
โ”‚   โ”‚       โ”œโ”€โ”€ storage/    # Dedup, content store
โ”‚   โ”‚       โ””โ”€โ”€ types/      # Config, errors
โ”‚   โ”œโ”€โ”€ halldyll-parser/    # HTML extraction (220 tests)
โ”‚   โ”œโ”€โ”€ halldyll-media/     # Media extraction (118 tests)
โ”‚   โ”œโ”€โ”€ halldyll-robots/    # robots.txt (45 tests)
โ”‚   โ””โ”€โ”€ halldyll-python/    # PyO3 bindings
โ”œโ”€โ”€ examples/               # Usage examples
โ””โ”€โ”€ README.md
```

## ๐Ÿ“„ License


MIT License - see [LICENSE](LICENSE) file.

## ๐Ÿ‘ค Author


**Geryan Roy**  
- Email: geryan.roy@icloud.com
- GitHub: [@Mr-soloDev]https://github.com/Mr-soloDev

## ๐Ÿ”— Links


- **Repository**: [github.com/Mr-soloDev/halldyll-Scrapper]https://github.com/Mr-soloDev/halldyll-Scrapper
- **Crates.io**: [crates.io/crates/halldyll-core]https://crates.io/crates/halldyll-core
- **Documentation**: [docs.rs/halldyll-core]https://docs.rs/halldyll-core