Skip to content

project

Define a project.

Classes:

Name Description
Project

A project is used to organize your artifacts.

Functions:

Name Description
set_project

Set the current project.

get_project

Get the current project.

Project(model: ProjectModel) #

A project is used to organize your artifacts.

Methods:

Name Description
create_or_get

Create project with the given name and description. Load project if the given name already exists.

load_all

Load all projects.

update

Update the current project.

__enter__

Set Project.CURRENT to this project.

__exit__

Restore previous Project.CURRENT.

list_datasets

List all datasets in this project.

list_trained_models

List all trained models in this project.

list_explanations

List all explanations in this project.

delete

Delete this project.

Attributes:

Name Type Description
CURRENT ContextVar[Project]
model
Source code in src/xpdeep/project.py
def __init__(self, model: ProjectModel) -> None:
    self.model = model

CURRENT: ContextVar[Project] = ContextVar('CURRENT_PROJECT') #

model = model #

create_or_get(*, name: str, description: str = '') -> Project #

Create project with the given name and description. Load project if the given name already exists.

Parameters:

Name Type Description Default
name #
str

Name of the project to create. If a project within this name already exists, it will be loaded

required
description #
str

Description of the new created project. Ignored in case of project loading.

""
Source code in src/xpdeep/project.py
@staticmethod
@initialized_client_verification
def create_or_get(*, name: str, description: str = "") -> "Project":
    """Create project with the given name and description. Load project if the given name already exists.

    Parameters
    ----------
    name : str
        Name of the project to create. If a project within this name already exists, it will be loaded
    description : str, default ""
        Description of the new created project. Ignored in case of project loading.
    """
    try:
        project_model = next(project for project in Project.load_all() if project.model.name == name).model
    except StopIteration:
        project_model = cast(
            "ProjectModel",
            create_project.sync(
                body=ProjectCreateRequestBody(
                    name=name,
                    description=description,
                ),
                client=ClientFactory.CURRENT.get()(),
            ),
        )

    return Project(project_model)

load_all() -> list[Project] #

Load all projects.

Source code in src/xpdeep/project.py
@classmethod
@initialized_client_verification
def load_all(cls) -> list["Project"]:
    """Load all projects."""
    project_models = cast("list[ProjectModel]", get_all_projects.sync(client=ClientFactory.CURRENT.get()()))
    return [cls(project_model) for project_model in project_models]

update(*, name: str | None = None, description: str | None = None) -> None #

Update the current project.

Parameters:

Name Type Description Default
name #
str | None

New project's name.

None
description #
str | None

New project's description.

None
Source code in src/xpdeep/project.py
@initialized_client_verification
def update(self, *, name: str | None = None, description: str | None = None) -> None:
    """Update the current project.

    Parameters
    ----------
    name : str | None, default None
        New project's name.
    description : str | None, default None
        New project's description.
    """
    if name is not None or description is not None:
        self.model = cast(
            "ProjectModel",
            update_project.sync(
                self.model.id,
                client=ClientFactory.CURRENT.get()(),
                body=ProjectUpdateRequestBody(name=name, description=description),
            ),
        )

__enter__() -> Self #

Set Project.CURRENT to this project.

Source code in src/xpdeep/project.py
def __enter__(self) -> Self:
    """Set ``Project.CURRENT`` to this project."""
    self.token = Project.CURRENT.set(self)

    return self

__exit__(exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) -> None #

Restore previous Project.CURRENT.

Source code in src/xpdeep/project.py
def __exit__(
    self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> None:
    """Restore previous Project.CURRENT."""
    Project.CURRENT.reset(self.token)

list_datasets() -> list[DatasetModel] #

List all datasets in this project.

Source code in src/xpdeep/project.py
@initialized_client_verification
def list_datasets(self) -> list[DatasetModel]:
    """List all datasets in this project."""
    client_factory = ClientFactory.CURRENT.get()
    with client_factory() as client:
        return cast("list[DatasetModel]", get_many_datasets.sync(self.model.id, client=client))

list_trained_models() -> list[TrainedModelModel] #

List all trained models in this project.

Source code in src/xpdeep/project.py
@initialized_client_verification
def list_trained_models(self) -> list[TrainedModelModel]:
    """List all trained models in this project."""
    client_factory = ClientFactory.CURRENT.get()
    with client_factory() as client:
        return cast("list[TrainedModelModel]", get_many_trained_models.sync(self.model.id, client=client))

list_explanations() -> list[ExplanationModel] #

List all explanations in this project.

Source code in src/xpdeep/project.py
@initialized_client_verification
def list_explanations(self) -> list[ExplanationModel]:
    """List all explanations in this project."""
    client_factory = ClientFactory.CURRENT.get()
    with client_factory() as client:
        return cast("list[ExplanationModel]", get_many_explanations.sync(self.model.id, client=client))

delete() -> None #

Delete this project.

Also deletes all artifacts in this project recursively. WARNING: not recoverable

Source code in src/xpdeep/project.py
@initialized_client_verification
def delete(self) -> None:
    """Delete this project.

    Also deletes all artifacts in this project recursively. WARNING: not recoverable
    """
    client_factory = ClientFactory.CURRENT.get()
    with client_factory() as client:
        delete_project.sync(self.model.id, client=client)
    del self.model

set_project(project: Project) -> None #

Set the current project.

Source code in src/xpdeep/project.py
def set_project(project: Project) -> None:
    """Set the current project."""
    Project.CURRENT.set(project)

get_project() -> Project | None #

Get the current project.

Source code in src/xpdeep/project.py
def get_project() -> Project | None:
    """Get the current project."""
    try:
        return Project.CURRENT.get()
    except LookupError:
        return None