Use cases¶
UseCase¶
Representation of a Use Case.
Variables
| Attribute | Type | Description |
|---|---|---|
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. |
files_count |
int |
The number of files 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
| Returns | Description |
|---|---|
| url | Permanent static hyperlink to this Use Case. |
Return type: str
get()¶
Gets information about a Use Case.
Parameters
| Parameter | Type | Description |
|---|---|---|
use_case_id |
str |
The identifier of the Use Case you want to load. |
Returns
| Returns | Description |
|---|---|
| use_case | The queried Use Case. |
Return type: UseCase
list()¶
Returns the Use Cases associated with this account.
Parameters
| Parameter | Type | Description |
|---|---|---|
search_params |
dict, optional. |
If not None, the returned projects are filtered by lookup. |
!!! note "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`
> * `files_count` or `-files_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
| Returns | Description |
|---|---|
| use_cases | Contains a list of Use Cases associated with this user account. |
Return type: list of UseCase instances
Raises
| Exception | Description |
|---|---|
| TypeError | Raised if search_params parameter is provided, but is not of supported type. |
create()¶
Create a new Use Case.
Parameters
| Parameter | Type | Description |
|---|---|---|
name |
str |
Optional. The name of the new Use Case. |
description |
str |
The description of the new Use Case. Optional. |
Returns
| Returns | Description |
|---|---|
| use_case | The created Use Case. |
Return type: UseCase
delete()¶
Delete a Use Case.
Parameters
| Parameter | Type | Description |
|---|---|---|
use_case_id |
str |
The ID of the Use Case to be deleted. |
Return type: None
update()¶
Update a Use Case’s name or description.
Parameters
| Parameter | Type | Description |
|---|---|---|
name |
str |
The updated name of the Use Case. |
description |
str |
The updated description of the Use Case. |
Returns
| Returns | Description |
|---|---|
| use_case | The updated Use Case. |
Return type: UseCase
add()¶
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
| Parameter | Type | Description |
|---|---|---|
entity |
Union[UseCaseReferenceEntity, Project, Dataset, Application, Files] |
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
| Returns | Description |
|---|---|
| use_case_reference_entity | The newly created reference link between this Use Case and the entity. |
Return type: UseCaseReferenceEntity
remove()¶
Remove an entity from a Use Case. Can only accept either an entity or an entity type and entity ID, but not both.
Parameters
| Parameter | Type | Description |
|---|---|---|
entity |
Union[UseCaseReferenceEntity, Project, Dataset, Application, Files] |
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()¶
Share this Use Case with or remove access from one or more user(s).
Parameters
| Parameter | Type | Description |
|---|---|---|
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. Supported share_recipient_type values are USER, ORGANIZATION, and GROUP. 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()¶
Retrieve access control information for this Use Case.
Parameters
| Parameter | Type | Description |
|---|---|---|
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
| Returns | Description |
|---|---|
| projects | All projects associated with this Use Case. |
Return type: List[Project]
list_datasets()¶
List all datasets associated with this Use Case.
Returns
| Returns | Description |
|---|---|
| datasets | All datasets associated with this Use Case. |
Return type: List[Dataset]
list_applications()¶
List all applications associated with this Use Case.
Returns
| Returns | Description |
|---|---|
| applications | All applications associated with this Use Case. |
Return type: List[Application]
from_data()¶
Instantiate an object of this class using a dict.
Parameters
| Parameter | Type | Description |
|---|---|---|
data |
dict |
Correctly snake_cased keys and their values. |
Return type: TypeVar(T, bound= APIObject)
from_server_data()¶
Instantiate an object of this class using the data directly from the server, meaning that the keys may have the wrong camel casing
Parameters
| Parameter | Type | Description |
|---|---|---|
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
UseCaseUser¶
Representation of a Use Case user.
Variables
| Attribute | Type | Description |
|---|---|---|
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. |
UseCaseReferenceEntity¶
An entity associated with a Use Case.
Variables
| Attribute | Type | Description |
|---|---|---|
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. |