Beaker Python Client
beaker-py is a lightweight, standalone, pure Python client for the Beaker platform, which is a machine learning experiment and dataset management system. It provides an RPC-based client to interact with Beaker servers. The library is actively maintained, with its latest version being 2.6.0, and follows a continuous release cadence.
Common errors
-
Failed to interact with Beaker: BeakerPermissionsError: User does not have permission...
cause The authenticated user lacks the necessary permissions for the requested operation or resource.fixCheck the permissions for your Beaker user token or the configured user within the Beaker platform. Ensure the default workspace specified has the correct access rights for your user. -
Failed to interact with Beaker: BeakerConfigurationError: No Beaker configuration file found at ... or BEAKER_TOKEN environment variable set.
cause The Beaker client could not find valid authentication credentials.fixSet the `BEAKER_TOKEN` environment variable, e.g., `export BEAKER_TOKEN="your_token"`, or ensure a valid `~/.beaker/config.yml` file exists with your Beaker configuration. -
Failed to interact with Beaker: BeakerWorkspaceNotFound: Workspace 'your_org/non_existent_workspace' not found.
cause The specified Beaker workspace either does not exist or the authenticated user does not have access to it.fixVerify the exact name or ID of the workspace in the Beaker UI or CLI. Ensure your `BEAKER_TOKEN` grants access to this specific workspace.
Warnings
- breaking Version 2.x introduces significant breaking changes from version 1.x. The project codebase and documentation location also moved. Old imports and API calls from `beaker-py<2.0` will not work with `beaker-py>=2.0`.
- gotcha Authentication and configuration are critical. The client relies on a `BEAKER_TOKEN` environment variable or a configuration file at `~/.beaker/config.yml`. Without proper credentials, most operations will fail with authentication or permission errors.
- gotcha Do not confuse `beaker-py` (client for AllenAI's Beaker platform) with the `beaker` library (a session and caching library). They are distinct projects with different purposes and APIs.
Install
-
pip install beaker-py -
pip install 'beaker-py<2.0'
Imports
- Beaker
from beaker import Beaker
Quickstart
import os
from beaker import Beaker
# Ensure BEAKER_TOKEN environment variable is set or a ~/.beaker/config.yml exists
# Example: export BEAKER_TOKEN="your_beaker_user_token"
# Or, for a quick demonstration without a real token (will likely fail auth):
# os.environ['BEAKER_TOKEN'] = os.environ.get('BEAKER_TOKEN', 'dummy-token-for-example')
try:
# Instantiate the Beaker client, optionally specifying a default workspace
with Beaker.from_env(default_workspace="your_org/your_workspace") as beaker:
# Example: List datasets (requires proper auth and workspace)
print(f"Beaker client initialized for workspace: {beaker.workspace.current.name}")
datasets = beaker.dataset.list()
if datasets:
print(f"Found {len(datasets)} datasets, e.g., {datasets[0].name}")
else:
print("No datasets found or unable to list.")
except Exception as e:
print(f"Failed to interact with Beaker: {e}")
print("Please ensure BEAKER_TOKEN is set or ~/.beaker/config.yml is configured correctly.")