Skip to content

Rapidata client

RapidataClient #

RapidataClient(
    client_id: str | None = None,
    client_secret: str | None = None,
    environment: str = "rapidata.ai",
    oauth_scope: str = "openid roles",
    cert_path: str | None = None,
    token: dict | None = None,
    leeway: int = 60,
)

The Rapidata client is the main entry point for interacting with the Rapidata API. It allows you to create orders and validation sets.

Parameters:

Name Type Description Default
client_id str

The client ID for authentication.

None
client_secret str

The client secret for authentication.

None
environment str

The API endpoint.

'rapidata.ai'
oauth_scope str

The scopes to use for authentication. In general this does not need to be changed.

'openid roles'
cert_path str

An optional path to a certificate file useful for development.

None
token dict

If you already have a token that the client should use for authentication. Important, if set, this needs to be the complete token object containing the access token, token type and expiration time.

None
leeway int

An optional leeway to use to determine if a token is expired. Defaults to 60 seconds.

60

Attributes:

Name Type Description
order RapidataOrderManager

The RapidataOrderManager instance.

validation ValidationSetManager

The ValidationSetManager instance.

mri RapidataBenchmarkManager

The RapidataBenchmarkManager instance.

Source code in src/rapidata/rapidata_client/rapidata_client.py
def __init__(
    self,
    client_id: str | None = None,
    client_secret: str | None = None,
    environment: str = "rapidata.ai",
    oauth_scope: str = "openid roles",
    cert_path: str | None = None,
    token: dict | None = None,
    leeway: int = 60,
):
    """Initialize the RapidataClient. If both the client_id and client_secret are None, it will try using your credentials under "~/.config/rapidata/credentials.json".
    If this is not successful, it will open a browser window and ask you to log in, then save your new credentials in said json file.

    Args:
        client_id (str): The client ID for authentication.
        client_secret (str): The client secret for authentication.
        environment (str, optional): The API endpoint.
        oauth_scope (str, optional): The scopes to use for authentication. In general this does not need to be changed.
        cert_path (str, optional): An optional path to a certificate file useful for development.
        token (dict, optional): If you already have a token that the client should use for authentication. Important, if set, this needs to be the complete token object containing the access token, token type and expiration time.
        leeway (int, optional): An optional leeway to use to determine if a token is expired. Defaults to 60 seconds.

    Attributes:
        order (RapidataOrderManager): The RapidataOrderManager instance.
        validation (ValidationSetManager): The ValidationSetManager instance.
        mri (RapidataBenchmarkManager): The RapidataBenchmarkManager instance.
    """
    tracer.set_session_id(
        uuid.UUID(int=random.Random().getrandbits(128), version=4).hex
    )

    with tracer.start_as_current_span("RapidataClient.__init__"):
        logger.debug("Checking version")
        self._check_version()
        if environment != "rapidata.ai":
            rapidata_config.logging.enable_otlp = False

        logger.debug("Initializing OpenAPIService")
        self._openapi_service = OpenAPIService(
            client_id=client_id,
            client_secret=client_secret,
            environment=environment,
            oauth_scope=oauth_scope,
            cert_path=cert_path,
            token=token,
            leeway=leeway,
        )

        logger.debug("Initializing RapidataOrderManager")
        self.order = RapidataOrderManager(openapi_service=self._openapi_service)

        logger.debug("Initializing ValidationSetManager")
        self.validation = ValidationSetManager(
            openapi_service=self._openapi_service
        )

        logger.debug("Initializing DemographicManager")
        self._demographic = DemographicManager(
            openapi_service=self._openapi_service
        )

        logger.debug("Initializing RapidataBenchmarkManager")
        self.mri = RapidataBenchmarkManager(openapi_service=self._openapi_service)

    self._check_beta_features()  # can't be in the trace for some reason

reset_credentials #

reset_credentials()

Reset the credentials saved in the configuration file for the current environment.

Source code in src/rapidata/rapidata_client/rapidata_client.py
def reset_credentials(self):
    """Reset the credentials saved in the configuration file for the current environment."""
    self._openapi_service.reset_credentials()

clear_all_caches #

clear_all_caches()

Clear all caches for the client.

Source code in src/rapidata/rapidata_client/rapidata_client.py
def clear_all_caches(self):
    """Clear all caches for the client."""
    self.order._asset_uploader.clear_cache()
    logger.info("All caches cleared")