Protego
Overview
Protego is a pure-Python robots.txt parser with support for modern conventions.
Requirements
- Python 2.7 or Python 3.5+
- Works on Linux, Windows, Mac OSX, BSD
Install
To install Protego, simply use pip:
pip install protego
Usage
>>> from protego import Protego
>>> robotstxt = """
... User-agent: *
... Disallow: /
... Allow: /about
... Allow: /account
... Disallow: /account/contact$
... Disallow: /account/*/profile
... Crawl-delay: 4
... Request-rate: 10/1m # 10 requests every 1 minute
...
... Sitemap: http://example.com/sitemap-index.xml
... Host: http://example.co.in
... """
>>> rp = Protego.parse(robotstxt)
>>> rp.can_fetch("http://example.com/profiles", "mybot")
False
>>> rp.can_fetch("http://example.com/about", "mybot")
True
>>> rp.can_fetch("http://example.com/account", "mybot")
True
>>> rp.can_fetch("http://example.com/account/myuser/profile", "mybot")
False
>>> rp.can_fetch("http://example.com/account/contact", "mybot")
False
>>> rp.crawl_delay("mybot")
4.0
>>> rp.request_rate("mybot")
RequestRate(requests=10, seconds=60, start_time=None, end_time=None)
>>> list(rp.sitemaps)
['http://example.com/sitemap-index.xml']
>>> rp.preferred_host
'http://example.co.in'
Using Protego with Requests
>>> from protego import Protego
>>> import requests
>>> r = requests.get("https://google.com/robots.txt")
>>> rp = Protego.parse(r.text)
>>> rp.can_fetch("https://google.com/search", "mybot")
False
>>> rp.can_fetch("https://google.com/search/about", "mybot")
True
>>> list(rp.sitemaps)
['https://www.google.com/sitemap.xml']
Documentation
Class protego.Protego:
Properties
sitemaps{list_iterator} A list of sitemaps specified inrobots.txt.preferred_host{string} Preferred host specified inrobots.txt.
Methods
parse(robotstxt_body)Parserobots.txtand return a new instance ofprotego.Protego.can_fetch(url, user_agent)Return True if the user agent can fetch the URL, otherwise return False.crawl_delay(user_agent)Return the crawl delay specified for the user agent as a float. If nothing is specified, return None.request_rate(user_agent)Return the request rate specified for the user agent as a named tupleRequestRate(requests, seconds, start_time, end_time). If nothing is specified, return None.
Metadata
Release files for Protego 0.1.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Protego-0.1.15.tar.gz | 3.2 MB | Without provenance | Details for Protego-0.1.15.tar.gz |
Release files / Protego-0.1.15.tar.gz
| Download URL | Protego-0.1.15.tar.gz |
|---|---|
| Size | 3.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
457238bc55ce864547cc8fe45f9dbfd0161b9d27d94f2eb313cc28f3b9145186
|
|
BLAKE2b-256 checksum How to use checksums |
e84bc72e7d801facc2f519824680b65d76373e6bb289df668dbf8758ea21ff10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.14
|
Security for Protego 0.1.15
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.