Client

class Beaker(config: Config, check_for_upgrades: bool = True, user_agent: str = 'beaker-py v2.4.3')[source]

A client for interacting with Beaker. This should be used as a context manager to ensure connections are properly closed on exit.

Tip

Use from_env() to create a client instance.

Parameters:
  • config – The Beaker Config.

  • check_for_upgrades – Automatically check that beaker-py is up-to-date. You’ll see a warning if it isn’t.

  • user_agent – Override the “User-Agent” header used in requests to the Beaker server.

VERSION_CHECK_INTERVAL: ClassVar[int] = 43200
MAX_RETRIES: ClassVar[int] = 5
BACKOFF_FACTOR: ClassVar[int] = 1
BACKOFF_MAX: ClassVar[int] = 120
TIMEOUT: ClassVar[float] = 5.0
POOL_MAXSIZE: ClassVar[int] = 60
classmethod from_env(check_for_upgrades: bool = True, user_agent: str = 'beaker-py v2.4.3', **overrides) Beaker[source]

Initialize client from a config file and/or environment variables.

Examples:

>>> with Beaker.from_env(default_workspace="ai2/my-workspace") as beaker:
...     print(beaker.user_name)
Parameters:
  • check_for_upgrades – Automatically check that beaker-py is up-to-date. You’ll see a warning if it isn’t.

  • user_agent – Override the “User-Agent” header used in requests to the Beaker server.

  • overrides – Fields in the Config to override.

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.

property user_name: str
property org_name: str
property organization: OrganizationClient

Manage organizations.

property user: UserClient

Manage users.

property workspace: WorkspaceClient

Manage workspaces.

property cluster: ClusterClient

Manage clusters.

property node: NodeClient

Manage nodes.

property dataset: DatasetClient

Manage datasets.

property image: ImageClient

Manage images.

property job: JobClient

Manage jobs.

property experiment: ExperimentClient

Manage experiments.

property workload: WorkloadClient

Manage workloads.

property secret: SecretClient

Manage secrets.

property group: GroupClient

Manage groups.

property queue: QueueClient

Manage queues.

http_session() Generator[Session, None, None][source]
close()[source]

Close down RPC channels and HTTP sessions. This will be called automatically when using the client as a context manager.

class Config(user_token: str, agent_address: str = 'https://beaker.org', rpc_address: str = 'beaker.org:443', default_org: str | None = 'ai2', default_workspace: str | None = None, default_image: str | None = None)[source]
user_token: str

Beaker user token that can be obtained from beaker.org.

agent_address: str = 'https://beaker.org'

The address of the Beaker server.

rpc_address: str = 'beaker.org:443'

The address of the Beaker gRPC server.

default_org: str | None = 'ai2'

Default Beaker organization to use.

default_workspace: str | None = None

Default Beaker workspace to use.

default_image: str | None = None

The default image used for interactive sessions.

ADDRESS_KEY: ClassVar[str] = 'BEAKER_ADDR'
CONFIG_PATH_KEY: ClassVar[str] = 'BEAKER_CONFIG'
TOKEN_KEY: ClassVar[str] = 'BEAKER_TOKEN'
IGNORE_FIELDS: ClassVar[Set[str]] = {'updater_message', 'updater_timestamp'}
classmethod from_env(**overrides) Config[source]

Initialize a config from environment variables or a local config file if one can be found.

Note

Environment variables take precedence over values in the config file.

classmethod from_path(path: Path) Config[source]

Initialize a config from a local config file.

save(path: Path | None = None)[source]

Save the config to the given path.

classmethod find_config() Path | None[source]