Skip to content

project

Define a project.

Project(id: str, *, name: str | None = None, description: str | None = None) #

A project is used to organize your artifacts.

Source code in src/xpdeep/project.py
@initialized_client_verification
def __init__(self, id: str, *, name: str | None = None, description: str | None = None) -> None:  # noqa: A002
    try:
        self.model = cast(ProjectModel, get_one_project.sync(id, client=ClientFactory.CURRENT.get()()))
    except UnexpectedStatus as exc:
        if exc.status_code == HTTPStatus.NOT_FOUND:
            self.model = cast(
                ProjectModel,
                create_project.sync(
                    body=ProjectCreateRequestBody(
                        id=id,
                        name=name if name is not None else id,
                        description=description if description is not None else "",
                    ),
                    client=ClientFactory.CURRENT.get()(),
                ),
            )
        else:
            raise

    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),
            ),
        )

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

model = cast(ProjectModel, get_one_project.sync(id, client=ClientFactory.CURRENT.get()())) #

__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

downloads() -> None #

Download all authorized artifacts.

Source code in src/xpdeep/project.py
def downloads(self) -> None:
    """Download all authorized artifacts."""

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

get_all_projects() -> list[ProjectModel] #

Get all accessible projects.

Source code in src/xpdeep/project.py
@initialized_client_verification
def get_all_projects() -> list[ProjectModel]:
    """Get all accessible projects."""
    return cast(list[ProjectModel], get_client_projects.sync(client=ClientFactory.CURRENT.get()()))