> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TrueFoundry ML Client

> Main client for TrueFoundry ML operations - manage ML repos, runs, models, and artifacts

MlFoundry.

## Properties

## Methods

<Accordion title="list_ml_repos">
  Returns a list of names of ML Repos accessible by the current user.

  #### Returns

  <ResponseField name="return" type="List[str]" />

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  # Get all ML repos accessible by the current user
  ml_repos = client.list_ml_repos()
  print(f'Found {len(ml_repos)} ML repos:')
  for repo in ml_repos:
      print(f'  - {repo}')
  ```
</Accordion>

<Accordion title="create_ml_repo">
  Creates an ML Repository.

  #### Parameters

  <ParamField body="name" type="str" required />

  <ParamField body="storage_integration_fqn" type="str" required />

  <ParamField body="description" type="Optional[str]" default="None" />

  #### Returns

  <ResponseField name="return" type="None" />

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  # Create a new ML repository
  client.create_ml_repo(
      name="my-ml-repo",
      storage_integration_fqn="your-storage-integration-fqn",
      description="My ML repository for experiments"
  )
  ```
</Accordion>

<Accordion title="create_run">
  Initialize a `run`.

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  <ParamField body="run_name" type="Optional[str]" default="None" />

  <ParamField body="tags" type="Optional[Dict[str, Any]]" default="None" />

  #### Returns

  <ResponseField name="return" type="MlFoundryRun">
    [🔗 MlFoundryRun](/docs/truefoundry-ml-reference/types#mlfoundryrun)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.create_run(
      ml_repo="my-ml-repo",
      run_name="my-run",
      tags={"key": "value"},
  )
  ```
</Accordion>

<Accordion title="get_run_by_id">
  Get an existing `run` by the `run_id`.

  #### Parameters

  <ParamField body="run_id" type="str" required />

  #### Returns

  <ResponseField name="return" type="MlFoundryRun">
    [🔗 MlFoundryRun](/docs/truefoundry-ml-reference/types#mlfoundryrun)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.get_run_by_id(
      run_id="run-id-123",
  )
  ```
</Accordion>

<Accordion title="get_run_by_fqn">
  Get an existing `run` by `fqn`.

  #### Parameters

  <ParamField body="run_fqn" type="str" required />

  #### Returns

  <ResponseField name="return" type="MlFoundryRun">
    [🔗 MlFoundryRun](/docs/truefoundry-ml-reference/types#mlfoundryrun)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.get_run_by_fqn(
      run_fqn="value",
  )
  ```
</Accordion>

<Accordion title="get_run_by_name">
  Get an existing `run` by `run_name`.

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  <ParamField body="run_name" type="str" required />

  #### Returns

  <ResponseField name="return" type="MlFoundryRun">
    [🔗 MlFoundryRun](/docs/truefoundry-ml-reference/types#mlfoundryrun)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.get_run_by_name(
      ml_repo="my-ml-repo",
      run_name="my-run",
  )
  ```
</Accordion>

<Accordion title="search_runs">
  The user must have `READ` access to the ML Repo.

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  <ParamField body="filter_string" type="str" />

  <ParamField body="run_view_type" type="ViewType" default="value">
    [🔗 ViewType](/docs/truefoundry-ml-reference/enums#viewtype)
  </ParamField>

  <ParamField body="order_by" type="Sequence[str]" default="..." />

  <ParamField body="job_run_name" type="Optional[str]" default="None" />

  #### Returns

  <ResponseField name="return" type="Iterator[MlFoundryRun]">
    [🔗 MlFoundryRun](/docs/truefoundry-ml-reference/types#mlfoundryrun)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.search_runs(
      ml_repo="my-ml-repo",
      filter_string="value",
      run_view_type="value",
      order_by="value",
      job_run_name="value",
  )

  # Iterate through results
  for item in response:
      print(item.name)
  ```
</Accordion>

<Accordion title="get_model_version">
  Get the model version to download contents or load it in memory

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  <ParamField body="name" type="str" required />

  <ParamField body="version" type="Union[str, int]" default="constants.LATEST_ARTIFACT_OR_MODEL_VERSION" />

  #### Returns

  <ResponseField name="return" type="Optional[ModelVersion]">
    [🔗 ModelVersion](/docs/truefoundry-ml-reference/types#modelversion)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.get_model_version(
      ml_repo="my-ml-repo",
      name="my-run",
      version="value",
  )
  ```
</Accordion>

<Accordion title="get_model_version_by_fqn">
  Get the model version to download contents or load it in memory

  #### Parameters

  <ParamField body="fqn" type="str" required />

  #### Returns

  <ResponseField name="return" type="ModelVersion">
    [🔗 ModelVersion](/docs/truefoundry-ml-reference/types#modelversion)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.get_model_version_by_fqn(
      fqn="run-id-123",
  )
  ```
</Accordion>

<Accordion title="list_model_versions">
  Get all the version of a model to download contents or load them in memory

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  <ParamField body="name" type="str" required />

  #### Returns

  <ResponseField name="return" type="Iterator[ModelVersion]">
    [🔗 ModelVersion](/docs/truefoundry-ml-reference/types#modelversion)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.list_model_versions(
      ml_repo="my-ml-repo",
      name="my-run",
  )
  ```
</Accordion>

<Accordion title="list_model_versions_by_fqn">
  List versions for a given model

  #### Parameters

  <ParamField body="model_fqn" type="str" required />

  #### Returns

  <ResponseField name="return" type="Iterator[ModelVersion]">
    [🔗 ModelVersion](/docs/truefoundry-ml-reference/types#modelversion)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.list_model_versions_by_fqn(
      model_fqn="value",
  )
  ```
</Accordion>

<Accordion title="get_artifact_version">
  Get the model version to download contents or load it in memory

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  <ParamField body="name" type="str" required />

  <ParamField body="artifact_type" type="Optional[ArtifactType]" default="ArtifactType.ARTIFACT">
    [🔗 ArtifactType](/docs/truefoundry-ml-reference/enums#artifacttype)
  </ParamField>

  <ParamField body="version" type="Union[str, int]" default="constants.LATEST_ARTIFACT_OR_MODEL_VERSION" />

  #### Returns

  <ResponseField name="return" type="Optional[ArtifactVersion]">
    [🔗 ArtifactVersion](/docs/truefoundry-ml-reference/types#artifactversion)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.get_artifact_version(
      ml_repo="my-ml-repo",
      name="my-run",
      artifact_type="value",
      version="value",
  )
  ```
</Accordion>

<Accordion title="get_artifact_version_by_fqn">
  Get the artifact version to download contents

  #### Parameters

  <ParamField body="fqn" type="str" required />

  #### Returns

  <ResponseField name="return" type="ArtifactVersion">
    [🔗 ArtifactVersion](/docs/truefoundry-ml-reference/types#artifactversion)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.get_artifact_version_by_fqn(
      fqn="run-id-123",
  )
  ```
</Accordion>

<Accordion title="list_artifact_versions">
  Get all the version of na artifact to download contents or load them in memory

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  <ParamField body="name" type="str" required />

  <ParamField body="artifact_type" type="Optional[ArtifactType]" default="ArtifactType.ARTIFACT">
    [🔗 ArtifactType](/docs/truefoundry-ml-reference/enums#artifacttype)
  </ParamField>

  #### Returns

  <ResponseField name="return" type="Iterator[ArtifactVersion]">
    [🔗 ArtifactVersion](/docs/truefoundry-ml-reference/types#artifactversion)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.list_artifact_versions(
      ml_repo="my-ml-repo",
      name="my-run",
      artifact_type="value",
  )
  ```
</Accordion>

<Accordion title="list_artifact_versions_by_fqn">
  List versions for a given artifact

  #### Parameters

  <ParamField body="artifact_fqn" type="str" required />

  #### Returns

  <ResponseField name="return" type="Iterator[ArtifactVersion]">
    [🔗 ArtifactVersion](/docs/truefoundry-ml-reference/types#artifactversion)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.list_artifact_versions_by_fqn(
      artifact_fqn="value",
  )
  ```
</Accordion>

<Accordion title="log_artifact">
  Logs an artifact for the current `ml_repo`.

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  <ParamField body="name" type="str" required />

  <ParamField body="artifact_paths" type="List[Union[Tuple[str], Tuple[str, Optional[str]], ArtifactPath]]" required>
    [🔗 ArtifactPath](/docs/truefoundry-ml-reference/types#artifactpath)
  </ParamField>

  <ParamField body="description" type="Optional[str]" default="None" />

  <ParamField body="metadata" type="Optional[Dict[str, Any]]" default="None" />

  <ParamField body="progress" type="Optional[bool]" default="None" />

  #### Returns

  <ResponseField name="return" type="Optional[ArtifactVersion]">
    [🔗 ArtifactVersion](/docs/truefoundry-ml-reference/types#artifactversion)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.log_artifact(
      ml_repo="my-ml-repo",
      name="my-run",
      artifact_paths=[ArtifactPath("file.txt")],
      description="value",
      metadata="value",
      progress="value",
  )
  ```
</Accordion>

<Accordion title="log_model">
  Serialize and log a versioned model under the current ml\_repo. Each logged model generates a new version

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  <ParamField body="name" type="str" required />

  <ParamField body="model_file_or_folder" type="Union[str, BlobStorageDirectory]" required>
    [🔗 BlobStorageDirectory](/docs/truefoundry-ml-reference/types#blobstoragedirectory)
  </ParamField>

  <ParamField body="description" type="Optional[str]" default="None" />

  <ParamField body="metadata" type="Optional[Dict[str, Any]]" default="None" />

  <ParamField body="progress" type="Optional[bool]" default="None" />

  <ParamField body="framework" type="Optional[Union[str, ModelFramework, Any]]" default="None">
    [🔗 ModelFramework](/docs/truefoundry-ml-reference/enums#modelframework)
  </ParamField>

  <ParamField body="environment" type="Optional[ModelVersionEnvironment]" default="None">
    [🔗 ModelVersionEnvironment](/docs/truefoundry-ml-reference/types#modelversionenvironment)
  </ParamField>

  #### Returns

  <ResponseField name="return" type="ModelVersion">
    [🔗 ModelVersion](/docs/truefoundry-ml-reference/types#modelversion)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.log_model(
      ml_repo="my-ml-repo",
      name="my-run",
      model_file_or_folder="model.pkl",
      description="value",
      metadata="value",
      progress="value",
      framework="value",
      environment="value",
  )
  ```
</Accordion>

<Accordion title="create_data_directory">
  Create DataDirectory to Upload the files

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  <ParamField body="name" type="str" required />

  <ParamField body="description" type="Optional[str]" default="None" />

  <ParamField body="metadata" type="Optional[Dict[str, Any]]" default="None" />

  #### Returns

  <ResponseField name="return" type="DataDirectory">
    [🔗 DataDirectory](/docs/truefoundry-ml-reference/types#datadirectory)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.create_data_directory(
      ml_repo="my-ml-repo",
      name="my-run",
      description="value",
      metadata="value",
  )
  ```
</Accordion>

<Accordion title="get_data_directory_by_fqn">
  Get the DataDirectory by DataDirectory FQN

  #### Parameters

  <ParamField body="fqn" type="str" required />

  #### Returns

  <ResponseField name="return" type="DataDirectory">
    [🔗 DataDirectory](/docs/truefoundry-ml-reference/types#datadirectory)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.get_data_directory_by_fqn(
      fqn="run-id-123",
  )
  ```
</Accordion>

<Accordion title="get_data_directory">
  Get an existing `data_directory` by `name`.

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  <ParamField body="name" type="str" required />

  #### Returns

  <ResponseField name="return" type="DataDirectory">
    [🔗 DataDirectory](/docs/truefoundry-ml-reference/types#datadirectory)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.get_data_directory(
      ml_repo="my-ml-repo",
      name="my-run",
  )
  ```
</Accordion>

<Accordion title="list_data_directories">
  Get the list of DataDirectory in a ml\_repo

  #### Parameters

  <ParamField body="ml_repo" type="str" required />

  #### Returns

  <ResponseField name="return" type="Iterator[DataDirectory]">
    [🔗 DataDirectory](/docs/truefoundry-ml-reference/types#datadirectory)
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry.ml import get_client

  client = get_client()

  client.list_data_directories(
      ml_repo="my-ml-repo",
  )
  ```
</Accordion>
