Skip to content

Use cases

class datarobot.UseCase

Representation of a Use Case.

  • Variables:
    • id (str) – The ID of the Use Case.
    • name (str) – The name of the Use Case.
    • description (str) – The description of the Use Case. Nullable.
    • created_at (str) – The timestamp generated at record creation.
    • created (UseCaseUser) – The user who created the Use Case.
    • updated_at (str) – The timestamp generated when the record was last updated.
    • updated (UseCaseUser) – The most recent user to update the Use Case.
    • models_count (int) – The number of models in a Use Case.
    • projects_count (int) – The number of projects in a Use Case.
    • datasets_count (int) – The number of datasets in a Use Case.
    • notebooks_count (int) – The number of notebooks in a Use Case.
    • applications_count (int) – The number of applications in a Use Case.
    • playgrounds_count (int) – The number of playgrounds in a Use Case.
    • vector_databases_count (int) – The number of vector databases in a Use Case.
    • owners (List[UseCaseUser]) – The most recent user to update the Use Case.
    • members (List[UseCaseUser]) – The most recent user to update the Use Case.

Examples

import datarobot
with UseCase.get("2348ac"):
    print(f"The current use case is {dr.Context.use_case}")

get_uri()

  • Returns: url – Permanent static hyperlink to this Use Case.
  • Return type: str

classmethod get(use_case_id)

Gets information about a Use Case.

  • Parameters: use_case_id (str) – The identifier of the Use Case you want to load.
  • Returns: use_case – The queried Use Case.
  • Return type: UseCase

classmethod list(search_params=None)

Returns the Use Cases associated with this account.

  • Parameters: search_params (dict, optional.) –

    If not None, the returned projects are filtered by lookup.

    Notes

    Currently, you can query use cases by:

    • offset - The number of records to skip over. Default 0.
    • limit - The number of records to return in the range from 1 to 100. Default 100.
    • search - Only return Use Cases with names that match the given string.
    • project_id - Only return Use Cases associated with the given project ID.
    • application_id - Only return Use Cases associated with the given app.
    • orderBy - The order to sort the Use Cases.

    orderBy queries can use the following options:

    • id or -id
    • name or -name
    • description or -description
    • projects_count or -projects_count
    • datasets_count or -datasets_count
    • notebooks_count or -notebooks_count
    • applications_count or -applications_count
    • created_at or -created_at
    • created_by or -created_by
    • updated_at or -updated_at
    • updated_by or -updated_by
  • Returns: use_cases – Contains a list of Use Cases associated with this user account.
  • Return type: list of UseCase instances
  • Raises: TypeError – Raised if search_params parameter is provided, but is not of supported type.

classmethod create(name=None, description=None)

Create a new Use Case.

  • Parameters:
    • name (str) – Optional. The name of the new Use Case.
    • description (str) – The description of the new Use Case. Optional.
  • Returns: use_case – The created Use Case.
  • Return type: UseCase

classmethod delete(use_case_id)

Delete a Use Case.

  • Parameters: use_case_id (str) – The ID of the Use Case to be deleted.
  • Return type: None

update(name=None, description=None)

Update a Use Case’s name or description.

  • Parameters:
    • name (str) – The updated name of the Use Case.
    • description (str) – The updated description of the Use Case.
  • Returns: use_case – The updated Use Case.
  • Return type: UseCase

add(entity=None, entity_type=None, entity_id=None)

Add an entity (project, dataset, etc.) to a Use Case. Can only accept either an entity or an entity type and entity ID, but not both.

Projects and Applications can only be linked to a single Use Case. Datasets can be linked to multiple Use Cases.

There are some prerequisites for linking Projects to a Use Case which are explained in the user guide.

  • Parameters:
    • entity (Union[UseCaseReferenceEntity, Project, Dataset, Application]) – An existing entity to be linked to this Use Case. Cannot be used if entity_type and entity_id are passed.
    • entity_type (UseCaseEntityType) – The entity type of the entity to link to this Use Case. Cannot be used if entity is passed.
    • entity_id (str) – The ID of the entity to link to this Use Case. Cannot be used if entity is passed.
  • Returns: use_case_reference_entity – The newly created reference link between this Use Case and the entity.
  • Return type: UseCaseReferenceEntity

remove(entity=None, entity_type=None, entity_id=None)

Remove an entity from a Use Case. Can only accept either an entity or an entity type and entity ID, but not both.

  • Parameters:
    • entity (Union[UseCaseReferenceEntity, Project, Dataset, Application]) – An existing entity instance to be removed from a Use Case. Cannot be used if entity_type and entity_id are passed.
    • entity_type (UseCaseEntityType) – The entity type of the entity to link to this Use Case. Cannot be used if entity is passed.
    • entity_id (str) – The ID of the entity to link to this Use Case. Cannot be used if entity is passed.
  • Return type: None

share(roles)

Share this Use Case with or remove access from one or more user(s).

  • Parameters: roles (List[SharingRole]) –

    A list of SharingRole instances, each of which references a user and a role to be assigned.

    Currently, the only supported roles for Use Cases are OWNER, EDITOR, and CONSUMER, and the only supported SHARING_RECIPIENT_TYPE is USER.

    To remove access, set a user’s role to datarobot.enums.SHARING_ROLE.NO_ROLE. * Return type: None

Examples

The SharingRole class is needed in order to share a Use Case with one or more users.

For example, suppose you had a list of user IDs you wanted to share this Use Case with. You could use a loop to generate a list of SharingRole objects for them, and bulk share this Use Case.

>>> from datarobot.models.use_cases.use_case import UseCase
>>> from datarobot.models.sharing import SharingRole
>>> from datarobot.enums import SHARING_ROLE, SHARING_RECIPIENT_TYPE
>>>
>>> user_ids = ["60912e09fd1f04e832a575c1", "639ce542862e9b1b1bfa8f1b", "63e185e7cd3a5f8e190c6393"]
>>> sharing_roles = []
>>> for user_id in user_ids:
...     new_sharing_role = SharingRole(
...         role=SHARING_ROLE.CONSUMER,
...         share_recipient_type=SHARING_RECIPIENT_TYPE.USER,
...         id=user_id,
...     )
...     sharing_roles.append(new_sharing_role)
>>> use_case = UseCase.get(use_case_id="5f33f1fd9071ae13568237b2")
>>> use_case.share(roles=sharing_roles)

Similarly, a SharingRole instance can be used to remove a user’s access if the role is set to SHARING_ROLE.NO_ROLE, like in this example:

>>> from datarobot.models.use_cases.use_case import UseCase
>>> from datarobot.models.sharing import SharingRole
>>> from datarobot.enums import SHARING_ROLE, SHARING_RECIPIENT_TYPE
>>>
>>> user_to_remove = "foo.bar@datarobot.com"
... remove_sharing_role = SharingRole(
...     role=SHARING_ROLE.NO_ROLE,
...     share_recipient_type=SHARING_RECIPIENT_TYPE.USER,
...     username=user_to_remove,
... )
>>> use_case = UseCase.get(use_case_id="5f33f1fd9071ae13568237b2")
>>> use_case.share(roles=[remove_sharing_role])

get_shared_roles(offset=None, limit=None, id=None)

Retrieve access control information for this Use Case.

  • Parameters:
    • offset (Optional[int]) – The number of records to skip over. Optional. Default is 0.
    • limit (Optional[int]) – The number of records to return. Optional. Default is 100.
    • id (Optional[str]) – Return the access control information for a user with this user ID. Optional.
  • Return type: List[SharingRole]

list_projects()

List all projects associated with this Use Case.

  • Returns: projects – All projects associated with this Use Case.
  • Return type: List[Project]

list_datasets()

List all datasets associated with this Use Case.

  • Returns: datasets – All datasets associated with this Use Case.
  • Return type: List[Dataset]

list_applications()

List all applications associated with this Use Case.

  • Returns: applications – All applications associated with this Use Case.
  • Return type: List[Application]

classmethod from_data(data)

Instantiate an object of this class using a dict.

  • Parameters: data (dict) – Correctly snake_cased keys and their values.
  • Return type: TypeVar(T, bound= APIObject)

classmethod from_server_data(data, keep_attrs=None)

Instantiate an object of this class using the data directly from the server, meaning that the keys may have the wrong camel casing

  • Parameters:
    • data (dict) – The directly translated dict of JSON from the server. No casing fixes have taken place
    • keep_attrs (iterable) – List, set or tuple of the dotted namespace notations for attributes to keep within the object structure even if their values are None
  • Return type: TypeVar(T, bound= APIObject)

open_in_browser()

Opens class’ relevant web browser location. If default browser is not available the URL is logged.

Note: If text-mode browsers are used, the calling process will block until the user exits the browser.

  • Return type: None

class datarobot.models.use_cases.use_case.UseCaseUser

Representation of a Use Case user.

  • Variables:
    • id (str) – The id of the user.
    • full_name (str) – The full name of the user. Optional.
    • email (str) – The email address of the user. Optional.
    • userhash (str) – User’s gravatar hash. Optional.
    • username (str) – The username of the user. Optional.

class datarobot.models.use_cases.use_case.UseCaseReferenceEntity

An entity associated with a Use Case.

  • Variables:
    • entity_type (UseCaseEntityType) – The type of the entity.
    • use_case_id (str) – The Use Case this entity is associated with.
    • id (str) – The ID of the entity.
    • created_at (str) – The date and time this entity was linked with the Use Case.
    • is_deleted (bool) – Whether or not the linked entity has been deleted.
    • created (UseCaseUser) – The user who created the link between this entity and the Use Case.