Skip to content

Upstream quirks

Behavior of the live Software Heritage archive API that shapes how the client works, with the Web API documentation as the reference. Where a quirk affects bibliofabric.softwareheritage, the behavior of the client is noted.

The anonymous rate limit is 120 requests per hour

The archive accepts 120 anonymous requests per hour from one IP and answers 429 with a Retry-After header above that. The client defaults to one request every 30 seconds with one concurrent request, so an hour of steady calls stays inside the limit. If your network holds a token that lifts the limit, raise SOFTWAREHERITAGE_MAX_REQUESTS_PER_SECOND and SOFTWAREHERITAGE_MAX_CONCURRENCY to match; the client itself sends no authentication.

One lookup can cost three requests

GET /origin/{origin_url}/visits/ returns visit summaries without snapshots, so a caller that wants the latest snapshot walks back through older pages. The visit/latest/ route answers with the snapshot id, and the client exposes it as origins.visit_latest().

Origin search, the /origins/ listing, and origin visits answer a list with an RFC 5988 Link header whose next relation is a full absolute URL that already carries the cursor (page_token or last_visit). The metadata search is the exception: it sends no Link header at all, so one call returns everything the route matches. The client parses the header in _next_cursor and sends the absolute URL as the next request; httpx resolves it against the base URL, so the token never has to be rebuilt by hand. When there is no next page the header is absent and the walk stops.

Origin search reports the total number of matches in an X-Total-Count response header, not in the body; the client reads it into page.total. The plain /origins/ listing sends no total, so count() on it is impossible and Page.total stays None.

Errors are plain HTTP statuses with JSON bodies

A missing object answers 404 with {"error": "Resource not found", "reason": "..."} and the client raises NotFoundError. A malformed SWHID in /resolve/ answers 400 and raises APIError; an unrecognized content hash answers 404 like any other missing object. The content facet routes (filetype, language, license) answer 404 when the facet was never computed for a file, for instance a five-byte blob with no detected language. The provenance and save-bulk routes answer 401 for anonymous callers and raise AuthError; the docs describe the payload but an anonymous client cannot observe it.

Objects carry SWHIDs in routes, and routes want the bare id

Routes such as /snapshot/{swhid} accept the core SWHID (swh:1:snp:<hash>); the client strips the swh:1:<type>: prefix before building the path, so snapshots.get("swh:1:snp:...") and the bare hash hit the same URL. Content routes additionally accept computed SWHID qualifiers such as swh:1:cnt:<hash>;origin=<url>. Two routes deviate: /resolve/ requires the full SWHID (a bare hash answers 400), and the citation origin route takes the origin URL in an origin_url query parameter, although the upstream documentation names it target_origin_url.

Snapshots are split across branch pages

A snapshot can hold tens of thousands of branches, so the snapshot body lists one page of branches and points to the next with a Link header. The client walks that header in iterate_branches(); snapshots.get() returns the model with the branches of the first response plus next_branch, and it does not walk silently because the full walk can cost dozens of requests at the anonymous pace.

The vault answers 404 for bundles nobody cooked yet

GET /vault/{bundle}/{swhid}/ reports success for a ready bundle and 404 for one that nobody requested. POST the same route to ask for a cook; the client leaves the cook call to you because it is a long-running write that anonymous callers often find already done for popular objects. download() streams the bundle from vault/{bundle}/{swhid}/raw/, the URL a ready task reports as its fetch_url.

Deleted and renamed upstream routes

The documentation keeps routes for /vault/directory/ and /vault/revision/gitfast/ under a deprecation note. The client exposes the bundle names through vault.status(bundle, swhid) where bundle is the literal string the archive expects (flat, git-bare, gitfast), so a deprecated bundle still resolves without a dedicated method.

Metadata routes return raw JSON

Intrinsic and extrinsic metadata answers are free-form JSON objects from the deposit and metadata authorities; the client wraps them in OriginMetadata and keeps the unknown keys in model_extra. metadata.raw() pages the /raw-extrinsic-metadata/{target}/ route with page_token links and can filter by authority.