Client#
- class beaker.Beaker(config, check_for_upgrades=True, timeout=5.0, session=None, pool_maxsize=None, user_agent='beaker-py v1.31.3')[source]#
Bases:
object
A client for interacting with Beaker.
- Parameters:
check_for_upgrades (
bool
, default:True
) – Automatically check that beaker-py is up-to-date. You’ll see a warning if it isn’t.timeout (
Union
[float
,Tuple
[float
,float
],None
], default:5.0
) – How many seconds to wait for the Beaker server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.session (
Union
[bool
,Session
,None
], default:None
) –Set to
True
or arequests.Session
instance to force the Beaker client to use a singleSession
for all HTTP requests to the Beaker server for the life of the client.See also
The
session()
context manager.pool_maxsize (
Optional
[int
], default:None
) – The maximum size of the connection pool to use. If not specified, a large default value will be used based on a multiple of the number of CPUs available.user_agent (
str
, default:'beaker-py v1.31.3'
) – Override the “User-Agent” header used in requests to the Beaker server.
The easiest way to initialize a Beaker client is with
from_env()
:>>> beaker = Beaker.from_env()
You can then interact with the various Beaker services through the corresponding property. For example, to manage workspaces, use
Beaker.workspace
:>>> beaker.workspace.get(workspace_name).full_name 'ai2/beaker-py-testing'
Tip
Use the right side nav to browse through the API docs for all of the different services.
- RECOVERABLE_SERVER_ERROR_CODES = (429, 500, 502, 503, 504)#
- MAX_RETRIES = 5#
- BACKOFF_FACTOR = 1#
- BACKOFF_MAX = 120#
- API_VERSION = 'v3'#
- CLIENT_VERSION = '1.31.3'#
- VERSION_CHECK_INTERVAL = 43200#
- logger = <Logger beaker (WARNING)>#
- classmethod from_env(check_for_upgrades=True, timeout=30.0, session=None, pool_maxsize=None, user_agent='beaker-py v1.31.3', **overrides)[source]#
Initialize client from a config file and/or environment variables.
- Parameters:
check_for_upgrades (
bool
, default:True
) – Automatically check that beaker-py is up-to-date. You’ll see a warning if it isn’t.timeout (
Union
[float
,Tuple
[float
,float
],None
], default:30.0
) – How many seconds to wait for the Beaker server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.session (
Union
[bool
,Session
,None
], default:None
) –Set to
True
or arequests.Session
instance to force the Beaker client to use a singleSession
for all HTTP requests to the Beaker server.See also
The
session()
context manager.pool_maxsize (
Optional
[int
], default:None
) – The maximum size of the connection pool to use. If not specified, a large default value will be used based on a multiple of the number of CPUs available.user_agent (
str
, default:'beaker-py v1.31.3'
) – Override the “User-Agent” header used in requests to the Beaker server.overrides – Fields in the
Config
to override.
- Return type:
Note
This will use the same config file that the Beaker command-line client creates and uses, which is usually located at
$HOME/.beaker/config.yml
.If you haven’t configured the command-line client, then you can alternately just set the environment variable
BEAKER_TOKEN
to your Beaker user token.
- session(session=None)[source]#
A context manager that forces the Beaker client to reuse a single
requests.Session
for all HTTP requests to the Beaker server.This can improve performance when calling a series of a client methods in a row.
- Examples:
>>> with beaker.session(): ... n_images = len(beaker.workspace.images()) ... n_datasets = len(beaker.workspace.datasets())
- property account: AccountClient#
Manage accounts.
- Examples:
>>> beaker.account.name 'petew'
Tip
See the Accounts Overview for a walk-through of the main methods, or check out the Account API Docs to see all of the available methods.
- property organization: OrganizationClient#
Manage organizations.
- Examples:
>>> beaker.organization.get("ai2").display_name 'AI2'
Tip
See the Organizations Overview for a walk-through of the main methods, or check out the Organization API Docs to see all of the available methods.
- property workspace: WorkspaceClient#
Manage workspaces.
Tip
See the Workspaces Overview for a walk-through of the main methods, or check out the Workspace API Docs to see all of the available methods.
- property cluster: ClusterClient#
Manage clusters.
- Examples:
>>> beaker.cluster.get(beaker_cluster_name).name 'ai2/canary'
Tip
See the Clusters Overview for a walk-through of the main methods, or check out the Cluster API Docs to see all of the available methods.
- property node: NodeClient#
Manage nodes.
- Examples:
>>> beaker.node.get(beaker_node_id).limits.gpu_count 8
Tip
See the Nodes Overview for a walk-through of the main methods, or check out the Node API Docs to see all of the available methods.
- property dataset: DatasetClient#
Manage datasets.
Tip
See the Datasets Overview for a walk-through of the main methods, or check out the Dataset API Docs to see all of the available methods.
- property image: ImageClient#
Manage images.
- Examples:
>>> beaker.image.get("petew/hello-world").original_tag 'hello-world'
Tip
See the Images Overview for a walk-through of the main methods, or check out the Image API Docs to see all of the available methods.
- property job: JobClient#
Manage jobs.
- Examples:
>>> running_jobs = beaker.job.list( ... cluster=beaker_on_prem_cluster_name, ... finalized=False, ... )
Tip
See the Jobs Overview for a walk-through of the main methods, or check out the Job API Docs to see all of the available methods.
- property experiment: ExperimentClient#
Manage experiments.
- Examples:
>>> logs = "".join([ ... line.decode() for line in ... beaker.experiment.logs("petew/hello-world", quiet=True) ... ])
Tip
See the Experiments Overview for a walk-through of the main methods, or check out the Experiment API Docs to see all of the available methods.
- property secret: SecretClient#
Manage secrets.
- Examples:
>>> secret = beaker.secret.write(secret_name, "foo")
Tip
See the Secrets Overview for a walk-through of the main methods, or check out the Secret API Docs to see all of the available methods.
- property group: GroupClient#
Manage groups.
- Examples:
>>> group = beaker.group.create(group_name)
Tip
See the Groups Overview for a walk-through of the main methods, or check out the Group API Docs to see all of the available methods.
- property docker: DockerClient#
Account#
- class beaker.services.AccountClient(beaker)[source]#
Bases:
ServiceClient
Accessed via
Beaker.account
.- property name#
- whoami()[source]#
Check who you are authenticated as.
- Raises:
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- list_organizations()[source]#
List all organizations you are a member of.
- Raises:
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- get(account)[source]#
Get information about an account.
- Parameters:
account (
str
) – The account name or ID.- Raises:
AccountNotFound – If the account doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
Organization#
- class beaker.services.OrganizationClient(beaker)[source]#
Bases:
ServiceClient
Accessed via
Beaker.organization
.- get(org=None)[source]#
Get information about an organization.
- Parameters:
org (
Optional
[str
], default:None
) – The organization name or ID. If not specified,Beaker.config.default_org
is used.- Raises:
OrganizationNotFound – If the organization doesn’t exist.
OrganizationNotSet – If neither
org
norBeaker.config.default_org
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- add_member(account, org=None)[source]#
Add an account to an organization.
- Parameters:
org (
Union
[str
,Organization
,None
], default:None
) – The organization name or object. If not specified,Beaker.config.default_org
is used.
- Raises:
OrganizationNotFound – If the organization doesn’t exist.
OrganizationNotSet – If neither
org
norBeaker.config.default_org
are set.AccountNotFound – If the account doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- get_member(account, org=None)[source]#
Get information about an organization member.
- Parameters:
org (
Union
[str
,Organization
,None
], default:None
) – The organization name or object. If not specified,Beaker.config.default_org
is used.
- Raises:
OrganizationNotFound – If the organization doesn’t exist.
OrganizationNotSet – If neither
org
norBeaker.config.default_org
are set.AccountNotFound – If the account doesn’t exist or isn’t a member of the org.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- list_members(org=None)[source]#
List members of an organization.
- Parameters:
org (
Union
[str
,Organization
,None
], default:None
) – The organization name or object. If not specified,Beaker.config.default_org
is used.- Raises:
OrganizationNotFound – If the organization doesn’t exist.
OrganizationNotSet – If neither
org
norBeaker.config.default_org
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- remove_member(account, org=None)[source]#
Remove a member from an organization.
- Parameters:
org (
Union
[str
,Organization
,None
], default:None
) – The organization name or object. If not specified,Beaker.config.default_org
is used.
- Raises:
OrganizationNotFound – If the organization doesn’t exist.
OrganizationNotSet – If neither
org
norBeaker.config.default_org
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
Workspace#
- class beaker.services.WorkspaceClient(beaker)[source]#
Bases:
ServiceClient
Accessed via
Beaker.workspace
.- get(workspace=None)[source]#
Get information about the workspace.
- Parameters:
workspace (
Optional
[str
], default:None
) – The workspace name or ID. If not specified,Beaker.config.default_workspace
is used.- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- create(workspace, *, description=None, public=None)[source]#
Create a workspace.
- Parameters:
- Raises:
ValueError – If the workspace name is invalid.
WorkspaceConflict – If a workspace by that name already exists.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- ensure(workspace)[source]#
Ensure that the given workspace exists.
- Parameters:
workspace (
str
) – The workspace name.- Raises:
ValueError – If the workspace name is invalid.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- archive(workspace)[source]#
Archive a workspace, making it read-only.
- Parameters:
workspace (
Union
[str
,Workspace
]) – The workspace to archive.- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- unarchive(workspace)[source]#
Unarchive a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
]) – The workspace to unarchive.- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- rename(workspace, name)[source]#
Rename a workspace.
- Parameters:
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
ValueError – If the new name is invalid.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- move(*items, workspace=None)[source]#
Move items into a workspace.
- Parameters:
items (
Union
[str
,Image
,Dataset
,Experiment
]) – The items to move into the workspace.workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name or object. If not specified,Beaker.config.default_workspace
is used.
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- iter(org=None, *, author=None, match=None, archived=None, limit=None, sort_by=WorkspaceSort.created, descending=True, cursor=0)[source]#
- list(org=None, *, author=None, match=None, archived=None, limit=None, sort_by=WorkspaceSort.created, descending=True, cursor=0)[source]#
List workspaces belonging to an organization.
- Parameters:
org (
Union
[str
,Organization
,None
], default:None
) – The organization name or object. If not specified,Beaker.config.default_org
is used.author (
Union
[str
,Account
,None
], default:None
) – Only list workspaces authored by this account.match (
Optional
[str
], default:None
) – Only include workspaces matching the text.archived (
Optional
[bool
], default:None
) – Only include/exclude archived workspaces.limit (
Optional
[int
], default:None
) – Limit the number of workspaces returned.sort_by (
WorkspaceSort
, default:<WorkspaceSort.created: 'created'>
) – The field to sort the results by.descending (
bool
, default:True
) – Order the results in descending order according to thesort_by
field.cursor (
int
, default:0
) – Set the starting cursor for the query. You can use this to paginate the results.
- Raises:
OrganizationNotFound – If the organization doesn’t exist.
OrganizationNotSet – If neither
org
norBeaker.config.default_org
are set.AccountNotFound – If the author account doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- iter_images(workspace=None, *, match=None, limit=None, sort_by=ImageSort.created, descending=True, cursor=0)[source]#
Iterate over the images in a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name or object. If not specified,Beaker.config.default_workspace
is used.match (
Optional
[str
], default:None
) – Only include images matching the text.limit (
Optional
[int
], default:None
) – Limit the number of images returned.sort_by (
ImageSort
, default:<ImageSort.created: 'created'>
) – The field to sort the results by.descending (
bool
, default:True
) – Order the results in descending order according to thesort_by
field.cursor (
int
, default:0
) – Set the starting cursor for the query. You can use this to paginate the results.
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- images(workspace=None, *, match=None, limit=None, sort_by=ImageSort.created, descending=True, cursor=0)[source]#
List the images in a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name or object. If not specified,Beaker.config.default_workspace
is used.match (
Optional
[str
], default:None
) – Only include images matching the text.limit (
Optional
[int
], default:None
) – Limit the number of images returned.sort_by (
ImageSort
, default:<ImageSort.created: 'created'>
) – The field to sort the results by.descending (
bool
, default:True
) – Order the results in descending order according to thesort_by
field.cursor (
int
, default:0
) – Set the starting cursor for the query. You can use this to paginate the results.
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- iter_experiments(workspace=None, *, match=None, limit=None, sort_by=ExperimentSort.created, descending=True, cursor=0)[source]#
Iterate over the experiments in a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name or object. If not specified,Beaker.config.default_workspace
is used.match (
Optional
[str
], default:None
) – Only include experiments matching the text.limit (
Optional
[int
], default:None
) – Limit the number of experiments returned.sort_by (
ExperimentSort
, default:<ExperimentSort.created: 'created'>
) – The field to sort the results by.descending (
bool
, default:True
) – Order the results in descending order according to thesort_by
field.cursor (
int
, default:0
) – Set the starting cursor for the query. You can use this to paginate the results.
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- experiments(workspace=None, *, match=None, limit=None, sort_by=ExperimentSort.created, descending=True, cursor=0)[source]#
List the experiments in a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name or object. If not specified,Beaker.config.default_workspace
is used.match (
Optional
[str
], default:None
) – Only include experiments matching the text.limit (
Optional
[int
], default:None
) – Limit the number of experiments returned.sort_by (
ExperimentSort
, default:<ExperimentSort.created: 'created'>
) – The field to sort the results by.descending (
bool
, default:True
) – Order the results in descending order according to thesort_by
field.cursor (
int
, default:0
) – Set the starting cursor for the query. You can use this to paginate the results.
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- iter_datasets(workspace=None, *, match=None, results=None, uncommitted=None, limit=None, sort_by=DatasetSort.created, descending=True, cursor=0)[source]#
Iterate over the datasets in a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name, or object. If not specified,Beaker.config.default_workspace
is used.match (
Optional
[str
], default:None
) – Only include datasets matching the text.results (
Optional
[bool
], default:None
) – Only include/exclude experiment result datasets.uncommitted (
Optional
[bool
], default:None
) – Only include/exclude uncommitted datasets.limit (
Optional
[int
], default:None
) – Limit the number of datasets returned.sort_by (
DatasetSort
, default:<DatasetSort.created: 'created'>
) – The field to sort the results by.descending (
bool
, default:True
) – Order the results in descending order according to thesort_by
field.cursor (
int
, default:0
) – Set the starting cursor for the query. You can use this to paginate the results.
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- datasets(workspace=None, *, match=None, results=None, uncommitted=None, limit=None, sort_by=DatasetSort.created, descending=True, cursor=0)[source]#
List the datasets in a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name, or object. If not specified,Beaker.config.default_workspace
is used.match (
Optional
[str
], default:None
) – Only include datasets matching the text.results (
Optional
[bool
], default:None
) – Only include/exclude experiment result datasets.uncommitted (
Optional
[bool
], default:None
) – Only include/exclude uncommitted datasets.limit (
Optional
[int
], default:None
) – Limit the number of datasets returned.sort_by (
DatasetSort
, default:<DatasetSort.created: 'created'>
) – The field to sort the results by.descending (
bool
, default:True
) – Order the results in descending order according to thesort_by
field.cursor (
int
, default:0
) – Set the starting cursor for the query. You can use this to paginate the results.
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- secrets(workspace=None)[source]#
List secrets in a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name, or object. If not specified,Beaker.config.default_workspace
is used.- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- iter_groups(workspace=None, *, match=None, limit=None, sort_by=GroupSort.created, descending=True, cursor=0)[source]#
Iterate over groups in a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name, or object. If not specified,Beaker.config.default_workspace
is used.match (
Optional
[str
], default:None
) – Only include groups matching the text.limit (
Optional
[int
], default:None
) – Limit the number of groups returned.sort_by (
GroupSort
, default:<GroupSort.created: 'created'>
) – The field to sort the results by.descending (
bool
, default:True
) – Order the results in descending order according to thesort_by
field.cursor (
int
, default:0
) – Set the starting cursor for the query. You can use this to paginate the results.
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- groups(workspace=None, *, match=None, limit=None, sort_by=GroupSort.created, descending=True, cursor=0)[source]#
List groups in a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name, or object. If not specified,Beaker.config.default_workspace
is used.match (
Optional
[str
], default:None
) – Only include groups matching the text.limit (
Optional
[int
], default:None
) – Limit the number of groups returned.sort_by (
GroupSort
, default:<GroupSort.created: 'created'>
) – The field to sort the results by.descending (
bool
, default:True
) – Order the results in descending order according to thesort_by
field.cursor (
int
, default:0
) – Set the starting cursor for the query. You can use this to paginate the results.
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- get_permissions(workspace=None)[source]#
Get workspace permissions.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name, or object. If not specified,Beaker.config.default_workspace
is used.- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- grant_permissions(auth, *accounts, workspace=None)[source]#
Grant workspace permissions to accounts.
- Parameters:
auth (
Permission
) – The authorization level to grant (e.g. “read”, “write”, “all”).accounts (
Union
[str
,Account
]) – The accounts to grant permissions to.workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name, or object. If not specified,Beaker.config.default_workspace
is used.
- Raises:
ValueError – If
auth
is invalid.AccountNotFound – If an account doesn’t exist.
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- set_visibility(public=False, workspace=None)[source]#
Set workspace visibility to public or private.
- Parameters:
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- revoke_permissions(*accounts, workspace=None)[source]#
Revoke workspace permissions to accounts.
- Parameters:
- Raises:
AccountNotFound – If an account doesn’t exist.
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- url(workspace=None)[source]#
Get the URL for a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name, or object. If not specified,Beaker.config.default_workspace
is used.- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.
- Return type:
- clear(workspace=None, *, groups=True, experiments=True, images=True, datasets=True, secrets=True, older_than=None)[source]#
Remove groups, experiments, images, datasets, and secrets from a workspace.
- Parameters:
workspace (
Union
[str
,Workspace
,None
], default:None
) – The Beaker workspace name, or object. If not specified,Beaker.config.default_workspace
is used.groups (
bool
, default:True
) – Whether to delete groups.experiments (
bool
, default:True
) – Whether to delete experiments.images (
bool
, default:True
) – Whether to delete images.datasets (
bool
, default:True
) – Whether to delete datasets.secrets (
bool
, default:True
) – Whether to delete secrets.older_than (
Optional
[datetime
], default:None
) – Only delete objects created before this date.
- Raises:
WorkspaceNotFound – If the workspace doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
WorkspaceClearResult
Cluster#
- class beaker.services.ClusterClient(beaker)[source]#
Bases:
ServiceClient
Accessed via
Beaker.cluster
.- get(cluster)[source]#
Get information about the cluster.
- Parameters:
cluster (
str
) – The cluster name or ID.- Raises:
ClusterNotFound – If the cluster doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- create(name, max_size=1, preemptible=False, cpus=None, gpus=0, gpu_type=None, memory=None)[source]#
Create a new Beaker cloud cluster.
Note
For creating on-premise clusters you should still use the Beaker CLI.
- Parameters:
name (
str
) – The name to assign to the new cluster. IfConfig.default_org
is not set, the name should start with the name of an organization: “{organization}/{cluster_name}”, e.g. “ai2/my-new-cluster”.max_size (
int
, default:1
) – The maximum number of nodes the cluster can scale up to.preemptible (
bool
, default:False
) – Use preemptible cloud machines for the nodes.cpus (
Optional
[float
], default:None
) – The number of virtual CPU available to each node.gpus (
int
, default:0
) – The number of GPUs available to each node.gpu_type (
Optional
[str
], default:None
) – The type of GPU available to each node.memory (
Optional
[str
], default:None
) – The amount of memory available to each node, specified as a number with a unit suffix. E.g. “2.5GiB”.
- Raises:
ValueError – If the cluster name or requested resources are invalid.
ClusterConflict – If a cluster by that name already exists.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- update(cluster, max_size=None, allow_preemptible=None)[source]#
Modify a cluster.
- Parameters:
- Raises:
ClusterNotFound – If the cluster doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- delete(cluster)[source]#
Delete a cluster.
- Parameters:
cluster (
Union
[str
,Cluster
]) – The cluster ID, full name, or object.- Raises:
ClusterNotFound – If the cluster doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- list(org=None)[source]#
List clusters under an organization.
- Parameters:
org (
Union
[str
,Organization
,None
], default:None
) – The organization name or object. If not specified,Beaker.config.default_org
is used.- Raises:
OrganizationNotFound – If the organization doesn’t exist.
OrganizationNotSet – If neither
org
norBeaker.config.default_org
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- nodes(cluster)[source]#
List the nodes in a cluster.
- Parameters:
cluster (
Union
[str
,Cluster
]) – The cluster ID, full name, or object.- Raises:
ClusterNotFound – If the cluster doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- utilization(cluster)[source]#
Get current utilization stats for each node in a cluster.
- Parameters:
cluster (
Union
[str
,Cluster
]) – The cluster ID, full name, or object.- Raises:
ClusterNotFound – If the cluster doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- filter_available(resources, *clusters)[source]#
Filter out clusters that don’t have enough available resources, returning a list of
ClusterUtilization
for each cluster that has sufficient resources.This can be used, for example, to automatically find an on-premise cluster with enough free resources to run a particular task.
Caution
This method is experimental and may change or be removed in future releases.
- Parameters:
resources (
TaskResources
) – The requested resources.clusters (
Union
[str
,Cluster
]) – Clusters to inspect and filter.
- Raises:
ClusterNotFound – If one of the clusters doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- url(cluster)[source]#
Get the URL for a cluster.
- Parameters:
cluster (
Union
[str
,Cluster
]) – The cluster ID, full name, or object.- Raises:
ClusterNotFound – If the cluster doesn’t exist.
- Return type:
- preempt_jobs(cluster, ignore_failures=False)[source]#
Preempt all preemptible jobs on the cluster.
- Parameters:
- Raises:
ClusterNotFound – If the cluster doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
Node#
- class beaker.services.NodeClient(beaker)[source]#
Bases:
ServiceClient
Accessed via
Beaker.node
.- get(node_id)[source]#
Get information about a node.
- Parameters:
node_id (
str
) – The ID of the node.- Raises:
NodeNotFound – If the node doesn’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
Dataset#
- class beaker.services.DatasetClient(beaker)[source]#
Bases:
ServiceClient
Accessed via
Beaker.dataset
.- HEADER_UPLOAD_ID = 'Upload-ID'#
- HEADER_UPLOAD_LENGTH = 'Upload-Length'#
- HEADER_UPLOAD_OFFSET = 'Upload-Offset'#
- HEADER_DIGEST = 'Digest'#
- HEADER_LAST_MODIFIED = 'Last-Modified'#
- HEADER_CONTENT_LENGTH = 'Content-Length'#
- get(dataset)[source]#
Get info about a dataset.
- Parameters:
dataset (
str
) – The dataset ID or name.- Raises:
DatasetNotFound – If the dataset can’t be found.
RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- create(name, *sources, target=None, workspace=None, description=None, force=False, max_workers=None, quiet=False, commit=True, strip_paths=False)[source]#
Create a dataset with the source file(s).
- Parameters:
name (
str
) – The name to assign to the new dataset.sources (
Union
[PathLike
,str
]) – Local source files or directories to upload to the dataset.target (
Union
[PathLike
,str
,None
], default:None
) – If specified, all source files/directories will be uploaded under a directory of this name.workspace (
Optional
[str
], default:None
) – The workspace to upload the dataset to. If not specified,Beaker.config.default_workspace
is used.description (
Optional
[str
], default:None
) – Text description for the dataset.force (
bool
, default:False
) – IfTrue
and a dataset by the given name already exists, it will be overwritten.max_workers (
Optional
[int
], default:None
) – The maximum number of thread pool workers to use to upload files concurrently.quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.commit (
bool
, default:True
) – Whether to commit the dataset after successful upload.strip_paths (
bool
, default:False
) –If
True
, all source files and directories will be uploaded under their name, not their path. E.g. the file “docs/source/index.rst” would be uploaded as just “index.rst”, instead of “docs/source/index.rst”.Note
This only applies to source paths that are children of the current working directory. If a source path is outside of the current working directory, it will always be uploaded under its name only.
- Raises:
ValueError – If the name is invalid.
DatasetConflict – If a dataset by that name already exists and
force=False
.UnexpectedEOFError – If a source is a directory and the contents of one of the directory’s files changes while creating the dataset.
FileNotFoundError – If a source doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- commit(dataset)[source]#
Commit the dataset.
- Parameters:
dataset (
Union
[str
,Dataset
]) – The dataset ID, name, or object.- Raises:
DatasetNotFound – If the dataset can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- fetch(dataset, target=None, prefix=None, force=False, max_workers=None, quiet=False, validate_checksum=True, chunk_size=None)[source]#
Download a dataset.
- Parameters:
dataset (
Union
[str
,Dataset
]) – The dataset ID, name, or object.target (
Union
[PathLike
,str
,None
], default:None
) – The target path to download fetched data to. Defaults toPath(.)
.prefix (
Optional
[str
], default:None
) – Only download files that start with the given prefix.max_workers (
Optional
[int
], default:None
) – The maximum number of thread pool workers to use to download files concurrently.force (
bool
, default:False
) – IfTrue
, existing local files will be overwritten.quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.validate_checksum (
bool
, default:True
) – IfTrue
, the checksum of every file downloaded will be verified.chunk_size (
Optional
[int
], default:None
) – The size of the buffer (in bytes) to use while downloading each file. Defaults toDOWNLOAD_CHUNK_SIZE
.
- Raises:
DatasetNotFound – If the dataset can’t be found.
DatasetReadError – If the
storage
hasn’t been set.FileExistsError – If
force=False
and an existing local file clashes with a file in the Beaker dataset.ChecksumFailedError – If
validate_checksum=True
and the digest of one of the downloaded files doesn’t match the expected digest.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- stream_file(dataset, file, offset=0, length=-1, quiet=False, validate_checksum=True, chunk_size=None)[source]#
Stream download the contents of a single file from a dataset.
See also
get_file()
is similar but returns the entire contents at once instead of a generator over the contents.- Parameters:
dataset (
Union
[str
,Dataset
]) – The dataset ID, name, or object.file (
Union
[str
,FileInfo
]) – The path of the file within the dataset or the correspondingFileInfo
object.offset (
int
, default:0
) – Offset to start from, in bytes.length (
int
, default:-1
) – Number of bytes to read.quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.validate_checksum (
bool
, default:True
) – IfTrue
, the checksum of the downloaded bytes will be verified.chunk_size (
Optional
[int
], default:None
) – The size of the buffer (in bytes) to use while downloading each file. Defaults toDOWNLOAD_CHUNK_SIZE
.
- Raises:
DatasetNotFound – If the dataset can’t be found.
DatasetReadError – If the
storage
hasn’t been set.FileNotFoundError – If the file doesn’t exist in the dataset.
ChecksumFailedError – If
validate_checksum=True
and the digest of the downloaded bytes don’t match the expected digest.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Examples:
>>> total_bytes = 0 :rtype: :py:class:`~typing.Generator`\[:py:class:`bytes`, :py:obj:`None`, :py:obj:`None`] >>> with open(tmp_path / squad_dataset_file_name, "wb") as f: ... for chunk in beaker.dataset.stream_file(squad_dataset_name, squad_dataset_file_name, quiet=True): ... total_bytes += f.write(chunk)
- get_file(dataset, file, offset=0, length=-1, quiet=False, validate_checksum=True, chunk_size=None)[source]#
Download the contents of a single file from a dataset.
See also
stream_file()
is similar but returns a generator over the contents.- Parameters:
dataset (
Union
[str
,Dataset
]) – The dataset ID, name, or object.file (
Union
[str
,FileInfo
]) – The path of the file within the dataset or the correspondingFileInfo
object.offset (
int
, default:0
) – Offset to start from, in bytes.length (
int
, default:-1
) – Number of bytes to read.quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.validate_checksum (
bool
, default:True
) – IfTrue
, the checksum of the downloaded bytes will be verified.chunk_size (
Optional
[int
], default:None
) – The size of the buffer (in bytes) to use while downloading each file. Defaults toDOWNLOAD_CHUNK_SIZE
.
- Raises:
DatasetNotFound – If the dataset can’t be found.
DatasetReadError – If the
storage
hasn’t been set.FileNotFoundError – If the file doesn’t exist in the dataset.
ChecksumFailedError – If
validate_checksum=True
and the digest of the downloaded bytes don’t match the expected digest.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Examples:
- Return type:
>>> contents = beaker.dataset.get_file(squad_dataset_name, squad_dataset_file_name, quiet=True)
- file_info(dataset, file_name)[source]#
Get the
FileInfo
for a file in a dataset.- Parameters:
- Raises:
DatasetNotFound – If the dataset can’t be found.
DatasetReadError – If the
storage
hasn’t been set.FileNotFoundError – If the file doesn’t exist in the dataset.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- delete(dataset)[source]#
Delete a dataset.
- Parameters:
dataset (
Union
[str
,Dataset
]) – The dataset ID, name, or object.- Raises:
DatasetNotFound – If the dataset can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- sync(dataset, *sources, target=None, quiet=False, max_workers=None, strip_paths=False)[source]#
Sync local files or directories to an uncommitted dataset.
- Parameters:
dataset (
Union
[str
,Dataset
]) – The dataset ID, name, or object.sources (
Union
[PathLike
,str
]) – Local source files or directories to upload to the dataset.target (
Union
[PathLike
,str
,None
], default:None
) – If specified, all source files/directories will be uploaded under a directory of this name.max_workers (
Optional
[int
], default:None
) – The maximum number of thread pool workers to use to upload files concurrently.quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.strip_paths (
bool
, default:False
) –If
True
, all source files and directories will be uploaded under their name, not their path. E.g. the file “docs/source/index.rst” would be uploaded as just “index.rst”, instead of “docs/source/index.rst”.Note
This only applies to source paths that are children of the current working directory. If a source path is outside of the current working directory, it will always be uploaded under its name only.
- Raises:
DatasetNotFound – If the dataset can’t be found.
DatasetWriteError – If the dataset was already committed.
FileNotFoundError – If a source doesn’t exist.
UnexpectedEOFError – If a source is a directory and the contents of one of the directory’s files changes while creating the dataset.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- upload(dataset, source, target, quiet=False)[source]#
Upload raw bytes to an uncommitted dataset.
- Parameters:
- Raises:
DatasetNotFound – If the dataset can’t be found.
DatasetWriteError – If the dataset was already committed.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- ls(dataset, prefix=None)[source]#
List files in a dataset.
- Parameters:
- Raises:
DatasetNotFound – If the dataset can’t be found.
DatasetReadError – If the
storage
hasn’t been set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- size(dataset)[source]#
Calculate the size of a dataset, in bytes.
- Parameters:
dataset (
Union
[str
,Dataset
]) – The dataset ID, name, or object.- Raises:
DatasetNotFound – If the dataset can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- rename(dataset, name)[source]#
Rename a dataset.
- Parameters:
- Raises:
ValueError – If the new name is invalid.
DatasetNotFound – If the dataset can’t be found.
DatasetConflict – If a dataset by that name already exists.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
Image#
- class beaker.services.ImageClient(beaker)[source]#
Bases:
ServiceClient
Accessed via
Beaker.image
.- get(image)[source]#
Get info about an image on Beaker.
- Parameters:
image (
str
) – The Beaker image ID or name.- Raises:
ImageNotFound – If the image can’t be found on Beaker.
RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- create(name, image_tag, workspace=None, description=None, quiet=False, commit=True)[source]#
Upload a Docker image to Beaker.
- Parameters:
name (
str
) – The name to assign to the image on Beaker.image_tag (
str
) – The tag of the local image you’re uploading.workspace (
Union
[str
,Workspace
,None
], default:None
) – The workspace to upload the image to. If not specified,Beaker.config.default_workspace
is used.description (
Optional
[str
], default:None
) – Text description of the image.quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.commit (
bool
, default:True
) – Whether to commit the image after successful upload.
- Raises:
ValueError – If the image name is invalid.
ImageConflict – If an image with the given name already exists.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- commit(image)[source]#
Commit an image.
- Parameters:
image (
Union
[str
,Image
]) – The Beaker image ID, name, or object.- Raises:
ImageNotFound – If the image can’t be found on Beaker.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- delete(image)[source]#
Delete an image on Beaker.
- Parameters:
image (
Union
[str
,Image
]) – The Beaker image ID, name, or object.- Raises:
ImageNotFound – If the image can’t be found on Beaker.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- rename(image, name)[source]#
Rename an image on Beaker.
- Parameters:
- Raises:
ImageNotFound – If the image can’t be found on Beaker.
ValueError – If the image name is invalid.
ImageConflict – If an image with the given name already exists.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- pull(image, quiet=False)[source]#
Pull an image from Beaker.
- Parameters:
- Raises:
ImageNotFound – If the image can’t be found on Beaker.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
Job#
- class beaker.services.JobClient(beaker)[source]#
Bases:
ServiceClient
Accessed via
Beaker.job
.- get(job_id)[source]#
Get information about a job.
- Parameters:
job_id (
str
) – The ID of the Beaker job.- Raises:
JobNotFound – If the job can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- list(*, author=None, cluster=None, experiment=None, finalized=False, kind=None, node=None)[source]#
List jobs.
- Parameters:
author (
Union
[str
,Account
,None
], default:None
) – List only jobs by particular author.cluster (
Union
[str
,Cluster
,None
], default:None
) – List jobs on a particular cluster.experiment (
Union
[str
,Experiment
,None
], default:None
) – List jobs in an experiment.finalized (
bool
, default:False
) – List only finalized or non-finalized jobs.kind (
Optional
[JobKind
], default:None
) – List jobs of a certain kind.node (
Union
[str
,Node
,None
], default:None
) – List jobs on a particular node.
- Return type:
Important
Either
cluster
,author
,experiment
, ornode
must be specified. Ifnode
is specified, neithercluster
norexperiment
can be specified.- Raises:
ValueError – If the arguments are invalid, e.g. both
node
andcluster
are specified.AccountNotFound – If the specified author doesn’t exist.
ClusterNotFound – If the specified cluster doesn’t exist.
ExperimentNotFound – If the specified experiment doesn’t exist.
NodeNotFound – If the specified node doesn’t exist.
- logs(job, quiet=False, since=None)[source]#
Download the logs for a job.
Returns a generator with the streaming bytes from the download. The generator should be exhausted, otherwise the logs downloaded will be incomplete.
See also
See also
- Parameters:
quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.since (
Union
[str
,datetime
,timedelta
,None
], default:None
) – Only show logs since a particular time. Could be adatetime
object (naive datetimes will be treated as UTC), a timestamp string in the form of RFC 3339 (e.g. “2013-01-02T13:23:37Z”), or atimedelta
(e.g. timedelta(seconds=60), which will show you the logs beginning 60 seconds ago).
- Raises:
JobNotFound – If the job can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- metrics(job)[source]#
Get the metrics from a job.
See also
- Parameters:
- Raises:
JobNotFound – If the job can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- results(job)[source]#
Get the results from a job.
See also
- Parameters:
- Raises:
JobNotFound – If the job can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- finalize(job)[source]#
Finalize a job.
- Parameters:
- Raises:
JobNotFound – If the job can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- preempt(job)[source]#
Preempt a job.
- Parameters:
- Raises:
JobNotFound – If the job can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- stop(job)[source]#
Stop a job.
- Parameters:
- Raises:
JobNotFound – If the job can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- wait_for(*jobs, timeout=None, poll_interval=1.0, quiet=False, strict=False)[source]#
Wait for jobs to finalize, returning the completed jobs as a list in the same order they were given as input.
Caution
This method is experimental and may change or be removed in future releases.
See also
See also
See also
- Parameters:
timeout (
Optional
[float
], default:None
) – Maximum amount of time to wait for (in seconds).poll_interval (
float
, default:1.0
) – Time to wait between polling each job’s status (in seconds).quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.strict (
bool
, default:False
) – IfTrue
, the exit code of each job will be checked, and aJobFailedError
will be raised for non-zero exit codes.
- Raises:
JobNotFound – If any job can’t be found.
JobTimeoutError – If the
timeout
expires.DuplicateJobError – If the same job is given as an argument more than once.
JobFailedError – If
strict=True
and any job finishes with a non-zero exit code.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- as_completed(*jobs, timeout=None, poll_interval=1.0, quiet=False, strict=False)[source]#
Wait for jobs to finalize, returning an iterator that yields jobs as they complete.
Caution
This method is experimental and may change or be removed in future releases.
See also
See also
See also
- Parameters:
timeout (
Optional
[float
], default:None
) – Maximum amount of time to wait for (in seconds).poll_interval (
float
, default:1.0
) – Time to wait between polling each job’s status (in seconds).quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.strict (
bool
, default:False
) – IfTrue
, the exit code of each job will be checked, and aJobFailedError
will be raised for non-zero exit codes.
- Raises:
JobNotFound – If any job can’t be found.
JobTimeoutError – If the
timeout
expires.DuplicateJobError – If the same job is given as an argument more than once.
JobFailedError – If
strict=True
and any job finishes with a non-zero exit code.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- follow(job, timeout=None, strict=False, include_timestamps=True, since=None)[source]#
Follow a job live, creating a generator that produces log lines (as bytes) from the job as they become available. The return value of the generator is the finalized
Job
object.See also
See also
See also
See also
- Parameters:
timeout (
Optional
[float
], default:None
) – Maximum amount of time to follow job for (in seconds).strict (
bool
, default:False
) – IfTrue
, the exit code of each job will be checked, and aJobFailedError
will be raised for non-zero exit codes.include_timestamps (
bool
, default:True
) – IfTrue
(the default) timestamps from the Beaker logs will be included in the output.since (
Union
[str
,datetime
,timedelta
,None
], default:None
) – Only show logs since a particular time. Could be adatetime
object (naive datetimes will be treated as UTC), a timestamp string in the form of RFC 3339 (e.g. “2013-01-02T13:23:37Z”), or atimedelta
(e.g. timedelta(seconds=60), which will show you the logs beginning 60 seconds ago).
- Raises:
JobNotFound – If any job can’t be found.
JobTimeoutError – If the
timeout
expires.JobFailedError – If
strict=True
and any job finishes with a non-zero exit code.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Examples:
>>> job = beaker.experiment.latest_job(hello_world_experiment_name) >>> for line in beaker.job.follow(job): ... # Every log line from Beaker starts with an RFC 3339 UTC timestamp ... # (e.g. '2021-12-07T19:30:24.637600011Z'). If we don't want to print ... # the timestamps we can split them off like this: ... line = line[line.find(b"Z ")+2:] ... print(line.decode(errors="ignore"), end="") Hello from Docker! :rtype: :py:class:`~typing.Generator`\[:py:class:`bytes`, :py:obj:`None`, :py:class:`~beaker.data_model.job.Job`] This message shows that your installation appears to be working correctly. ...
Experiment#
- class beaker.services.ExperimentClient(beaker)[source]#
Bases:
ServiceClient
Accessed via
Beaker.experiment
.- get(experiment)[source]#
Get info about an experiment.
- Parameters:
experiment (
str
) – The experiment ID or name.- Raises:
ExperimentNotFound – If the experiment can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- list(*, author=None, cluster=None, finalized=False, node=None)[source]#
List experiments.
- Parameters:
author (
Union
[str
,Account
,None
], default:None
) – List only experiments by particular author.cluster (
Union
[str
,Cluster
,None
], default:None
) – List experiments on a particular cluster.finalized (
bool
, default:False
) – List only finalized or non-finalized experiments.node (
Union
[str
,Node
,None
], default:None
) – List experiments on a particular node.
- Return type:
Important
Either
cluster
,author
,experiment
, ornode
must be specified. Ifnode
is specified, neithercluster
norexperiment
can be specified.- Raises:
ValueError – If the arguments are invalid, e.g. both
node
andcluster
are specified.AccountNotFound – If the specified author doesn’t exist.
ClusterNotFound – If the specified cluster doesn’t exist.
NodeNotFound – If the specified node doesn’t exist.
- create(*args, **kwargs)[source]#
Create a new Beaker experiment with the given
spec
.- Parameters:
spec (
ExperimentSpec
|Path
|str
) – The spec for the Beaker experiment. This can either be anExperimentSpec
instance or the path to a YAML spec file.name (
str
, optional) – An optional name to assign the experiment. Must be unique.workspace (
Workspace
|str
, optional) – An optional workspace to create the experiment under. If not specified,Beaker.config.default_workspace
is used.
- Raises:
ValueError – If the name is invalid.
ExperimentConflict – If an experiment with the given name already exists.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- spec(experiment)[source]#
Get the
spec
of an experiment.- Parameters:
experiment (
Union
[str
,Experiment
]) – The experiment ID, name, or object.- Raises:
ExperimentNotFound – If the experiment can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- stop(experiment)[source]#
Stop an experiment.
- Parameters:
experiment (
Union
[str
,Experiment
]) – The experiment ID, name, or object.- Raises:
ExperimentNotFound – If the experiment can’t be found.
ExperimentConflict – If the experiment was already stopped.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- resume(experiment)[source]#
Resume a preempted experiment.
- Parameters:
experiment (
Union
[str
,Experiment
]) – The experiment ID, name, or object.- Raises:
ExperimentNotFound – If the experiment can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- delete(experiment, delete_results_datasets=True)[source]#
Delete an experiment.
- Parameters:
experiment (
Union
[str
,Experiment
]) – The experiment ID, name, or object.delete_results_datasets (
bool
, default:True
) – Also delete the experiment’s results datasets.
- Raises:
ExperimentNotFound – If the experiment can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- rename(experiment, name)[source]#
Rename an experiment.
- Parameters:
experiment (
Union
[str
,Experiment
]) – The experiment ID, name, or object.name (
str
) – The new name for the experiment.
- Raises:
ValueError – If the new name is invalid.
ExperimentNotFound – If the experiment can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- tasks(experiment)[source]#
List the tasks in an experiment.
- Parameters:
experiment (
Union
[str
,Experiment
]) – The experiment ID, name, or object.- Raises:
ExperimentNotFound – If the experiment can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Examples:
- Return type:
>>> task = beaker.experiment.tasks(hello_world_experiment_name)["main"]
- logs(experiment, task=None, quiet=False, since=None)[source]#
Download the logs for an experiment.
Returns a generator with the streaming bytes from the download. The generator should be exhausted, otherwise the logs downloaded will be incomplete.
Important
When there are multiple jobs for the given experiment / task, the logs for the latest job will be returned.
See also
- Parameters:
experiment (
Union
[str
,Experiment
]) – The experiment ID, name, or object.task (
Union
[str
,Task
,None
], default:None
) – The task ID, name, or object of a specific task from the Beaker experiment to fetch logs for. Required if there are multiple tasks in the experiment.quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.since (
Union
[str
,datetime
,timedelta
,None
], default:None
) – Only show logs since a particular time. Could be adatetime
object (naive datetimes will be treated as UTC), a timestamp string in the form of RFC 3339 (e.g. “2013-01-02T13:23:37Z”), or atimedelta
(e.g. timedelta(seconds=60), which will show you the logs beginning 60 seconds ago).
- Raises:
ValueError – The experiment has no tasks or jobs, or the experiment has multiple tasks but
task
is not specified.TaskNotFound – If the given task doesn’t exist.
ExperimentNotFound – If the experiment can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- metrics(experiment, task=None)[source]#
Get the metrics from a task in an experiment.
Important
When there are multiple jobs for the given experiment / task, the metrics for the latest finalized job will be returned.
See also
- Parameters:
- Raises:
ValueError – The experiment has no tasks, or the experiment has multiple tasks but
task
is not specified.TaskNotFound – If the given task doesn’t exist.
ExperimentNotFound – If the experiment can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- results(experiment, task=None)[source]#
Get the result dataset from a task in an experiment.
Important
When there are multiple jobs for the given experiment / task, the results for dataset the latest finalized job will be returned.
See also
- Parameters:
- Raises:
ValueError – The experiment has no tasks, or the experiment has multiple tasks but
task
is not specified.TaskNotFound – If the given task doesn’t exist.
ExperimentNotFound – If the experiment can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- wait_for(*experiments, timeout=None, poll_interval=1.0, quiet=False, strict=False)[source]#
Wait for experiments to finalize, returning the completed experiments as a list in the same order they were given as input.
Caution
This method is experimental and may change or be removed in future releases.
See also
See also
See also
- Parameters:
experiments (
Union
[str
,Experiment
]) – Experiment ID, name, or object.timeout (
Optional
[float
], default:None
) – Maximum amount of time to wait for (in seconds).poll_interval (
float
, default:1.0
) – Time to wait between polling the experiment (in seconds).quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.strict (
bool
, default:False
) – IfTrue
, the exit code of each job will be checked, and aJobFailedError
will be raised for non-zero exit codes.
- Raises:
ExperimentNotFound – If any experiment can’t be found.
JobTimeoutError – If the
timeout
expires.DuplicateExperimentError – If the same experiment is given as an argument more than once.
JobFailedError – If
strict=True
and any job finishes with a non-zero exit code.TaskStoppedError – If
strict=True
and a task is stopped before a corresponding job is initialized.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- as_completed(*experiments, timeout=None, poll_interval=1.0, quiet=False, strict=False)[source]#
Wait for experiments to finalize, returning an iterator that yields experiments as they complete.
Caution
This method is experimental and may change or be removed in future releases.
See also
See also
See also
- Parameters:
experiments (
Union
[str
,Experiment
]) – Experiment ID, name, or object.timeout (
Optional
[float
], default:None
) – Maximum amount of time to wait for (in seconds).poll_interval (
float
, default:1.0
) – Time to wait between polling the experiment (in seconds).quiet (
bool
, default:False
) – IfTrue
, progress won’t be displayed.strict (
bool
, default:False
) – IfTrue
, the exit code of each job will be checked, and aJobFailedError
will be raised for non-zero exit codes.
- Raises:
ExperimentNotFound – If any experiment can’t be found.
JobTimeoutError – If the
timeout
expires.DuplicateExperimentError – If the same experiment is given as an argument more than once.
JobFailedError – If
strict=True
and any job finishes with a non-zero exit code.TaskStoppedError – If
strict=True
and a task is stopped before a corresponding job is initialized.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- follow(experiment, task=None, timeout=None, strict=False, include_timestamps=True, since=None)[source]#
Follow an experiment live, creating a generator that produces log lines (as bytes) from the task’s job as they become available. The return value of the generator is the final
Experiment
object.See also
See also
See also
See also
- Parameters:
experiment (
Union
[str
,Experiment
]) – Experiment ID, name, or object.task (
Union
[str
,Task
,None
], default:None
) – The task ID, name, or object of a specific task from the Beaker experiment to follow. Required if there are multiple tasks in the experiment.timeout (
Optional
[float
], default:None
) – Maximum amount of time to wait for (in seconds).strict (
bool
, default:False
) – IfTrue
, the exit code of the job will be checked, and aJobFailedError
will be raised for non-zero exit codes.include_timestamps (
bool
, default:True
) – IfTrue
(the default) timestamps from the Beaker logs will be included in the output.since (
Union
[str
,datetime
,timedelta
,None
], default:None
) – Only show logs since a particular time. Could be adatetime
object (naive datetimes will be treated as UTC), a timestamp string in the form of RFC 3339 (e.g. “2013-01-02T13:23:37Z”), or atimedelta
(e.g. timedelta(seconds=60), which will show you the logs beginning 60 seconds ago).
- Raises:
ExperimentNotFound – If any experiment can’t be found.
ValueError – The experiment has no tasks or jobs, or the experiment has multiple tasks but
task
is not specified.TaskNotFound – If the given task doesn’t exist.
JobTimeoutError – If the
timeout
expires.JobFailedError – If
strict=True
and the task’s job finishes with a non-zero exit code.TaskStoppedError – If
strict=True
and a task is stopped before a corresponding job is initialized.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Examples:
>>> for line in beaker.experiment.follow(hello_world_experiment_name): ... # Every log line from Beaker starts with an RFC 3339 UTC timestamp ... # (e.g. '2021-12-07T19:30:24.637600011Z'). If we don't want to print ... # the timestamps we can split them off like this: ... line = line[line.find(b"Z ")+2:] ... print(line.decode(errors="ignore"), end="") Hello from Docker! :rtype: :py:class:`~typing.Generator`\[:py:class:`bytes`, :py:obj:`None`, :py:class:`~beaker.data_model.experiment.Experiment`] This message shows that your installation appears to be working correctly. ...
- url(experiment, task=None)[source]#
Get the URL for an experiment.
- Parameters:
- Raises:
TaskNotFound – If the given task doesn’t exist.
ExperimentNotFound – If the experiment can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- latest_job(experiment, task=None, ensure_finalized=False)[source]#
Get the latest job that ran for a task in an experiment.
- Parameters:
- Raises:
ValueError – The experiment has no tasks, or the experiment has multiple tasks but
task
is not specified.TaskNotFound – If the given task doesn’t exist.
ExperimentNotFound – If the experiment can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
Secret#
- class beaker.services.SecretClient(beaker)[source]#
Bases:
ServiceClient
Accessed via
Beaker.secret
.- get(secret, workspace=None)[source]#
Get metadata about a secret.
- Parameters:
- Raises:
SecretNotFound – If the secret doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- read(secret, workspace=None)[source]#
Read the value of a secret.
- Parameters:
- Raises:
SecretNotFound – If the secret doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- write(name, value, workspace=None)[source]#
Write a new secret or update an existing one.
- Parameters:
- Raises:
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- delete(secret, workspace=None)[source]#
Permanently delete a secret.
- Parameters:
- Raises:
SecretNotFound – If the secret doesn’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
Group#
- class beaker.services.GroupClient(beaker)[source]#
Bases:
ServiceClient
Accessed via
Beaker.group
.- get(group)[source]#
Get info about a group.
- Parameters:
group (
str
) – The group ID or name.- Raises:
GroupNotFound – If the group can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- create(name, *experiments, description=None, workspace=None)[source]#
- Parameters:
name (
str
) – The name to assign the group.experiments (
Union
[str
,Experiment
]) – Experiments to add to the group.description (
Optional
[str
], default:None
) – Group description.workspace (
Union
[str
,Workspace
,None
], default:None
) – The workspace to create the group under. If not specified,Beaker.config.default_workspace
is used.
- Raises:
ValueError – If the name is invalid.
GroupConflict – If a group with the given name already exists.
ExperimentNotFound – If any of the given experiments don’t exist.
WorkspaceNotSet – If neither
workspace
norBeaker.config.default_workspace
are set.BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- delete(group)[source]#
Delete a group.
- Parameters:
- Raises:
GroupNotFound – If the group can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- rename(group, name)[source]#
Rename a group.
- Parameters:
- Raises:
ValueError – If the new name is invalid.
GroupNotFound – If the group can’t be found.
GroupConflict – If a group by that name already exists.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- add_experiments(group, *experiments)[source]#
Add experiments to a group.
- Parameters:
- Raises:
GroupNotFound – If the group can’t be found.
ExperimentNotFound – If any of the given experiments don’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- remove_experiments(group, *experiments)[source]#
Remove experiments from a group.
- Parameters:
- Raises:
GroupNotFound – If the group can’t be found.
ExperimentNotFound – If any of the given experiments don’t exist.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- list_experiments(group)[source]#
List experiments in a group.
- Parameters:
- Raises:
GroupNotFound – If the group can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type:
- export_experiments(group, quiet=False)[source]#
Export all experiments and metrics in a group as a CSV.
Returns a generator that should be exhausted to get the complete file.
- Parameters:
- Raises:
GroupNotFound – If the group can’t be found.
BeakerError – Any other
BeakerError
type that can occur.RequestException – Any other exception that can occur when contacting the Beaker server.
- Return type: