SDK Client#

This documentation auto-generates details about the OAuth authentication and convenience methods provided by the SDK for users.

Note

The required configuration values (eg IDs) can be found at OAuth.

class libs.sdk.src.destiny_sdk.client.OAuthMiddleware(env: Literal['development', 'staging', 'production'] | None = None, auth_url: str = 'https://auth.evidence-repository.org', realm: str = 'destiny', client_id: str | None = None, client_secret: SecretStr | None = None, callback_port: int = 8400, azure_client_id: str | None = None, azure_application_id: str | None = None, azure_login_url: HttpUrl | str | None = None, azure_client_secret: SecretStr | None = None, *, use_managed_identity: bool = False)[source]#

Auth middleware that routes to either Keycloak or Azure OAuth backends.

The backend is selected by which kwargs are provided:

  • Keycloak (default): the routing target unless any Azure kwarg is given. env (recommended) or client_id is required.

  • Azure AD: pass any azure_* kwarg or use_managed_identity=True. Managed identity is supported. The interactive (public-client) and confidential-client (azure_client_secret) flows are deprecated and will be removed in a future release; migrate those callers to Keycloak.

# Interactive login for user accounts
auth = OAuthMiddleware(env="production")

# Client credentials flow for service accounts
auth = OAuthMiddleware(
    client_id="your-client-id",
    client_secret="your-client-secret"
)
class libs.sdk.src.destiny_sdk.client.OAuthClient(base_url: HttpUrl | str | None = None, auth: Auth | None = None, timeout: int = 10, *, env: Literal['development', 'staging', 'production'] | None = None)[source]#

Client for interaction with the Destiny API using OAuth2.

This will apply the provided authentication, usually OAuthMiddleware, to all requests. Some API endpoints are supported directly through methods on this class, while others can be accessed through the underlying httpx client.

Example usage:

from destiny_sdk.client import OAuthClient

# Either use env for defaults or provide explicit auth and base_url
client = OAuthClient(env="production")
client = OAuthClient(
    base_url="https://destiny-repository.example.com",
    auth=OAuthMiddleware(...),
)

# Supported method
response = client.search(query="example")

# Unsupported method, use underlying httpx client
response = client.get_client().get("/system/healthcheck/")
get_client() Client[source]#

Get the underlying httpx client.

This can be used to make custom requests not covered by the SDK methods.

Returns:

The underlying httpx client with authentication attached.

Return type:

httpx.Client

get_search_enhancement_request(enhancement_request_id: Annotated[Annotated[UUID, UuidVersion(uuid_version=4)] | Annotated[UUID, UuidVersion(uuid_version=7)], FieldInfo(annotation=NoneType, required=True, description='A DESTINY UUID, which can be either UUID4 or UUID7.')] | str, timeout: int | None = None) SearchEnhancementRequestRead[source]#

Get the current status of a search-based enhancement request.

The returned model tracks two phases: search_status for scanning the search and requesting enhancements, and request_status for the downstream processing of those enhancements.

See also: Requesting Enhancements from a Search.

Parameters:
  • enhancement_request_id (libs.sdk.src.destiny_sdk.core.UUID | str) – The ID of the search enhancement request, as returned by request_search_enhancement().

  • timeout (int | None) – The timeout for the request, in seconds. If provided, this will override the client timeout.

Returns:

The current status of the search enhancement request.

Return type:

libs.sdk.src.destiny_sdk.robots.SearchEnhancementRequestRead

lookup(identifiers: list[str | IdentifierLookup], timeout: int | None = None) list[Reference][source]#

Lookup references by identifiers.

See also: API Lookup.

Parameters:
Returns:

The list of references matching the identifiers.

Return type:

list[libs.sdk.src.destiny_sdk.references.Reference]

request_search_enhancement(robot_id: Annotated[Annotated[UUID, UuidVersion(uuid_version=4)] | Annotated[UUID, UuidVersion(uuid_version=7)], FieldInfo(annotation=NoneType, required=True, description='A DESTINY UUID, which can be either UUID4 or UUID7.')] | str, search_query: str, source: str | None = None, *, dry_run: Literal[False] = False, timeout: int | None = None) SearchEnhancementRequestRead[source]#
request_search_enhancement(robot_id: Annotated[Annotated[UUID, UuidVersion(uuid_version=4)] | Annotated[UUID, UuidVersion(uuid_version=7)], FieldInfo(annotation=NoneType, required=True, description='A DESTINY UUID, which can be either UUID4 or UUID7.')] | str, search_query: str, source: str | None = None, *, dry_run: Literal[True], timeout: int | None = None) SearchResultTotal

Request enhancements for every reference matching a search.

The search_query uses the same Lucene syntax as search(); see API Query String Search.

See also: Requesting Enhancements from a Search.

Parameters:
  • robot_id (libs.sdk.src.destiny_sdk.core.UUID | str) – The robot to be used to create the enhancements.

  • search_query (str) – The Lucene query string selecting references to enhance.

  • source (str | None) – An optional source identifier for the enhancement request.

  • dry_run (bool) – If True, synchronously return the number of matching references without creating a request. Defaults to False.

  • timeout (int | None) – The timeout for the request, in seconds. If provided, this will override the client timeout.

Returns:

The pollable request status, or the match count for a dry run.

Return type:

libs.sdk.src.destiny_sdk.robots.SearchEnhancementRequestRead | libs.sdk.src.destiny_sdk.search.SearchResultTotal

search(query: str, start_year: int | None = None, end_year: int | None = None, annotations: list[str | AnnotationFilter] | None = None, concepts: list[str | Collection[str]] | None = None, sort: str | None = None, page: int = 1, timeout: int | None = None) ReferenceSearchResult[source]#

Send a search request to the Destiny Repository API.

See also: API Query String Search.

Parameters:
  • query (str) – The search query string.

  • start_year (int | None) – The start year for filtering results.

  • end_year (int | None) – The end year for filtering results.

  • annotations (list[str | libs.sdk.src.destiny_sdk.search.AnnotationFilter] | None) – A list of annotation filters to apply.

  • concepts (list[str | collections.abc.Collection[str]] | None) – A list of linked-data concept filters. Each entry ANDs with the others. Pass a single URI string for a single match, or a collection of URIs to OR them within a single filter.

  • sort (str | None) – The sort order for the results.

  • page (int) – The page number of results to retrieve.

  • timeout (int | None) – The timeout for the request, in seconds. If provided, this will override the client timeout.

Returns:

The response from the API.

Return type:

libs.sdk.src.destiny_sdk.references.ReferenceSearchResult