fastrobots
A blazingly fast robots.txt parser written in Rust with Python bindings. A modern replacement for reppy with extended features.
Features
- Blazingly Fast: Written in Rust, 1M+ parses/sec, 8M+ URL checks/sec
- Modern API: Python 3.10+ with full type hints
- Async Support: Native async/await for HTTP fetching
- Caching: LRU caching with TTL support
- CLI: Command-line tool for quick checks
- RFC Compliant: Supports Allow, Disallow, Crawl-delay, Sitemap, wildcards
Installation
pip install fastrobots
Or with uv:
uv add fastrobots
Quick Start
from fastrobots import Robots
# Parse robots.txt content
robots = Robots.parse("""
User-agent: *
Disallow: /private/
Allow: /public/
Crawl-delay: 1
Sitemap: https://example.com/sitemap.xml
""")
# Check if a path is allowed
robots.allowed("/public/page", "MyBot") # True
robots.allowed("/private/secret", "MyBot") # False
# Get crawl delay
robots.crawl_delay("MyBot") # 1.0
# Get sitemaps
robots.sitemaps # ["https://example.com/sitemap.xml"]
Fetching from URLs
from fastrobots import fetch, fetch_async
# Sync fetching
robots = fetch("https://example.com")
robots.allowed("/path", "MyBot")
# Async fetching
robots = await fetch_async("https://example.com")
Caching
from fastrobots import RobotsCache, AgentCache
# Cache multiple domains
cache = RobotsCache(capacity=100, default_ttl=3600)
allowed = cache.allowed("https://example.com/path", "MyBot")
# Or async
allowed = await cache.allowed_async("https://example.com/path", "MyBot")
# Single-agent cache (more memory efficient)
cache = AgentCache(agent="MyBot", capacity=100)
allowed = cache.allowed("https://example.com/path")
Agent API
from fastrobots import Robots
robots = Robots.parse(content)
agent = robots.agent("Googlebot")
agent.allowed("/path") # True/False
agent.delay # Crawl delay in seconds or None
agent.name # "Googlebot"
CLI Usage
# Check if a URL is allowed
fastrobots check https://example.com/path --agent MyBot
# Parse and display robots.txt
fastrobots parse https://example.com
# Output as JSON
fastrobots parse https://example.com --json
# Benchmark performance
fastrobots benchmark
fastrobots benchmark /path/to/robots.txt
Wildcard Support
Supports * and $ wildcards as per Google's robots.txt specification:
robots = Robots.parse("""
User-agent: *
Disallow: /*.pdf$
Disallow: /search?*q=
""")
robots.allowed("/doc.pdf", "*") # False
robots.allowed("/doc.pdf.bak", "*") # True ($ means end)
robots.allowed("/search?q=test", "*") # False
Performance
fastrobots is designed for high-performance web crawling. Benchmarked against reppy in Docker (Ubuntu 20.04):
| Library | Parse Speed | Check Speed |
|---|---|---|
| fastrobots v0.3.0 | 1,022,875 /sec | 8,025,846 /sec |
| reppy | 159,968 /sec | 2,609,011 /sec |
| Speedup | 6.4x faster | 3.1x faster |
Why fastrobots is faster
- Arena allocation: All path data stored in a single contiguous memory block
- Packed structs: 8-byte rule structs (8 rules per CPU cache line)
- Zero-allocation hot path: No heap allocations during URL checking
- Lock-free design: Immutable after parsing, no synchronization overhead
- Custom SIMD matcher: Uses
memchrfor fast wildcard matching, no regex engine
Additional advantages over reppy
- Actually installs: reppy fails to compile on modern systems (g++ incompatibility)
- Pure Rust: No C++ dependencies, just
cargo build - Thread-safe: Safe to share across threads without locks
API Reference
Robots
Robots.parse(content: str) -> Robots- Parse robots.txt contentrobots.allowed(path: str, user_agent: str) -> bool- Check if path is allowedrobots.crawl_delay(user_agent: str) -> float | None- Get crawl delayrobots.agent(user_agent: str) -> Agent- Get Agent objectrobots.sitemaps: list[str]- List of sitemap URLsrobots.user_agents: list[str]- List of user-agents
Agent
agent.allowed(path: str) -> bool- Check if path is allowedagent.delay: float | None- Crawl delayagent.name: str- User-agent name
RobotsCache
RobotsCache(capacity=100, default_ttl=3600)- Create cachecache.allowed(url, user_agent) -> bool- Check with cachingcache.allowed_async(url, user_agent) -> bool- Async checkcache.clear()- Clear cache
fetch / fetch_async
fetch(url, user_agent=..., timeout=10.0) -> Robots- Fetch robots.txtfetch_async(url, ...) -> Robots- Async fetch
Utility Functions
robots_url(url: str) -> str- Get robots.txt URL for any URLurl_path(url: str) -> str- Extract path from URL
License
MIT License
Metadata
Release files for fastrobots 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastrobots-0.3.0.tar.gz | 39.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastrobots-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.34+ x86-64 | Details |
Total release size: 394.5 kB
Release files / fastrobots-0.3.0.tar.gz
| Download URL | fastrobots-0.3.0.tar.gz |
|---|---|
| Size | 39.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c7c2ba4eaf4f3a93c3df21bbad2bfa5b6fab345e6e612b8c1e8a2fc3c2c4b88
|
|
BLAKE2b-256 checksum How to use checksums |
e830c68e8b6c9c561aa90d2b95e96e1258b500f0360652fa51bb150eec1c8e63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / fastrobots-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | fastrobots-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 354.6 kB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
3fd150d47e95ad1ed23928b03093522c9f43a2777d253e696418f92feb285cd1
|
|
BLAKE2b-256 checksum How to use checksums |
eb0ab8f1a7f101de44c4b910c2afb116b872a1c51b0b20a96b806a086520d34f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|