Skip to content

metrics

pyDataverse.dataverse.metrics

Provides access to Dataverse-level metrics.

This class fetches and aggregates usage/content metrics from a Dataverse instance using its Metrics API. It exposes key metrics and summaries as DataFrames and direct counters, with clear interface and documentation.

Attributes

NameTypeDescription
metrics_apiMetricsApiThe MetricsApi instance used for all metrics API calls.

Example

>>> dv = Dataverse(“https://demo.dataverse.org”) >>> dv.metrics.total(“datasets”) >>> dv.metrics.df # Summary DataFrame of all core metrics

Attributes

NameTypeDescription
collections_by_subjectpd.DataFrameDataFrame of Dataverse collections grouped by subject.
collections_by_categorypd.DataFrameDataFrame of collections grouped by category.
dfpd.DataFrameDataFrame with a summary of all top-level, site-wide metrics.
datasets_by_subjectpd.DataFrameDataFrame of datasets grouped by subject.

Methods

total(self, data_type: DataType, date_to_month: Optional[Union[str, date]] = None) -> int

Get the total count for a type of entity (e.g., all datasets, files, downloads, dataverses).

Parameters

NameTypeDescription
data_typeDataTypeOne of ‘dataverses’, ‘datasets’, ‘files’, or ‘downloads’.
date_to_monthOptional[Union[str, date]]Optional (str or date) - If provided, gives the value for a given month (‘YYYY-MM’ or date object). (default: None)

Returns

TypeDescription
intTotal count for the given type and period.

Example

>>> dv.metrics.total(“datasets”) >>> dv.metrics.total(“downloads”, “2024-01”) # For a specific month

past_days(self, data_type: DataType, days: Union[int, str]) -> int

Number of objects/events for the past number of days.

Parameters

NameTypeDescription
data_typeDataTypeWhich type (‘dataverses’, ‘datasets’, ‘files’, ‘downloads’).
daysUnion[int, str]Integer or string (e.g., 7, 30) – period to consider.

Returns

TypeDescription
intCount for the given period.

Example

>>> dv.metrics.past_days(“datasets”, days=30)

datasets_by_data_location(self, data_location: DataLocation) -> int

Number of datasets by storage location (local, remote, or all).

Parameters

NameTypeDescription
data_locationDataLocationOne of ‘local’, ‘remote’, or ‘all’.

Returns

TypeDescription
intDataset count for the location.

Example

>>> dv.metrics.datasets_by_data_location(“local”)

dict(self) -> Dict[str, Any]

Dictionary of all metrics.

json(self, indent: Optional[int] = 4) -> str

JSON string of all metrics.