Links

Python client reference

A reference for modules and functions included with the Baseten Python client.
Page under construction! This reference is still incomplete but will be finished soon!
Baseten's Python client is the most complete and convenient way to interface with your Baseten account from a local development environment or Jupyter notebook.
Install the Python client with pip install --upgrade baseten. We recommend always using the latest version of the Python client.

baseten module

Baseten module

configure()

You'll only need this argument if you have a custom installation of Baseten or a staging environment.
Arguments:
  • server_url (str): The base URL of the server
Returns:
None, called for side effect only.
Usage:
baseten.configure('https://baseten.yourcompany.com')

create_artifact()

deploy()

Deploy accepts different arguments depending on whether you are deploying a model from a supported framework or a custom model. (supported framework, one of scikit-learn, Keras, XGBoost, LightGBM, Hugging Face, or Pytorch)
Arguments:
  • model (an in-memory model object): A model object to be deployed (e.g. a RandomForestClassifier object).
  • model_name (str, optional): The name of the model to be created, if necessary.
  • model_files (List[str], optional): Additional files required for model definition, e.g class definitions for pytorch models.
  • feature_names (List[str], optional): The list of feature names. If not provided, a list of feature names that match the model's input dimensions will be automatically generated. If the model's input has multiple dimensions, feature_names should be a flattened list of names.
  • class_labels (List[str], optional): The list of target class labels, if applicable.
  • version_bump (str, optional): The version bump for this deployment, one of 'MAJOR', 'MINOR', 'PATCH'.
Usage:
baseten_model = baseten.deploy(
model=,
model_name=,
model_files=,
feature_names=,
class_labels=,
version_bump='MAJOR'
)

deploy_custom()

Arguments:
  • model_name (str): The name of the model to be created.
  • model_class (str): The name of the model class which implements load and predict methods, defined in one of the model_files.
  • model_files (List[str]): A list of files — which must include the file containing model_class — to include with the model deployment, including serialized models, python files, data, embeddings, etc. Files will match based on pathname patterns, eg *.py will match all python files in the current working directory.
  • requirements_file (str, optional): A requirements.txt file specifying requirements to be installed alongside the model.
  • version_bump (str, optional): The version bump for this deployment, one of 'MAJOR', 'MINOR', 'PATCH'. Defaults to 'MINOR'.
baseten_model = baseten.deploy(
model_name=,
model_class=,
model_files=,
requirements_file=,
version_bump='MAJOR'
)
For further details about deployment, read about Truss, an open-source tool for model deployment build by Baseten.

deployed_artifact_id()

deployed_model_id()

deployed_model_version_id()

login()

This method uses an API key to authenticate your local environment to your Baseten account. Generate an API key here.
Arguments:
  • api_key (str): an API key on your account.
Returns:
None, called for side effect only.
Usage:
import os
baseten.login(os.environ['BASETEN_API_KEY'])
Log in before deploying any models or requesting any permissions.
Your Baseten API key is a secret and should be treated accordingly. Do not hardcode it into your Python file or otherwise commit it to your code repository.

models_summary()

artifact object

Artifact object

model object

When you call deployed_model_id() or deployed_model_version_id(), you get back an object that represents a deployed model on baseten. Let's run down the essential functions:

install_requirements()

predict()