Skip to main content

A Python Beaker client

Project description

Beaker-py

A lightweight pure-Python client for Beaker.

Quick Links

Installing

Installing with pip

beaker-py is available on PyPI. Just run

pip install beaker-py

Installing from source

To install beaker-py from source, first clone the repository:

git clone https://github.com/allenai/beaker.git

Then create or activate a Python virtual environment, and run:

cd beaker/bindings/python
make dev-install

Quick start

If you've already configured the Beaker command-line client, beaker-py will find and use the existing configuration file (usually located at $HOME/.beaker/config.yml) or BEAKER_TOKEN environment variable.

Then you can instantiate the Beaker client with the .from_env() class method:

from beaker import Beaker

with Beaker.from_env() as beaker:
    ...

With the Python client, you can:

  • Query Clusters with beaker.cluster.* methods. For example:

    beaker.cluster.get("ai2/jupiter-cirrascale-2")
    
  • Manage Datasets with beaker.dataset.* methods. For example:

    beaker.dataset.create(dataset_name, source_dir)
    
  • Manage Experiments with beaker.experiment.* and beaker.workload.* methods. For example:

    beaker.experiment.create(spec=spec, name=name)
    
  • Manage Groups with beaker.group.* methods. For example:

    beaker.group.create(name)
    
  • Manage Images with beaker.image.* methods. For example:

    beaker.image.update(image, name=name)
    
  • Manage Secrets with beaker.secret.* methods. For example:

    beaker.secret.write(name, value)
    
  • Manage Workspaces with beaker.workspace.* methods. For example:

    beaker.workspace.create("ai2/new_workspace")
    
  • Track Jobs with beaker.job.* methods. For example:

    beaker.job.logs(job, follow=True)
    
  • Create and process Queues with beaker.queue.* methods. For example:

    beaker.queue.create("my-work-queue", batch_size=4)
    

If you're coming from v1 of beaker-py, consider reading the migration guide.

Example workflow

Launch and follow an experiment like beaker-gantry does:

import time
from beaker import Beaker, BeakerExperimentSpec, BeakerJobPriority


with Beaker.from_env() as beaker:
    # Build experiment spec...
    spec = BeakerExperimentSpec.new(
        description="beaker-py test run",
        beaker_image="petew/hello-world",
        priority=BeakerJobPriority.low,
        preemptible=True,
    )

    # Create experiment workload...
    workload = beaker.experiment.create(spec=spec)

    # Wait for job to be created...
    while (job := beaker.workload.get_latest_job(workload)) is None:
        print("waiting for job to start...")
        time.sleep(1.0)

    # Follow logs...
    print("Job logs:")
    for job_log in beaker.job.logs(job, follow=True):
        print(job_log.message.decode())

See the integration tests for more examples.

Development

After installing from source, you can run checks and tests locally with:

make checks

Releases

At the moment releases need to be published manually by following these steps:

  1. Ensure you've authenticated with PyPI through a ~/.pypirc file and have write permissions to the beaker-py project. The local ~/.pypirc file looks like:
[distutils]
index-servers = pypi

[pypi]
username = __token__
password = #beaker-py pypi API token from 1pass#
  1. Ensure the target release version defined in src/beaker/version.py is correct, or change the version on the fly by adding the Make argument BEAKER_PY_VERSION=X.X.X to the command in the next step.
  2. Ensure the CHANGELOG.md has a section at the top for the new release (## vX.X.X - %Y-%m-%d).
  3. Run make publish for a stable release or make publish-nightly for a nightly pre-release.

Project details


Release history Release notifications | RSS feed

This version

2.5.8

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

beaker_py-2.5.8.tar.gz (104.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

beaker_py-2.5.8-py3-none-any.whl (116.0 kB view details)

Uploaded Python 3

File details

Details for the file beaker_py-2.5.8.tar.gz.

File metadata

  • Download URL: beaker_py-2.5.8.tar.gz
  • Upload date:
  • Size: 104.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for beaker_py-2.5.8.tar.gz
Algorithm Hash digest
SHA256 3451bf45a89d78d38161ed0af20c94a205857fd20a307712ad1d07d4eb706ea7
MD5 a88dfbd8514e36067b4a7c6c013b8660
BLAKE2b-256 4a191242e86362727f8a7d662b7140c9de0c57f6e47c19d49ef8ef4a2132c9a5

See more details on using hashes here.

File details

Details for the file beaker_py-2.5.8-py3-none-any.whl.

File metadata

  • Download URL: beaker_py-2.5.8-py3-none-any.whl
  • Upload date:
  • Size: 116.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for beaker_py-2.5.8-py3-none-any.whl
Algorithm Hash digest
SHA256 87b4850c39e802156c093d57ee789af0ee71e0eb0e11d5b6a8f5c625c36773b7
MD5 207f55cedd3cb82d185553d2b8208ee0
BLAKE2b-256 919cdc9ea5c369467ed97a95fd4c0eddcff2266f12322477cfaf3bbfebbc2591

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page