Skip to content

API reference

Generated from the source with mkdocstrings.

Client

bibliofabric.softwareheritage.SoftwareHeritageClient

Client for the Software Heritage archive Web API.

The API needs no credentials. The client paces itself to one request every 30 seconds by default, the budget the anonymous limit of 120 requests per hour admits, and sends Accept: application/json on every request.

origins: OriginsResource cached property

The origin, origins, and origin visit routes.

snapshots: SnapshotsResource cached property

The snapshot route with its branch pages.

revisions: RevisionsResource cached property

The revision routes: revisions, their log, and root directory.

releases: ReleasesResource cached property

The release route.

directories: DirectoriesResource cached property

The directory routes: entry lists and path lookups.

contents: ContentsResource cached property

The content routes: blob metadata, derived facts, and raw bytes.

known: KnownResource cached property

The /known/ existence check for SWHIDs.

resolve: ResolveResource cached property

The /resolve/ route for SWHIDs.

raw: RawResource cached property

The /raw/ route: the internal bytes of an archive object.

extid: ExtidResource cached property

The external identifier routes.

provenance: ProvenanceResource cached property

The provenance routes.

metadata: MetadataResource cached property

The intrinsic, extrinsic, raw, and citation metadata routes.

vault: VaultResource cached property

The vault routes: cooking status and cooked bundle downloads.

saves: SavesResource cached property

The save request routes.

forges: ForgeRequestsResource cached property

The add-forge request routes.

stats: StatsResource cached property

The archive statistics route.

ping() -> bool async

Return True when the API answers its health check with pong.

The sync twin SoftwareHeritageSyncClient mirrors the client method for method and exports from the same module: from bibliofabric.softwareheritage import SoftwareHeritageSyncClient.

Settings

bibliofabric.softwareheritage.SoftwareHeritageSettings

Software Heritage-specific client settings.

Inherits timeout, max_retries, max_retry_wait, max_concurrency, max_requests_per_second, rate_limits, user_agent, and mailto from :class:bibliofabric.config.BaseApiSettings. The defaults pace the client to one request every 30 seconds, one request in flight, because the archive API admits 120 anonymous requests per hour. The API needs no credentials; authenticated access (for example the graph API on graph.softwareheritage.org) is not part of this client.

Resources

Each resource inherits the generic operations from bibliofabric.Resource (get, search, iterate, collect, first, count). Only the members that Software Heritage changes or adds are shown here.

bibliofabric.softwareheritage.OriginsResource

Client for the origin, origins, origin visit, and origin search routes.

The search pages through the Link header: the next_cursor of a page is the absolute URL of the following page, and the total comes from the X-Total-Count header, which only the search route sends.

get(id: str | int, *, select: Sequence[str] | None = None, params: Mapping[str, Any] | None = None) -> OriginSummary async

Fetch one origin by URL; an unknown origin raises NotFoundError.

search(filters: BaseModel | Mapping[str, Any] | None = None, *, query: str | None = None, sort: str | Sequence[str] | None = None, select: Sequence[str] | None = None, page: int | None = None, page_size: int | None = None, cursor: str | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None, params: Mapping[str, Any] | None = None, with_visit: bool | None = None, visit_type: str | None = None, use_ql: bool | None = None) -> Page[OriginSummary] async

Fetch one page of origins whose URL matches query.

query is required and case-insensitive upstream. page_size is the page size (upstream limit, bounded to 1000). cursor is the next_cursor of an earlier page; the search then resumes from that page URL. The total comes from the X-Total-Count header.

iterate(filters: BaseModel | Mapping[str, Any] | None = None, *, query: str | None = None, sort: str | Sequence[str] | None = None, select: Sequence[str] | None = None, page_size: int | None = None, limit: int | None = None, cursor: str | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None, on_page: Callable[[int, str | None], Any] | None = None, params: Mapping[str, Any] | None = None, with_visit: bool | None = None, visit_type: str | None = None, use_ql: bool | None = None) -> AsyncIterator[OriginSummary]

Yield origin summaries page by page.

With query the walk goes through the search route and honors with_visit, visit_type, use_ql, and page_size (the upstream limit). Without query it walks the plain /origins/ listing, where page_size is the upstream origin_count. The walk stops at limit origins or when the Link header runs out.

collect(filters: BaseModel | Mapping[str, Any] | None = None, *, query: str | None = None, sort: str | Sequence[str] | None = None, select: Sequence[str] | None = None, page_size: int | None = None, limit: int | None = None, cursor: str | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None, on_page: Callable[[int, str | None], Any] | None = None, params: Mapping[str, Any] | None = None, with_visit: bool | None = None, visit_type: str | None = None, use_ql: bool | None = None) -> list[OriginSummary] async

Collect :meth:iterate output into a list, bounded by limit.

first(filters: BaseModel | Mapping[str, Any] | None = None, *, query: str | None = None, sort: str | Sequence[str] | None = None, select: Sequence[str] | None = None, page_size: int | None = 1, cursor: str | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None, params: Mapping[str, Any] | None = None, with_visit: bool | None = None, visit_type: str | None = None, use_ql: bool | None = None) -> OriginSummary | None async

Return the first origin whose URL matches query, or None.

count(filters: BaseModel | Mapping[str, Any] | None = None, *, query: str | None = None, params: Mapping[str, Any] | None = None) -> int async

Return the total of a search from its X-Total-Count header.

Only the search route reports a total; query is required.

visits(origin_url: str, *, page_size: int | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None) -> Page[OriginVisit] async

Fetch one page of the visits of an origin, newest first.

page_size travels as the upstream per_page parameter; the next_cursor of the page is the URL of the following page.

iterate_visits(origin_url: str, *, page_size: int | None = None, limit: int | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None, on_page: Callable[[int, str | None], Any] | None = None) -> AsyncIterator[OriginVisit]

Yield the visits of an origin, newest first, page by page.

visit(origin_url: str, visit_id: int) -> OriginVisit async

Fetch one visit of an origin through GET /origin/{url}/visit/{id}/.

visit_latest(origin_url: str, *, require_snapshot: bool | None = None, visit_type: str | None = None) -> OriginVisit async

Fetch the latest visit of an origin.

require_snapshot=True asks for a visit that carries a snapshot; visit_type filters by visit type.

search_metadata(fulltext: str, *, limit: int | None = None) -> Page[OriginSummary] async

Search origins by their CodeMeta metadata full text.

The route ranks matches, reports no total, and sends no Link header, so one call returns everything the archive matches.

bibliofabric.softwareheritage.SnapshotsResource

Client for the /snapshot/ route.

The route serves branches in pages (1000 by default) and announces the next branch page through the Link header, so the branches dict of a page is one slice of a possibly larger snapshot.

get(id: str | int, *, select: Sequence[str] | None = None, params: Mapping[str, Any] | None = None, branches_from: str | None = None, branches_count: int | None = None, target_types: str | None = None) -> Snapshot async

Fetch one branch page of a snapshot.

branches_from skips branches whose name sorts before it, branches_count bounds the page (default 1000), and target_types filters branches by a comma-separated list of target types (content, directory, revision, release, snapshot, alias). Branches beyond the page come through :meth:iterate_branches, which follows the Link header.

iterate_branches(id: str | int, *, branches_count: int | None = None, target_types: str | None = None, limit: int | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None, on_page: Callable[[int, str | None], Any] | None = None) -> AsyncIterator[Branch]

Yield the branches of a snapshot across all of its pages.

The walk follows the Link header; each yielded branch carries its name in name. limit caps the number of yielded branches.

search(filters: Any = None, *, query: str | None = None, **kwargs: Any) -> Page[Snapshot] async

Unsupported: the snapshot route has no search.

bibliofabric.softwareheritage.RevisionsResource

Client for the /revision/ routes: revisions, their log, and root directory.

log(id: str | int, *, limit: int | None = None) -> list[Revision] async

Return the commit log heading to a revision.

The route serves one array in BFS order; limit bounds the BFS traversal (upstream default 10, capped at 1000). The route sends no Link header, so long logs need one call per starting revision.

directory(id: str | int) -> RevisionDirectory async

Return the root directory entries of a revision.

directory_entry(id: str | int, path: str) -> DirectoryEntry async

Return the entry a relative path points to under the root directory.

A file path answers with the content metadata of the file (checksums and length); a directory path answers with its entry object.

vulnerabilities(id: str | int) -> list[dict[str, Any]] async

Return the known vulnerabilities affecting a revision.

Most revisions answer 404; the route exists for revisions that a vulnerability report covers, and each answer item keeps the raw advisory shape.

bibliofabric.softwareheritage.ReleasesResource

Client for the /release/ route.

bibliofabric.softwareheritage.DirectoriesResource

Client for the /directory/ routes.

The route answers a directory as the array of its entries, and a directory plus path as the single entry the path resolves to.

entries(id: str | int) -> list[DirectoryEntry] async

Return the entries of a directory.

entry(id: str | int, path: str) -> DirectoryEntry async

Return the entry a relative path resolves to under a directory.

A file path answers with the content metadata of the file (checksums and length); a directory path answers with its entry object.

bibliofabric.softwareheritage.ContentsResource

Client for the /content/ routes: blob metadata and derived facts.

raw(id: str | int, dest: Path | str) -> Path async

Download the raw bytes of a content object to dest.

Returns the path the bytes landed on; an interrupted download leaves no partial file.

filetype(id: str | int) -> Filetype async

Return the detected MIME type of a content object.

language(id: str | int) -> Language async

Return the detected programming language of a content object.

license(id: str | int) -> License async

Return the detected license of a content object.

bibliofabric.softwareheritage.KnownResource

Client for the /known/ route.

The route takes a JSON array of SWHIDs and answers one known flag per SWHID, keyed by the SWHID as sent.

check(swhids: Sequence[str]) -> dict[str, KnownCheck] async

Check which SWHIDs are present in the archive.

One request carries at most 1000 SWHIDs; a longer input is split into chunks of that size. The result maps every input SWHID to its KnownCheck.

bibliofabric.softwareheritage.ResolveResource

Client for the /resolve/ route.

bibliofabric.softwareheritage.RawResource

Client for the /raw/ route.

The route serves the internal representation of an archive object as an octet stream, so its only operation is a download to a path.

download(swhid: str, dest: Path | str) -> Path async

Download the raw object bytes of a SWHID to dest.

bibliofabric.softwareheritage.ExtidResource

Client for the /extid/ routes.

by_extid(extid_type: str, extid_format: str, extid: str, *, extid_version: int | None = None) -> Extid async

Fetch the archived object an external identifier targets.

extid_format is base64url, hex, or raw; the value travels encoded in the path as extid/{type}/{format}:{value}/. extid_version is required by the Guix and Nix identifier types.

targets(swhid: str, *, extid_type: str | None = None, extid_format: str | None = None, extid_version: int | None = None) -> list[Extid] async

Return the external identifiers that target an archived object.

extid_type and extid_version only travel together, as the route requires; extid_format defaults to hex upstream.

bibliofabric.softwareheritage.ProvenanceResource

Client for the /provenance/ routes.

Both routes answer strings: a qualified SWHID that names the release or revision anchoring the target and the origin that holds it. The routes answer 401 without authentication on the production archive, so anonymous callers see AuthenticationError.

whereis(swhid: str) -> str async

Return the qualified SWHID with provenance info for one core SWHID.

whereare(swhids: Sequence[str]) -> list[str] async

Return the qualified SWHIDs with provenance info for many core SWHIDs.

One request carries the SWHIDs as a JSON array; the answer is an array of qualified SWHIDs in the same order as the input.

bibliofabric.softwareheritage.MetadataResource

Client for the intrinsic, extrinsic, and raw metadata routes.

origin_intrinsic(origin_url: str) -> list[OriginMetadata] async

Return the intrinsic CodeMeta metadata records of an origin.

origin_extrinsic(origin_url: str) -> list[OriginMetadata] async

Return the extrinsic CodeMeta metadata records of an origin.

authorities(target: str) -> list[Authority] async

Return the metadata authorities that provided metadata on a core SWHID.

origin_authorities(origin_url: str) -> list[Authority] async

Return the metadata authorities that provided metadata on an origin.

raw(target: str, *, authority: str, after: str | None = None, limit: int | None = None, page_token: str | None = None) -> Page[RawMetadata] async

Return one page of the raw extrinsic metadata of a core SWHID.

authority is required by the route and formatted as <type> <IRI> (for example forge https://pypi.org/); read the available authorities with :meth:authorities first. after bounds the discovery date from below, limit bounds the page (upstream default 100), and page_token resumes an earlier page through its next_cursor.

citation(target_swhid: str, *, citation_format: str = 'bibtex') -> Citation async

Return a formatted software citation for an object SWHID.

citation_format is bibtex or csl. The route answers 404 when the pointed object carries no citation metadata.

origin_citation(origin_url: str, *, citation_format: str = 'bibtex') -> Citation async

Return a formatted software citation for a software origin.

bibliofabric.softwareheritage.VaultResource

Client for the /vault/ routes.

The routes report the cooking status of a bundle (flat, git-bare, or gitfast) for a SWHID and serve the cooked archive. Cooking itself is a POST write and out of scope: a status call answers 404 until someone requested the cooking, upstream or through the web application.

status(bundle: str, swhid: str) -> VaultTask async

Return the cooking status of one bundle for a SWHID.

download(bundle: str, swhid: str, dest: Path | str) -> Path async

Download the cooked bundle to dest.

The route answers 404 while the bundle has not been cooked or is still cooking.

bibliofabric.softwareheritage.SavesResource

Client for the /origin/save/ routes.

The read routes report the status of save requests; creating a save request is a POST write and out of scope. The bulk routes answer 401 without authentication.

get(id: str | int, *, select: Any = None, params: Any = None) -> SaveRequest async

Return one save request by its numeric id.

for_origin(visit_type: str, origin_url: str) -> list[SaveRequest] async

Return every save request submitted for an origin.

visit_type is one of bzr, cvs, git, hg, svn, or tarball. The route answers 404 when no save request exists for the origin.

iterate_bulk_requests(*, page_size: int | None = None, limit: int | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None, on_page: Callable[[int, str | None], Any] | None = None) -> AsyncIterator[BulkSaveRequest]

Yield the save bulk requests of the authenticated user.

page_size travels as the upstream per_page parameter; the walk follows the Link header. The route answers 401 without authentication.

bulk_request(request_id: str, *, page_size: int | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None) -> Page[BulkOriginStatus] async

Return one page of the origin loading statuses of a save bulk request.

page_size travels as the upstream per_page parameter; the next_cursor of the page is the URL of the following page. The route answers 401 without authentication and 403 for a request the user did not submit.

bibliofabric.softwareheritage.ForgeRequestsResource

Client for the /add-forge/request/ routes.

The read routes report the status of add-forge-now requests; creating a request is a POST write and out of scope.

get(id: str | int, *, select: Any = None, params: Any = None) -> AddForgeRequest async

Return one add-forge request by its numeric id.

The route answers 404 for a request id nobody can read anonymously.

list_requests(*, limit: int | None = None) -> list[AddForgeRequest] async

Return the most recent add-forge requests across all forges.

The route answers a plain list; limit bounds the number of rows the archive returns.

bibliofabric.softwareheritage.StatsResource

Client for the /stat/counters/ route.

get(id: str | int = '', *, select: Any = None, params: Any = None) -> ArchiveStats async

Return the archive-wide counters (contents, origins, and more).