Skip to content

Project

This section shows how to create, modify and list projects in AI & Analytics Engine using the SDK

Creating a project

You can create a new project within an organization by specifying a project name, some description.

import os
from aiaengine import Org

org_id = os.environ.get('ORG_ID', 'b6240512-cd17-43a0-8297-84c51c1bc5a0')
org = Org(id=org_id)

# create the new project
project = org.create_project(name='Project name', description='What is this project about')

print(f'Project id: {project.id}')
package com.aiaengine.examples.project;

import com.aiaengine.Engine;
import com.aiaengine.Org;
import com.aiaengine.Project;
import com.aiaengine.org.request.CreateProjectRequest;

import java.io.FileNotFoundException;

public class CreateProjectApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        Org org = engine.getOrg("cae24b10-e6b0-4d61-8cef-a9f4b8f6133d");
        Project project = org.createProject(CreateProjectRequest.builder()
                .name("Project name")
                .description("What is this project about")
                .build());
        System.out.println(project.getId());
    }
}

Retrieving information of a project

You can get information about a project by providing the project ID.

from aiaengine import Project

# get the project by the ID
project = Project(id='ID_of_the_project')

print(project.name)
package com.aiaengine.examples.project;

import com.aiaengine.Engine;
import com.aiaengine.Project;

import java.io.FileNotFoundException;

public class GetProjectApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        Project project = engine.getProject("d76d9e6e-336d-4cbb-8ffa-42fdf4281659");
        System.out.println(project.getName());
    }
}

Updating a project

You can modify the name and description of an existing project by specifying the project ID.

import os
from aiaengine import Project

project_id = os.environ.get('PROJECT_ID', '')
project = Project(id=project_id)
project.update(name='Updated Project', description='This project has been updated')
package com.aiaengine.examples.project;

import com.aiaengine.Engine;
import com.aiaengine.Project;
import com.aiaengine.project.request.UpdateProjectRequest;

import java.io.FileNotFoundException;

public class UpdateProjectApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        Project project = engine.getProject("d76d9e6e-336d-4cbb-8ffa-42fdf4281659");
        project.update(UpdateProjectRequest.builder()
                        .name("Updated Project")
                        .description("This project has been updated")
                .build());
    }
}

Listing projects in an organization

You can list all the projects within an organization by providing the organization ID.

from aiaengine import Org

# get the org
org = Org(id='ID_of_org')

# list projects of the org
projects = org.list_projects()
print(projects)
package com.aiaengine.examples.project;

import com.aiaengine.Engine;
import com.aiaengine.Org;
import com.aiaengine.Project;

import java.io.FileNotFoundException;
import java.util.List;

public class ListProjectsApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        Org org = engine.getOrg("cae24b10-e6b0-4d61-8cef-a9f4b8f6133d");
        List<Project> projects = org.listProjects();
        projects.forEach(project -> System.out.println(project.getName()));
    }
}

Listing projects accessible by the current user

Similarly you can inspect all the projects that can be accessed by the current user.

from aiaengine import Project

# list projects that can be accessed by the current authenticated user
projects = Project.list_user_projects()
for project in projects:
    print(project.name)
package com.aiaengine.examples.project;

import com.aiaengine.Engine;
import com.aiaengine.Project;

import java.io.FileNotFoundException;
import java.util.List;

public class ListUserProjectsApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        List<Project> projects = engine.listUserProjects();
        projects.forEach(project -> System.out.println(project.getName()));
    }
}

Listing users that can access a project

You can also list all the users who have access to a particular project by providing the project ID.

from aiaengine import Project

# get the project we want to list the users
project = Project(id='4c098a3f-29ba-456a-bec3-3a3ad41aa943') # replace with your own project ID

project_users = project.list_users()
for project_user in project_users:
    print(f"{project_user.user.name} - {project_user.user.email}")
package com.aiaengine.examples.project;

import com.aiaengine.Engine;
import com.aiaengine.Project;
import com.aiaengine.project.ProjectUser;

import java.io.FileNotFoundException;
import java.util.List;

public class ListProjectUsersApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        Project project = engine.getProject("d76d9e6e-336d-4cbb-8ffa-42fdf4281659");
        List<ProjectUser> users = project.listProjectUsers();
        users.forEach(user -> System.out.println(user.getUser().getName()));
    }
}

Adding a user to a project

You can add an existing user of the platform to a project by specifying the project id, the user id and the role of the user (project-viewer, project-owner, project-editor).

import os
from aiaengine import Project, UserRoles

# get project ID from environment variable if available, otherwise use the default one
project_id = os.environ.get('PROJECT_ID', '')
project = Project(id=project_id)

# add the user to the project with the Editor role
project.add_user(user_email='user@example.com', role=UserRoles.ProjectEditor)
package com.aiaengine.examples.project;

import com.aiaengine.Engine;
import com.aiaengine.Project;
import com.aiaengine.user.UserRoles;

import java.io.FileNotFoundException;

public class AddProjectUserApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        Project project = engine.getProject("d76d9e6e-336d-4cbb-8ffa-42fdf4281659");
        project.addUser("user@example.com", UserRoles.ProjectViewer);
    }
}

Removing a user from a project

Once a user is no longer interested in a project, you can remove the user with input of the project id and user ID.

from aiaengine import Project

project = Project(id='your_project_ID')

project.remove_user(user_email='user@example.com')
package com.aiaengine.examples.project;

import com.aiaengine.Engine;
import com.aiaengine.Project;

import java.io.FileNotFoundException;

public class RemoveProjectUserApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        Project project = engine.getProject("d76d9e6e-336d-4cbb-8ffa-42fdf4281659");
        project.removeUser("user@example.com");
    }
}

Deleting a project

You can also remove a project which is no longer needed by giving the project ID.

import os
from aiaengine import Project

project_id = os.environ.get('PROJECT_ID', '')
project = Project(id=project_id)
project.delete()
package com.aiaengine.examples.project;

import com.aiaengine.Engine;
import com.aiaengine.Project;

import java.io.FileNotFoundException;

public class DeleteProjectApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        Project project = engine.getProject("a08a059a-1a83-4868-9368-787df8fa96c0");
        project.delete();
    }
}