Server Classesο
This module contains classes for managing connections to Dataverse servers.
DataverseServerο
The main class for interacting with a Dataverse server installation.
- class dartfx.dataverse.DataverseServer(server=None, api_key=None, on_api_error='raise', on_api_success_return='json', session=None, lookup_installation=True, *, installation, user_agent='dartfx-dataverse/0.2.0', ssl_verify=True)[source]ο
Bases:
BaseModel- model_config = {'arbitrary_types_allowed': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- installation: ServerInstallationο
- session: CachedSessionο
- __init__(server=None, api_key=None, on_api_error='raise', on_api_success_return='json', session=None, lookup_installation=True, **kwargs)[source]ο
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- request(method, path, description=None, headers=None, success=200, return_type=None, **kwargs)[source]ο
Call the API.
- get_request(path, description=None, headers=None, success=200, return_type=None, **kwargs)[source]ο
Call the API using the GET method.
- post_request(path, description=None, headers=None, success=200, **kwargs)[source]ο
Call the API using the POST method.
- get_info_api_terms()[source]ο
Get API Terms of Use.
The response contains the text value inserted as API Terms of use which uses the database setting :ApiTermsOfUse:.
- get_info_export_formats()[source]ο
Get the available export formats, including custom formats. Introduced in version 6.5
- get_info_server()[source]ο
Get the server name.
This is useful when a Dataverse installation is composed of multiple app servers behind a load balancer.
- get_info_version()[source]ο
Get the Dataverse installation version. The response contains the version and build numbers:.
- get_info_zip_download_limit()[source]ο
Get the configured zip file download limit. The response contains the long value of the limit in bytes.
- get_metadatablocks()[source]ο
Lists brief info about all metadata blocks registered in the system.
- get_metadatablock(identifier)[source]ο
Return data about the block whose identifier is passed, including allowed controlled vocabulary values. identifier can either be the blockβs database id, or its name (i.e. βcitationβ).
- get_dataset(identifier)[source]ο
Get information about a specific dataset by its persistent identifier.
- Parameters:
identifier (str) β Persistent identifier (e.g., βdoi:10.5683/SP3/FNS9EFβ)
- search_simple(q, **kwargs)[source]ο
Search for dataverses, datasets, and files using a simple query string.
- search(parameters)[source]ο
Search for dataverses, datasets, and files.
References: - https://guides.dataverse.org/en/latest/api/search.html - https://github.com/IQSS/dataverse/issues/2558
ServerInstallationο
Represents a Dataverse installation with its metadata.
- class dartfx.dataverse.ServerInstallation(*, name=None, description=None, lat=None, lng=None, hostname=None, metrics=False, launch_year=None, country=None, continent=None, harvesting_sets=None, core_trust_seals=None, gdcc_member=None, doi_authority=None, board=None, contact_email=None)[source]ο
Bases:
BaseModelRepresents a dataverse installation. Based on the content of the data.json file in the dataverse-installations repository at https://github.com/IQSS/dataverse-installations
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Functionsο
Examplesο
Creating a Server Connectionο
from dartfx.dataverse import DataverseServer, ServerInstallation
# Create installation object
installation = ServerInstallation(
name="Harvard Dataverse",
hostname="dataverse.harvard.edu"
)
# Create server connection
server = DataverseServer(installation)
With API Keyο
server = DataverseServer(
server=installation,
api_key="your-api-key-here"
)
Custom Configurationο
import requests_cache
from datetime import timedelta
# Create custom session
session = requests_cache.CachedSession(
cache_name='my_cache',
expire_after=timedelta(hours=1)
)
# Create server with custom config
server = DataverseServer(
server=installation,
session=session,
ssl_verify=True,
on_api_error="raise"
)
Getting Server Informationο
# Get server info
info = server.get_server_info()
print(f"Version: {info['data']['version']}")
# Get metadata blocks
blocks = server.get_metadatablocks()
for block in blocks['data']:
print(block['name'])