Skip to main content
Version: v0.64.0

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.
ConstantValueDescription
MLOPS_API_URLUsually: https://api.mlops.my.domainDefines 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_NAMESharedProjectExampleDefines 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.

  1. Download the ShareProjectsExample.py file.

  2. Change the values of the following constants in your ShareProjectsExample.py file as given in the preceding data table.

    ShareProjectsExample.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>
  3. Run the ShareProjectsExample.py file.

    python3 ShareProjectsExample.py
  4. Navigate to MLOps to view the created project SharedProjectsExample. Then click the plus icon to see the users the project has been shared with.

Share a project in MLOps
  1. In the Share project: SharedProjectExample side panel, you can see that the project has been shared with the specified user with Default permission.
Share a project in MLOps

Example walkthrough

The following steps provide a walkthrough of each of the sections in the ShareProjectsExample.py file.

  1. Set up the token provider using an existing refresh token.

  2. Set up the MLOps client.

  3. Get a user to share the project with.

    ShareProjectsExample.py
    user_for_sharing: mlops.StorageUser = (
    mlops_client.storage.user.get_user_by_username(
    mlops.StorageGetUserByUsernameRequest(username=USER_TO_SHARE_WITH)
    ).user
    )
  4. Get the roles in MLOps.

    ShareProjectsExample.py
    roles_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
  5. Create a project to share.

    ShareProjectsExample.py
    project: mlops.StorageProject = mlops_client.storage.project.create_project(
    mlops.StorageCreateProjectRequest(
    mlops.StorageProject(display_name=PROJECT_NAME)
    )
    ).project
  6. Finally, restrict the role of the user to either Default or Reader, and share the created project with the specified user.

    ShareProjectsExample.py
    mlops_client.storage.project.share_project(
    mlops.StorageShareProjectRequest(
    project_id=project.id,
    user_id=user_for_sharing.id,
    restriction_role_id=roles["Default"],
    )
    )

Feedback