Skip to content

API reference

Generated from the source with mkdocstrings.

Client

bibliofabric.dataverse.DataverseClient

Client for the Dataverse native API and search API.

The default base URL points at the Harvard installation (https://dataverse.harvard.edu/api/v1/); the same API serves every Dataverse installation, so pass base_url (or set DATAVERSE_BASE_URL) to talk to another one.

Public reads need no credentials. With api_key set the client sends X-Dataverse-key on every request, which unlocks private data and the draft versions; the write routes (create dataset, upload file, publish, collection management) are out of scope.

Credentials resolve in the constructor: an explicit api_key argument wins, then :class:DataverseSettings. An empty string forces anonymous access.

search: SearchResource cached property

The search resource client.

dataverses: DataversesResource cached property

The collection resource client.

datasets: DatasetsResource cached property

The dataset resource client.

files: FilesResource cached property

The file resource client.

access: AccessResource cached property

The download resource client.

info: InfoResource cached property

The server info resource client.

metrics: MetricsResource cached property

The metrics resource client.

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

Settings

bibliofabric.dataverse.DataverseSettings

Dataverse-specific client settings.

Inherits timeout, max_retries, max_retry_wait, max_requests_per_second, max_concurrency, rate_limits, user_agent, and mailto from :class:bibliofabric.config.BaseApiSettings. Public reads need no credentials. The base URL is a setting because the same API serves every Dataverse installation; the default points at the Harvard installation.

Resources

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

bibliofabric.dataverse.SearchResource

Client for the /search endpoint.

q is the query string; * matches everything. The type, subtree, fq, and metadata_fields arguments accept one value or a sequence and travel as repeated query parameters. sort reads "field" or "field:asc|desc" over name, date, and score. page is the zero-based start offset and page_size maps to per_page. :attr:Page.meta carries the facet counts of the answer when the query passed show_facets=True.

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, type: Sequence[str] | str | None = None, subtree: Sequence[str] | str | None = None, fq: Sequence[str] | str | None = None, metadata_fields: Sequence[str] | str | None = None, show_facets: bool | None = None, show_relevance: bool | None = None, show_entity_ids: bool | None = None, show_type_counts: bool | None = None, show_collections: bool | None = None) -> Page[SearchResult] async

Fetch one page of search results.

The dataverse, dataset, and file results share one item shape; each type fills a different subset of :class:bibliofabric.dataverse.SearchResult.

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, type: Sequence[str] | str | None = None, subtree: Sequence[str] | str | None = None, fq: Sequence[str] | str | None = None, metadata_fields: Sequence[str] | str | None = None, show_facets: bool | None = None, show_relevance: bool | None = None, show_entity_ids: bool | None = None, show_type_counts: bool | None = None, show_collections: bool | None = None) -> Any

Iterate over every matching item, page by page.

Accepts the same arguments as :meth:search. Iteration stops at limit, on an empty page, or when total_count records were seen. Deep paging past 10,000 answers HTTP 400 upstream.

collect(filters: BaseModel | Mapping[str, Any] | None = None, *, limit: int | None = None, query: str | None = None, sort: str | Sequence[str] | None = None, select: Sequence[str] | None = None, page_size: 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, type: Sequence[str] | str | None = None, subtree: Sequence[str] | str | None = None, fq: Sequence[str] | str | None = None, metadata_fields: Sequence[str] | str | None = None, show_facets: bool | None = None, show_relevance: bool | None = None, show_entity_ids: bool | None = None, show_type_counts: bool | None = None, show_collections: bool | None = None) -> list[SearchResult] async

Collect iterate() output into a list, optionally bounded.

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, type: Sequence[str] | str | None = None, subtree: Sequence[str] | str | None = None, fq: Sequence[str] | str | None = None, metadata_fields: Sequence[str] | str | None = None, show_facets: bool | None = None, show_relevance: bool | None = None, show_entity_ids: bool | None = None, show_type_counts: bool | None = None, show_collections: bool | None = None) -> SearchResult | None async

Return the first matching item, or None when there is none.

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

Return total_count of the query.

bibliofabric.dataverse.DataversesResource

Client for the /dataverses endpoints.

id is the alias (harvard, SEE_Precursors), the database id, or the special :root spelling the API documents for the root collection; a collection URL works too.

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

Fetch one Dataverse collection.

Published collections answer without credentials; unpublished ones need a token with access. return_owners includes the collections this one is part of, and return_child_count the direct child counts.

Raises:

Type Description
ConfigurationError

select is passed; the route has no field selection.

contents(id: str | int) -> list[DataverseContent] async

List the direct children of one Dataverse collection.

The route answers one list with the child collections first and the child datasets second, each ordered by database id; it does not page and does not recurse into child collections. A large collection (the root of a busy installation, for example) can make this route slow.

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

Return the facet field names of one Dataverse collection.

facet_details(id: str | int) -> list[Facet] async

Return the facets of one Dataverse collection with their details.

Sends returnDetails=true, so every facet carries its display name and database id.

bibliofabric.dataverse.DatasetsResource

Client for the /datasets endpoints.

Every method accepts the numeric database id (46625) or the persistent id (doi:10.7910/DVN/27221, or its doi.org URL). The version arguments accept a number (1.0) or the specifiers :latest, :latest-published, and :draft; the draft needs a token with access.

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

Fetch one dataset with its latest visible version.

Without a token this is the newest published version; with a token that has access, the draft. return_owners includes the collections the dataset is part of.

Raises:

Type Description
ConfigurationError

select is passed; the route has no field selection.

version(id: str | int, version: str = ':latest', *, exclude_files: bool | None = None, exclude_metadata_blocks: bool | None = None, include_deaccessioned: bool | None = None, return_owners: bool | None = None) -> DatasetVersion async

Fetch one version of a dataset.

:latest prefers the draft over the newest published version; :latest-published never answers the draft. exclude_files (default true upstream) drops the file list and exclude_metadata_blocks (default false) drops the typed metadata blocks.

versions(id: str | int, *, page: int | None = None, page_size: int | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None, params: Mapping[str, Any] | None = None) -> Page[DatasetVersion] async

List the versions of one dataset, newest first.

The route pages with limit and offset; page is the zero-based offset index and page_size maps to limit. The answer carries no total, so :attr:Page.total is None.

files(id: str | int, version: str = ':latest', filters: Mapping[str, Any] | None = None, *, page: int | None = None, page_size: int | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None, params: Mapping[str, Any] | None = None) -> Page[FileMetadata] async

List the files of one dataset version, paged.

The route pages with limit and offset; page is the zero-based offset index and page_size maps to limit. filters takes the route's filter parameters as a mapping: contentType, categoryName, tabularTagName, searchText, accessStatus (Public, Restricted, EmbargoedThenRestricted, EmbargoedThenPublic, RetentionPeriodExpired), orderCriteria (NameAZ default, NameZA, Newest, Oldest, Size, Type; the values are case sensitive upstream), and includeDeaccessioned.

Raises:

Type Description
ConfigurationError

filters carries an unknown key or a value outside the lists above.

metadata(id: str | int, version: str = ':latest') -> MetadataBlocks async

Return the metadata blocks of one dataset version.

The answer maps block names (citation, geospatial, ...) to their typed fields, without files or other version members.

export(id: str | int, exporter: str, version: str | None = None) -> str async

Return the metadata of a dataset in an export format, as text.

exporter is a name such as dataverse_json, Datacite, dcterms, ddi, or oai_dc; the exporters vary per installation, and client.info.export_formats() answers the names of the installation this client points at. Without version the route answers the latest published version; :draft needs a token with access.

Raises:

Type Description
ConfigurationError

id is a numeric database id (the route takes a persistent id only), or exporter or version is malformed.

bibliofabric.dataverse.FilesResource

Client for the /files endpoints.

get accepts the numeric file id (2498426) or the file persistent id (doi:10.7910/DVN/27221/MFKS54). The route answers the same file metadata entry the version file lists carry.

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

Fetch one file's metadata entry.

A persistent id rides the files/:persistentId route; a numeric id the plain files/{id} route. The answer carries the dataFile object with the checksum, content type, and size, nested in the version file metadata.

Raises:

Type Description
ConfigurationError

select is passed; the route has no field selection.

bibliofabric.dataverse.AccessResource

Client for the /access download endpoints.

The routes stream the file bytes (the dataset bundle as one zip) and redirect to storage; the downloads go through the core atomic download, so an interrupted transfer leaves no partial file behind. A file whose access is restricted, or whose dataset requires a guestbook response, needs an API token on the client.

datafile(id: str | int, dest: Path | str, *, output_format: str | None = None, image_thumb: str | None = None, no_var_header: bool | None = None, headers: Mapping[str, str] | None = None) -> Path async

Download one data file to dest and return the path.

id is the numeric file id or the file persistent id. output_format converts tabular files: original fetches the saved original (Stata, SPSS, ...), RData an R data frame, and prep pre-processed JSON. image_thumb renders image and PDF files as a thumbnail of the given pixel width ("true" for the default 64). no_var_header drops the variable-name header line of tabular downloads. headers carries raw HTTP headers, for example {"Range": "bytes=0-99"} for a byte range.

Raises:

Type Description
ConfigurationError

dest or output_format is empty or malformed.

dataset(id: str | int, dest: Path | str, *, output_format: str | None = None) -> Path async

Download the files of a dataset as one zip bundle to dest.

id is the numeric dataset id or the dataset persistent id. The bundle holds the files of the latest accessible version plus a MANIFEST.TXT; tabular files ship in their archival form unless output_format="original" requests the saved originals. Files the caller cannot access (restricted, or over the installation's zip size limit) are missing from the bundle and named in the manifest. The download sends Accept: application/zip because the route rejects the client's JSON Accept header with 406.

bibliofabric.dataverse.InfoResource

Client for the /info endpoints.

All three routes answer without credentials and name the installation the client points at, which matters because every Dataverse installation exposes the same API with its own configuration.

version() -> ServerVersion async

Return the Dataverse software version and build.

server() -> ServerInfo async

Return the server name of the installation.

export_formats() -> ExportFormats async

Return the dataset metadata exporters of the installation.

The names are the exporter values the :meth:DatasetsResource.export route accepts (the Datacite entry, for example, answers with the display name DataCite).

metadatablocks() -> list[MetadataBlockSummary] async

List the metadata blocks the installation defines.

metadatablock(name: str, *, return_field_types: bool = True) -> MetadataBlockDefinition async

Return the full definition of one metadata block.

name is the block name (citation and so on). Sends returnDatasetFieldTypes=true by default, so fields maps every field typeName to its definition.

bibliofabric.dataverse.MetricsResource

Client for the /info/metrics endpoints.

One method covers the endpoint matrix of the metrics API: name is the metric path (dataverses, datasets, datasets/bySubject, files/byType, downloads, makeDataCount/viewsTotal, tree), and the monthly, month, and days arguments build the /monthly, /toMonth/{month}, and /pastDays/{days} suffixes. Single-count metrics answer count; time series and per-item metrics answer a list under :attr:MetricResponse.data. The routes answer JSON; the CSV forms the documentation mentions ride client.stream() with an Accept: text/csv header.

get(name: str, *, monthly: bool | None = None, month: str | None = None, days: int | None = None, parent_alias: str | None = None, data_location: str | None = None, country: str | None = None, params: Mapping[str, Any] | None = None) -> MetricResponse async

Fetch one metric.

monthly, month, and days are mutually exclusive. parent_alias scopes the metric to one collection subtree, data_location (local, remote, or all) applies to dataset metrics, and country (an ISO 3166 code) to the Make Data Count metrics.

Raises:

Type Description
ConfigurationError

name is not a metric path, the three time arguments combine, month is not YYYY-MM, days is not positive, or data_location is not one of the three values.