Harvest public APIs from Python, politely, and be able to prove what you harvested. robots.txt is read per RFC 9309, each origin is paced at the rate you declare, and the retries a server asks for are honoured. A harvest checks every row against every filter its contract lists, splits a capped result set until the server answers in full, and returns a coverage report that names whatever it could not reach.
pip install forktex-crawl
import asyncio
from forktex_crawl import HttpTransport, Politeness, PolitenessSpec, Request
async def main() -> None:
async with HttpTransport() as http:
response = await Politeness(agent="my-bot (+https://example.org/bot)").request(
http, Request(url="https://example.com/"), PolitenessSpec(rate_per_second=1)
)
print(response.status, response.text()[:80])
asyncio.run(main())
Requirements
| Python | 3.14 |
| Nothing else | No service, no database and no global state. Requests go out through httpx; a run is written to a directory you name, or to a sink of your own. |
What you can build
| You want to | Read |
|---|---|
| Fetch pages from a site within its robots.txt and a rate it will tolerate | Fetch a page politely |
| Write down how a site's own API is called, as a reviewable file | Write a contract |
| Harvest a capped API completely, with every filter verified | Harvest an API |
| Know exactly what a run did not cover, and why | Read the coverage report |
| Keep each run's records, raw responses and coverage on disk, and read them back | Keep a run on disk, Read a run back |
| Ask an official API for known keys and learn which it lacks | Ask an official API for known keys |
| Test your own harvest without a network and without waiting | Test a harvest |
How it works
| Concept | What it is |
|---|---|
| Transport | Somewhere a request goes and a response comes back: HttpTransport, or your own. Stateless, so it can be retried, paced and replayed. |
| Politeness | robots.txt, per-origin pacing, retries and redirect hops, applied around a transport. One object, naming who you are, shared by every task. |
| RequestContract | One endpoint: URL, the headers the remote requires, paging, each filter with where its effect must show in a row, how to partition by date, and how hard it may be pushed. |
| Run | What a harvest needs, as one value: transport, politeness, sink, run id and a page limit. |
| Sink | Where records go and exchanges are kept: RunDirectory, or your own. |
| Coverage | What a harvest covered and, by partition, what it did not: truncated, and failed with a kind saying why. |
| CrawlError | Every failure raised, with a kind — the same vocabulary as a recorded failure — and one AppErrorCode per kind. |
Things to know
| A filter is proved, not trusted | A remote can ignore a filter it does not know and answer 200. Every returned row is checked against every filter the contract lists; a contradiction, or a page on which no row shows the filtered field at all, raises CrawlError of kind drift and stops the run. Fixed fields in body_template are sent unchecked. |
| Complete means complete | A non-2xx answer, rows missing from where the contract says they are, fewer rows than the reported total, a page shorter than page_size with more after it, a key batch the remote did not wholly account for, a repeated page or the page limit is a recorded failure, so a failure never shows up as an empty, complete run. A run that asked for nothing — an empty or reversed date range — is empty and complete. A run whose manifest was never written — stopped by drift, or killed — has no manifest(). |
| Your mistake is refused at once | A URL that is not absolute http/https, a header HTTP cannot carry, a request with both a JSON body and a form, or an agent that cannot go on the wire is refused where it is written, never sent and reported as the remote's failure. |
| robots.txt fails closed | An unreachable robots.txt (5xx, no answer) disallows the origin until it is back, per RFC 9309; a 4xx other than 429 allows everything. A harvest records it as a robots failure. |
| Non-2xx is an answer | Politeness.request returns a 404 as a Response; it raises only for robots, throttling, exhausted retries, a body it will not read, more than five redirects, a redirect into a private address or somewhere HTTP cannot go, a request HTTP cannot send, or a closed transport. |
| POST is sent once | Only idempotent methods are retried unless a source's PolitenessSpec sets retry_non_idempotent, and a POST is never replayed to another origin by a redirect. |
| The remote's failure is not your caller's | A failure caused by the remote carries unavailable or failed, never a code that blames whoever called your API. |
| Files name their format | Contracts, manifests and kept exchanges carry "format": 1 and ignore fields they do not know; a later format, or a value outside one of their closed vocabularies, is refused rather than guessed at. |
| No stealth | No user-agent rotation, proxies or fingerprint patching. The agent you pass names you. |
Documentation
| Page | For |
|---|---|
| Guide | Runnable recipes for each way to use it |
| Reference | Every public name, field, error and file format |
| Operating | Robots, rates, redirects, limits, the storage layout, what to watch |
Stability
Semantic versioning covers every name in forktex_crawl.__all__, the nine
error kinds and the AppErrorCode each maps to, and the persisted formats —
contracts, manifests and kept exchanges, at "format": 1. A new field in a
file is a minor change; a new value in one of its closed vocabularies
(Method, AssertKind, paging, end_bound, Kind) is a new format. Anything else —
module paths included — is internal. Changes are listed in the
CHANGELOG.
Contributing
Working on forktex-crawl itself? Start with
docs/development.md. Security issues go to the
address in SECURITY.md.
Licence
AGPL-3.0-or-later, or a commercial licence from FORKTEX S.R.L. See LICENSE and NOTICE.
Metadata
Release files for forktex-crawl 1.0.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 | Provenance | Actions |
|---|---|---|---|---|
| forktex_crawl-1.0.0.tar.gz | 291.3 kB | Without provenance | Details for forktex_crawl-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| forktex_crawl-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for forktex_crawl-1.0.0-py3-none-any.whl |
Total release size: 328.7 kB
Release files / forktex_crawl-1.0.0.tar.gz
| Download URL | forktex_crawl-1.0.0.tar.gz |
|---|---|
| Size | 291.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a91c98c8f646c056a90c9e512041e667bc9c563b1c53a1394f69fa6b75eaaaef
|
|
BLAKE2b-256 checksum How to use checksums |
3007a76d2ace4d1a1a5d1f9f68eb9e6def19d2e14375e9c09b2bd2e4af5cced5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Release files / forktex_crawl-1.0.0-py3-none-any.whl
| Download URL | forktex_crawl-1.0.0-py3-none-any.whl |
|---|---|
| Size | 37.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cc41be87c5af9feb5a9a9526c8884303accef7ddffa22d6705d2c088d4aa2442
|
|
BLAKE2b-256 checksum How to use checksums |
958462a911350ab87a23deb880adda8f11f91f90aa4d5c345fd36bb3ada66f43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Security for forktex-crawl 1.0.0
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.