Skip to content

API Reference

Client

Bases: BaseClient

A client that interacts with the re3data API.

Attributes:

Name Type Description
_client Client

The underlying HTTP client.

_repository_manager RepositoryManager

The repository manager to retrieve metadata from the repositories endpoints.

Examples:

>>> client = Client():
>>> response = re3data.repositories.list()
>>> print(response)
<?xml version="1.0" encoding="UTF-8"?>
<list>
<repository>
    <id>r3d100010468</id>
    <doi>https://doi.org/10.17616/R3QP53</doi>
    <name>Zenodo</name>
    <link href="https://www.re3data.org/api/beta/repository/r3d100010468" rel="self" />
</repository>
... (remaining repositories truncated)
Source code in src/re3data/_client.py
class Client(BaseClient):
    """A client that interacts with the re3data API.

    Attributes:
        _client: The underlying HTTP client.
        _repository_manager: The repository manager to retrieve metadata from the repositories endpoints.

    Examples:
        >>> client = Client():
        >>> response = re3data.repositories.list()
        >>> print(response)
        <?xml version="1.0" encoding="UTF-8"?>
        <list>
        <repository>
            <id>r3d100010468</id>
            <doi>https://doi.org/10.17616/R3QP53</doi>
            <name>Zenodo</name>
            <link href="https://www.re3data.org/api/beta/repository/r3d100010468" rel="self" />
        </repository>
        ... (remaining repositories truncated)
    """

    _client: httpx.Client

    def __init__(self) -> None:
        super().__init__(httpx.Client)
        self._repository_manager: RepositoryManager = RepositoryManager(self)

    def _request(self, endpoint: str, return_type: str) -> str | httpx.Response:
        """Send a HTTP GET request to the specified endpoint.

        Args:
            endpoint: The endpoint to send the request to.
            return_type: The type of response to expect.

        Returns:
            A string representation of the response (if `return_type` is "xml") or the full response object.

        Raises:
            httpx.RequestError: If the request fails or times out.
            ValueError: If an invalid `return_type` is provided.
        """
        if return_type not in ALLOWED_RETURN_TYPES:
            raise ValueError(f"Invalid `return_type`: {return_type}. Expected one of: {ALLOWED_RETURN_TYPES}")
        response = self._client.get(endpoint)
        response.raise_for_status()
        if return_type == "xml":
            return response.text
        return response

    @property
    def repositories(self) -> RepositoryManager:
        """Get the repository manager for this client.

        Returns:
            The repository manager.
        """
        return self._repository_manager

repositories: RepositoryManager property

Get the repository manager for this client.

Returns:

Type Description
RepositoryManager

The repository manager.