Software Heritage
The Software Heritage client (bibliofabric.softwareheritage) reads the
Software Heritage archive Web API:
software origins, their visits and snapshots, the revision, release,
directory, and content objects of the archive graph, the vault bundles, the
save requests, and the metadata services. Calls return typed Pydantic models
through an async client and a generated sync twin.
Credentials
The archive API needs no credentials. Anonymous clients get 120 requests per
hour, so the client paces itself to one request every 30 seconds with one
concurrent request by default, which never trips that limit. Use of the API
falls under the Software Heritage API terms of use;
the archive serves source code under the license of each original project.
You can raise the pace with SOFTWAREHERITAGE_MAX_REQUESTS_PER_SECOND and
SOFTWAREHERITAGE_MAX_CONCURRENCY (for example when your network holds a
token that lifts the anonymous limit; the client itself sends no
authentication, and the token-only graph API on graph.softwareheritage.org
is out of scope); see the
settings guide. One lookup plus a follow-up can take
a minute at the anonymous pace; plan scripts accordingly.
Quick start
import asyncio
from bibliofabric.softwareheritage import SoftwareHeritageClient
async def main() -> None:
async with SoftwareHeritageClient() as client:
visit = await client.origins.visit_latest("https://github.com/hylang/hy")
print(visit.visit, visit.status, visit.snapshot)
snapshot = await client.snapshots.get(visit.snapshot)
print(sorted(snapshot.branches)[:5])
page = await client.origins.search(query="hylang", page_size=5)
print(page.total, "matching origins")
asyncio.run(main())
1935 full b4a8ee02952ba5c168b1f4b8cd68eea962716c82
['1.3.1', 'HEAD']
377 matching origins
Sync quick start
from bibliofabric.softwareheritage import SoftwareHeritageSyncClient
with SoftwareHeritageSyncClient() as client:
for origin in client.origins.iterate(page_size=3, limit=3):
print(origin.url)
https://github.com/leosanqing/wx-order
https://github.com/LudmilaRCS100/day10
https://github.com/OdatNurd/ruinous-twitch-addons
Use the sync client in scripts, notebooks, or threads; it never starts or touches an event loop. See async and sync clients for when each fits. Both variants take the same parameters and raise the same errors.
What the client offers
| Attribute | Returns | Methods | Notes |
|---|---|---|---|
client.origins |
OriginSummary, OriginVisit |
get, search, iterate, visits, iterate_visits, visit, visit_latest, search_metadata, plus collect, first, count |
get() accepts the raw URL or an swh:1:ori: SWHID |
client.snapshots |
Snapshot |
get, iterate_branches; the search-family helpers raise |
branch pages walk Link headers |
client.revisions |
Revision |
get, log, directory, directory_entry, vulnerabilities |
|
client.releases |
Release |
get and the generic helpers |
|
client.directories |
DirectoryEntry |
entries, entry |
entry() resolves a path inside the directory |
client.contents |
Content |
get, raw, filetype, language, license |
raw() streams bytes to a file |
client.known |
KnownCheck |
check |
posts SWHIDs in chunks of 1000 |
client.resolve |
ResolvedSwhid |
get |
maps a SWHID to its canonical form |
client.raw |
byte streams | download |
serves the object itself, not its metadata |
client.extid |
Extid |
by_extid, targets |
maps external ids to SWHIDs and back |
client.provenance |
plain values | whereis, whereare |
the archive answers anonymous calls with 401 |
client.metadata |
RawMetadata, Authority |
origin_intrinsic, origin_extrinsic, authorities, origin_authorities, raw, citation, origin_citation |
|
client.vault |
VaultTask |
status, download |
bundles are flat, git-bare, or gitfast |
client.saves |
SaveRequest |
get, for_origin, iterate_bulk_requests, bulk_request |
bulk_request needs authentication |
client.forges |
AddForgeRequest |
get, list_requests |
the archive answers 404 for a request id you did not submit |
client.stats |
ArchiveStats |
get |
client.ping() checks the archive answers. The snapshot route is a query on
the branches of one fixed snapshot, not a record search, so snapshots.search
and its search-family siblings raise ConfigurationError; use get() and
iterate_branches() with branches_from, branches_count, and
target_types. sort and select raise ConfigurationError on every
Software Heritage resource because the archive has no such parameters, and
the archive paces itself, so explicit page jumps are refused in favor of
cursor iteration.
Examples
Runnable scripts live in packages/bibliofabric/examples/softwareheritage:
quickstart.py: visits, snapshots, origin search.sync_quickstart.py: the same walk with the sync client.
Next
- Upstream quirks: rate limits, Link-header paging, and other live behavior.
- API reference: every public class generated from the source.