Python urllib.robotparser: parse robots.txt fetch rules
Answer: This module provides a single class, RobotFileParser, for robots.txt files.
Asking whether a fetch is allowed
The class answers whether a particular user agent can fetch a URL on the site that published the file.
set url stores the URL referring to a robots.txt file.
read fetches that URL and feeds it to the parser.
can fetch returns True if the useragent is allowed to fetch the URL.
Optional robots.txt parameters
crawl delay returns the Crawl-delay value for a useragent, or None when it is missing or invalid.
request rate returns the Request-rate parameter as a named tuple of requests and seconds.
site_maps returns Sitemap parameter contents as a list, or None when syntax is invalid.
mtime returns the time the robots.txt file was last fetched, which helps long-running spiders.
See also
Claims
- id: C1 claim: This module provides a single RobotFileParser class for robots.txt files. source: S1 evidence: "This module provides a single class"
- id: C2 claim: can fetch returns True if the useragent may fetch the URL. source: S1 evidence: "True if the useragent is allowed to fetch"
- id: C3 claim: read fetches the robots.txt URL and feeds it to the parser. source: S1 evidence: "Reads the robots.txt URL and feeds it to the parser"
- id: C4 claim: The class can also parse and answer questions about the file at a URL. source: S2 evidence: "methods to read, parse and answer questions about"
Sources
- [S1] urllib.robotparser — Parser for robots.txt. Python Software Foundation. https://docs.python.org/3/library/urllib.robotparser.html . License: PSF License Version 2. Accessed 2026-11-24.
- [S2] urllib.robotparser documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/urllib.robotparser.rst . License: PSF License Version 2. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, urllib.robotparser — Parser for robots.txt; CPython, urllib.robotparser documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, urllib.robotparser — Parser for robots.txt; CPython, urllib.robotparser documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python urllib.robotparser: parse robots.txt fetch rules." iinventedlight Library, iil:note:r31smx1e, version of 2026-11-24. https://iinventedlight.com/library/notes/python-urllib-robotparser/. License: CC-BY-4.0.
@misc{iil_note_r31smx1e,
author = {{iinventedlight}},
title = {{Python urllib.robotparser: parse robots.txt fetch rules}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/python-urllib-robotparser/},
note = {Permanent ID iil:note:r31smx1e. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-urllib-robotparser.schema.json (schema; CC-BY-4.0)
- python-urllib-robotparser.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-urllib-robotparser.md.