Skip to content

xpdeep

Xpdeep.

Modules:

Name Description
client_factory

The client factory module is responsible for creating a client instance.

dataset

Manage data upload to be processed by xpdeep.

explain

Define the explain package, used to compute explanations.

filtering

Filtering module.

initialize

Initialize the API.

metrics

Implement metric objects, to be used to monitor the training or in the explanation.

model

The model package provides tools for working with Xpdeep models.

project

Define a project.

trainer

Define the trainer package, used to train the XpdeepModel.

utils

Utils package.

Classes:

Name Description
Project

A project is used to organize your artifacts.

Functions:

Name Description
init

Initialize the Xpdeep API with an API key.

get_project

Get the current project.

set_project

Set the current project.

__all__ = ('Project', 'get_project', 'init', 'set_project') #

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

A project is used to organize your artifacts.

Methods:

Name Description
__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.

downloads

Download all authorized artifacts.

Attributes:

Name Type Description
CURRENT ContextVar[Project]
model
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."""

init(api_key: str, api_url: str = 'https://xpdeep.com/api') -> None #

Initialize the Xpdeep API with an API key.

To generate an API key, please refer to the documentation.

https://docs.xpdeep.com/latest/Getting%20started/installation/#get-an-api-key

Source code in src/xpdeep/initialize.py
def init(
    api_key: str,
    api_url: str = "https://xpdeep.com/api",
) -> None:
    """Initialize the Xpdeep API with an API key.

    To generate an API key, please refer to the documentation.

    https://docs.xpdeep.com/latest/Getting%20started/installation/#get-an-api-key
    """
    ClientFactory.CURRENT.set(ClientFactory(api_key, api_url))
    with ClientFactory.CURRENT.get()() as client:
        try:
            response = check_auth.sync(client=client)
        except UnexpectedStatus as exc:
            if exc.status_code == 401:  # noqa: PLR2004
                msg = (
                    "Please check your API key:\n"
                    "https://docs.xpdeep.com/latest/Getting%20started/installation/#get-an-api-key"
                )
                raise RuntimeError(msg) from exc
            if exc.status_code == 404:  # noqa: PLR2004
                msg = "Please check your API URL. Does it end with '/api'?"
                raise RuntimeError(msg) from exc
            raise
        if response is not None:
            logger.debug("authenticated: user_id=%s, tenant_id=%s", response.id, response.tenant_id)

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

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)