Share projects
This example demonstrates how you can create and share a project with another user using the MLOps Python client.
- 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
ShareProjectsExample.pyfile as given in the preceding data table.- Format
- Sample
ShareProjectsExample.py### ConstantsMLOPS_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>ShareProjectsExample.py### ConstantsMLOPS_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
ShareProjectsExample.pyfile.python3 ShareProjectsExample.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
Defaultpermission.

Example walkthrough
The following steps provide a walkthrough of each of the sections in the ShareProjectsExample.py file.
-
Get a user to share the project with.
ShareProjectsExample.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.
ShareProjectsExample.pyroles_raw: List[mlops.StorageRole] = mlops_client.storage.role.list_roles({}).roleroles = {r.display_name: r.id for r in roles_raw}NoteTwo basic roles are available for default installations of MLOps:
Default- Read/Write accessReader- only Read access
-
Create a project to share.
ShareProjectsExample.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
DefaultorReader, and share the created project with the specified user.ShareProjectsExample.pymlops_client.storage.project.share_project(mlops.StorageShareProjectRequest(project_id=project.id,user_id=user_for_sharing.id,restriction_role_id=roles["Default"],))
- Submit and view feedback for this page
- Send feedback about H2O MLOps to cloud-feedback@h2o.ai