Registry / http-networking / robotspy

robotspy

JSON →
library0.13.0pypypi✓ verified 86d ago

robotspy is a Python library for parsing `robots.txt` files, implementing the Robots Exclusion Protocol (REP) as defined by RFC 9309. It allows applications to determine whether a web crawler is permitted to access a given URL path on a server. The library is actively maintained, with the current version being 0.13.0, and has a steady release cadence addressing bug fixes and adherence to Google's parsing behavior.

pip install robotspy
INSTALL
IMPORT
SIG · ROBOTSPY
R
robotspy
http-networkingpythonv0.13.0
Install
1.5s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.13.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RobotFileParser
✓ from robots import RobotFileParser
✗ from robotspy import RobotFileParser
RobotsParser
✓ from robots import RobotsParser
RequestRate
✓ from robots import RequestRate

This example demonstrates how to initialize `RobotFileParser` with a URL, fetch the `robots.txt` file using `read()`, and then check crawling permissions for various user agents and paths using `can_fetch()`. It also shows how to set a custom `user_agent` when initializing the parser, which is used for fetching the `robots.txt` file itself.

from robotspy import RobotFileParser import urllib.request # robotspy uses urllib.request internally # Initialize the parser with the URL of the robots.txt file # Using a well-known site's robots.txt for demonstration parser = RobotFileParser(url="https://www.google.com/robots.txt") try: # Read the robots.txt file from the specified URL # This performs an HTTP GET request to fetch the file. parser.read() print(f"User-agent '*' can fetch /: {parser.can_fetch('*', '/')}") print(f"User-agent 'Googlebot' can fetch /search: {parser.can_fetch('Googlebot', '/search')}") print(f"User-agent 'Googlebot' can fetch /images/search: {parser.can_fetch('Googlebot', '/images/search')}") print(f"User-agent 'AdsBot-Google' can fetch /ads: {parser.can_fetch('AdsBot-Google', '/ads')}") except Exception as e: print(f"Error reading robots.txt: {e}") print("Ensure you have network connectivity and the URL is correct.") # Example of initializing with a custom user agent for fetching the robots.txt file itself # This can help avoid 403 errors from some servers. parser_custom_ua = RobotFileParser(url="https://www.google.com/robots.txt", user_agent="MyCustomCrawler/1.0") try: parser_custom_ua.read() print(f"\nUsing 'MyCustomCrawler/1.0' to fetch, then checking for 'Googlebot': {parser_custom_ua.can_fetch('Googlebot', '/')}") except Exception as e: print(f"Error reading robots.txt with custom user agent: {e}")
Debug
Known issues
gotchaThe interpretation of the '?' character in URL path patterns changed in v0.10.0. Previously, it was treated as a wildcard matching any single character; now it is treated as a literal '?' character, aligning with common `robots.txt` parsing behavior.
fix
Upgrade to `robotspy >= 0.10.0` to ensure correct and standard handling of the '?' character in `robots.txt` disallow/allow rules.
affects: <0.10.0
gotchaThe parser's behavior for handling user-agent product tokens was updated in v0.9.0 to align more closely with Google's robots parser. Older versions might have been more aggressive in discarding parts of a user-agent string if it contained malformed product tokens.
fix
Upgrade to `robotspy >= 0.9.0` for more accurate parsing of `User-agent` lines, especially those with non-standard or partially malformed tokens.
affects: <0.9.0
gotchaPrior to v0.8.0, `robotspy` might have struggled or failed to correctly parse `robots.txt` files that were not UTF-8 encoded. The library was improved to handle non-UTF-8 encodings more robustly.
fix
Upgrade to `robotspy >= 0.8.0` to ensure better compatibility with `robots.txt` files using various character encodings.
affects: <0.8.0
gotchaWhen fetching `robots.txt` files, some websites (e.g., Cloudflare-protected sites) may return a 403 Forbidden error if no user agent is specified in the HTTP request. While `robotspy >= 0.8.0` adds a default user agent, custom or more specific user agents might still be needed.
fix
If you encounter 403 errors, ensure you are using `robotspy >= 0.8.0`. For persistent issues, explicitly set a descriptive user agent when initializing the parser, e.g., `RobotFileParser(url=..., user_agent='MyCoolCrawler/1.0')`.
affects: <0.8.0
Upgrade
Version history
0.13.0latest on PyPI · released Mar 1, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
robotspy — pip install robotspy · libregistry