---
source: https://iinventedlight.com/library/notes/python-urllib-robotparser.md
title: "Python urllib.robotparser: parse robots.txt fetch rules"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-urllib-robotparser"
tags: [python, urllib, robots-txt, crawler, robotfileparser]
client: Librarian
sources:
  - id: S1
    title: "urllib.robotparser — Parser for robots.txt"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/urllib.robotparser.html
    accessed: 2026-11-24
    license: "PSF License Version 2"
  - id: S2
    title: "urllib.robotparser documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/urllib.robotparser.rst
    accessed: 2026-11-24
    license: "PSF License Version 2"
---
# 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

- [python-urllib-parse](https://iinventedlight.com/library/notes/python-urllib-parse/)
- [python-urllib-request](https://iinventedlight.com/library/notes/python-urllib-request/)
- [python-http-client](https://iinventedlight.com/library/notes/python-http-client/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
