mantik.utils.mantik_api.run

Attributes

logger

Classes

GPUInfo

NoteBookSource

A class representing the source of a notebook, including its location,

ProviderType

Create a collection of name/value pairs.

RunInfrastructure

Functions

check_notebook_type(→ Optional[ProviderType])

Determines the type of notebook environment in which the code is

get_download_artifact_url(project_id, run_id, token)

get_latest_git_commit(→ str)

Retrieves the latest Git commit hash from the current repository.

save_run(project_id, run_data, token)

submit_run(project_id, submit_run_data, token)

update_logs(project_id, run_id, logs, token)

update_notebook_source(project_id, run_id, ...)

Updates the notebook source for a specific run within a project.

update_run_infrastructure(project_id, run_id, ...)

update_run_status(project_id, run_id, status, token)

Module Contents

class mantik.utils.mantik_api.run.GPUInfo[source]
driver: str[source]
classmethod from_dict(_dict)[source]
id: str[source]
name: str[source]
to_json()[source]
total_memory: str[source]
class mantik.utils.mantik_api.run.NoteBookSource[source]

A class representing the source of a notebook, including its location, version, and provider.

This class encapsulates details about a notebook’s origin, such as whether it is hosted on Google Colab or located locally. It provides functionality to represent the notebook information as JSON and to create instances based on the execution environment.

location[source]

The location of the notebook. This can be a URL

Type:

str

(e.g., for Google Colab)

or a local file path.

version[source]

The version of the notebook, typically

Type:

Optional[str]

derived from a Git commit,

if available. This may not always be set (e.g., in environments like Google Colab).

provider[source]

The provider of the notebook, such as

Type:

ProviderType

Google Colab or local execution.
to_json() dict[source]

Converts the notebook source details into a JSON-serializable dictionary.

create_instance(provider

ProviderType) -> “NoteBookSource”: Creates a new instance of NoteBookSource based on the specified

provider. Handles

environment-specific logic, such as detecting the Colab container hostname or using the local file path.

For Google Colab:
  • Resolves the container hostname and IP address.

  • Sends a request to the Colab API to retrieve session

details. - Constructs a URL pointing to the active notebook in Colab.

For local execution:
  • Uses the current file path as the notebook location.

  • Retrieves the latest Git commit hash as the version.

Raises:
  • RuntimeError – If environment-specific detection fails (e.g., failure to retrieve

  • Colab session details or hostname resolution issues).

classmethod create_instance(provider: ProviderType) NoteBookSource[source]
location: str[source]
provider: ProviderType[source]
to_json() dict[source]
version: str | None[source]
class mantik.utils.mantik_api.run.ProviderType(*args, **kwds)[source]

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

COLAB = 'Colab'[source]
JUPYTER = 'Jupyter'[source]
class mantik.utils.mantik_api.run.RunInfrastructure[source]
cpu_cores: int[source]
classmethod from_system()[source]
gpu_count: int[source]
gpu_info: List[GPUInfo][source]
hostname: str[source]
memory_gb: str[source]
os: str[source]
platform: str[source]
processor: str[source]
python_executable: str[source]
python_version: str[source]
to_json()[source]
mantik.utils.mantik_api.run.check_notebook_type() ProviderType | None[source]

Determines the type of notebook environment in which the code is running.

Returns:

Optional[ProviderType]
  • ProviderType.JUPYTER: Running in Jupyter notebook

  • ProviderType.COLAB: Running in Google Colab

  • None: Running in IPython terminal or standard Python interpreter

Notes

  • This function uses ipython.get_ipython() to detect the type of interactive shell currently running.

  • It relies on checking substrings in the shell’s type to

distinguish

between Jupyter, Google Colab, and other environments.

  • ProviderType is assumed to be an enum or class that defines constants for different notebook types (e.g., Jupyter, Colab).

mantik.utils.mantik_api.run.get_download_artifact_url(project_id: uuid.UUID, run_id: uuid.UUID, token: str)[source]
mantik.utils.mantik_api.run.get_latest_git_commit() str[source]

Retrieves the latest Git commit hash from the current repository.

Returns:

The latest Git commit hash as a string if the command executes successfully.

If the current directory is not a Git repository or there are no commits, returns “Not a git repository or no git commit found”. If an unexpected exception occurs, returns an error message with the exception details.

Return type:

str

Exceptions:
  • Handles subprocess.CalledProcessError if the git rev-parse

command fails. - Handles any other exceptions and returns a descriptive error message.

mantik.utils.mantik_api.run.logger[source]
mantik.utils.mantik_api.run.save_run(project_id: uuid.UUID, run_data: dict, token: str)[source]
mantik.utils.mantik_api.run.submit_run(project_id: uuid.UUID, submit_run_data: dict, token: str)[source]
mantik.utils.mantik_api.run.update_logs(project_id: uuid.UUID, run_id: uuid.UUID, logs: str, token: str)[source]
mantik.utils.mantik_api.run.update_notebook_source(project_id: uuid.UUID, run_id: uuid.UUID, notebook_source: NoteBookSource, token: str)[source]

Updates the notebook source for a specific run within a project.

Parameters:
  • project_id (uuid.UUID) – The unique identifier of the project.

  • run_id (uuid.UUID) – The unique identifier of the run.

  • notebook_source (NoteBookSource) – An object containing the notebook

  • updated. (source data to be)

  • token (str) – The authentication token used to authorize the API

  • request.

Returns:

Status code returned from Mantik API after update process.

Return type:

Response

Raises:

Any exceptions raised during the API request will propagate.

Side Effects:
  • Logs a success message if the update is completed successfully.

mantik.utils.mantik_api.run.update_run_infrastructure(project_id: uuid.UUID, run_id: uuid.UUID, infrastructure: RunInfrastructure, token: str)[source]
mantik.utils.mantik_api.run.update_run_status(project_id: uuid.UUID, run_id: uuid.UUID, status: str, token: str)[source]