TrueFoundry SDK
The TrueFoundry Python SDK provides convenient access to the TrueFoundry API, enabling users to programmatically interact with the platform. It supports managing applications, deployments, workspaces, and offers capabilities for ML experiment tracking and interacting with ML repositories. The SDK is currently at version 0.2.0 and has an active release cadence, with frequent updates. It is designed to work with the TrueFoundry MLOps platform, which includes an AI Gateway, deployment tools, and observability features.
Warnings
- breaking The `include_virtual_accounts` parameter has been removed from `client.users.list()`. Calling this method with the removed parameter will result in a `TypeError`.
- breaking Some type fields have been removed in version 0.2.0. Specific details on which fields are affected are not provided in the release notes snippet, but this indicates potential changes in data structures returned by the API.
- gotcha The TrueFoundry Python SDK is programmatically generated. Direct contributions or modifications to the library's source code will likely be overwritten in subsequent releases.
- gotcha There are two main ways to interact: the `truefoundry_sdk.TrueFoundry` client for general platform interactions (applications, users) and `truefoundry.ml.get_client()` for ML-specific functionalities (experiment tracking, ML repositories). Using the wrong client for a specific task can lead to errors.
- gotcha Proper configuration of `api_key` and `base_url` is crucial. The `base_url` might vary depending on whether you are interacting with your TrueFoundry instance directly or through the TrueFoundry AI Gateway, especially when integrating with other SDKs like OpenAI or Anthropic.
Install
-
pip install truefoundry-sdk
Imports
- TrueFoundry
from truefoundry_sdk import TrueFoundry
- get_client
from truefoundry.ml import get_client
Quickstart
import os
from truefoundry_sdk import TrueFoundry
# It's recommended to store API keys securely, e.g., via environment variables.
API_KEY = os.environ.get('TRUEFOUNDRY_API_KEY', 'YOUR_TRUEFOUNDRY_API_KEY')
# The base_url should point to your TrueFoundry instance or Gateway.
BASE_URL = os.environ.get('TRUEFOUNDRY_BASE_URL', 'https://api.truefoundry.com')
if API_KEY == 'YOUR_TRUEFOUNDRY_API_KEY':
print("Warning: Please replace 'YOUR_TRUEFOUNDRY_API_KEY' with your actual API key or set the TRUEFOUNDRY_API_KEY environment variable.")
if BASE_URL == 'https://api.truefoundry.com':
print("Note: Using default TrueFoundry API base URL. Adjust TRUEFOUNDRY_BASE_URL if needed.")
client = TrueFoundry(
api_key=API_KEY,
base_url=BASE_URL,
)
try:
# Example: List applications in a workspace
# Replace 'your-workspace-fqn' with an actual workspace FQN from your TrueFoundry setup
applications_page = client.applications.list(workspace_fqn='your-workspace-fqn', limit=1)
print(f"Found {len(applications_page.items)} application(s) in workspace 'your-workspace-fqn'.")
if applications_page.items:
print(f"First application name: {applications_page.items[0].name}")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure 'your-workspace-fqn' is a valid workspace and your API key and base URL are correct.")