Share projects¶
This example demonstrates how you can create and share a project with another user using the MLOps Python client.
Before you begin
- You will need the values for the following constants in order to successfully carry out the task. Contact your administrator to obtain deployment specific values.
Constant |
Value | Description |
---|---|---|
MLOPS_API_URL |
Usually: https://api.mlops.my.domain |
Defines the URL for the MLOps Gateway component. You can verify the correct URL by navigating to the API URL in your browser. It should provide a page with a list of available routes. |
TOKEN_ENDPOINT_URL |
https://mlops.keycloak.domain/auth/realms/[fill-in-realm-name]/protocol/openid-connect/token |
Defines the token endpoint URL of the Identity Provider. This uses Keycloak as the Identity Provider. Keycloak Realm should be provided. |
REFRESH_TOKEN |
<your-refresh-token> |
Defines the user's refresh token |
CLIENT_ID |
<your-client-id> |
Sets the client id for authentication. This is the client you will be using to connect to MLOps. |
PROJECT_NAME |
SharedProjectExample |
Defines a project name that the script will be using. |
USER_TO_SHARE_WITH |
<user-id> |
Defines a user to share the project with. |
The following steps demonstrate how you can use MLOps Python client to create and share a project with another user.
-
Change the values of the following constants in your
SharingProjectsExample.py
file as given in the preceding data table.SharingProjectsExample.py### Constants MLOPS_API_URL = <MLOPS_API_URL> TOKEN_ENDPOINT_URL = <TOKEN_ENDPOINT_URL> REFRESH_TOKEN = <REFRESH_TOKEN> CLIENT_ID = <CLIENT_ID> PROJECT_NAME = <PROJECT_NAME> USER_TO_SHARE_WITH = <USER_TO_SHARE_WITH>
SharingProjectsExample.py### Constants MLOPS_API_URL = "https://api.mlops.my.domain" TOKEN_ENDPOINT_URL="https://mlops.keycloak.domain/auth/realms/[fill-in-realm-name]/protocol/openid-connect/token" REFRESH_TOKEN="<your-refresh-token>" CLIENT_ID="<your-mlops-client>" PROJECT_NAME = "SharedProjectExample" USER_TO_SHARE_WITH = "<user-id>"
-
Run the
SharingProjectsExample.py
file.python3 SharingProjectsExample.py
-
Navigate to MLOps to view the created project
SharedProjectsExample
. Then click the plus icon to see the users the project has been shared with. -
In the Share project: SharedProjectExample side panel, you can see that the project has been shared with the specified user with
Default
permission.
Example walkthrough¶
The following steps provide a walkthrough of each of the sections in the SharingProjectsExample.py
file.
-
Get a user to share the project with.
SharingProjectsExample.pyuser_for_sharing: mlops.StorageUser = ( mlops_client.storage.user.get_user_by_username( mlops.StorageGetUserByUsernameRequest(username=USER_TO_SHARE_WITH) ).user )
-
Get the roles in MLOps.
SharingProjectsExample.pyroles_raw: List[mlops.StorageRole] = mlops_client.storage.role.list_roles({}).role roles = {r.display_name: r.id for r in roles_raw}
Note
Two basic roles are available for default installations of MLOps:
-
Default
- Read/Write access -
Reader
- only Read access
-
-
Create a project to share.
SharingProjectsExample.pyproject: mlops.StorageProject = mlops_client.storage.project.create_project( mlops.StorageCreateProjectRequest( mlops.StorageProject(display_name=PROJECT_NAME) ) ).project
-
Finally, restrict the role of the user to either
Default
orReader
, and share the created project with the specified user.SharingProjectsExample.pymlops_client.storage.project.share_project( mlops.StorageShareProjectRequest( project_id=project.id, user_id=user_for_sharing.id, restriction_role_id=roles["Default"], ) )