Skip to main content

Client library for Bedrock platform

Project description

Bedrock helps data scientists own the end-to-end deployment of machine learning workflows. bdrk is the official client library for interacting with APIs on Bedrock platform.


In order to use bdrk, you need to register an account with Basis AI. Please email to get started. Once an account is created, you will be issued a personal API token that you can use to authenticate with Bedrock.

Installing Bedrock client

You can install Bedrock client library from PyPi with the following command. We recommend running it in a virtual environment to prevent potential dependency conflicts.

pip install bdrk

Note that the client library is officially supported for python 3.7 and above.

Installing optional dependencies

The following optional dependencies can be installed to enable additional featues.

Command line support:

pip install bdrk[cli]

Setting up your environment

Once installed, you need to add a well formed bedrock.hcl configuration file in your project's root directory. The configuration file specifies which script to run for training and deployment as well as their respective base Docker images. You can find an example directory layout here.

When using the module locally, you may need to define the following environment variables for bedrock_client and lab runs to make API calls to Bedrock. These variables will be automatically set on your workload container when running in cluster.

BEDROCK_API_TOKEN=<your personal API token>

bedrock_client library

The bedrock_client library provides utility functions for your training runs.

Logging training metrics

You can easily export training metrics to Bedrock by adding logging code to The example below demonstrates logging charts and metrics for visualisation on Bedrock platform.

import logging

from bedrock_client.bedrock.api import BedrockApi

logger = logging.getLogger(__name__)
bedrock = BedrockApi(logger)
bedrock.log_metric("Accuracy", 0.97)
bedrock.log_chart_data([0, 1, 1], [0.1, 0.7, 0.9])

bdrk library

The bdrk library provides APIs for interacting with the Bedrock platform.

from bdrk.v1 import ApiClient, Configuration, PipelineApi
from bdrk.v1.models import (

configuration = Configuration()
configuration.api_key["X-Bedrock-Access-Token"] = "MY-TOKEN" = ""

api_client = ApiClient(configuration)
pipeline_api = PipelineApi(api_client)

pipeline = pipeline_api.get_training_pipeline_by_id(pipeline_id="MY-PIPELINE")
run_schema = TrainingPipelineRunSchema(
    resources=PipelineResourcesSchema(cpu="500m", memory="200M"),
    script_parameters={"MYPARAM": "1.23"},
run = pipeline_api.run_training_pipeline(
    pipeline_id=pipeline.public_id, training_pipeline_run_schema=run_schema

Lab run

The labrun command can be used to launch test runs of local training code on the Bedrock platform.

  # Set environment variables with credentials for this session
  $ unset HISTFILE # Don't save history for this session
  $ export BEDROCK_API_TOKEN=<your personal API token>

  $ bdrk labrun --help

  $ bdrk labrun --verbose --domain $BEDROCK_API_DOMAIN submit \
        $HOME/basis/span-example-colourtest \
        bedrock.hcl \
        canary-dev \
        --cpu 0.6 \
        --memory 1.1G \
        -p ALPHA=0.9 \
        -p L5_RATIO=0.1 \
        -s DUMMY_SECRET_A=foo \
        -s DUMMY_SECRET_B=bar

  $ bdrk labrun logs <run_id> <run_token>

  $ bdrk labrun artefact <run_id> <run_token>

bdrk changelog

v0.1.5 (2019-xx-xx)


  • Added kwargs to models to allow backward compatibility.
  • Changed response schema for ModelApi.get_artefact_details from ModelArtefactDetails to ModelArtefactSchema.
  • Removed unused schemas.

v0.1.4 (2019-10-09)


  • Added get_training_pipeline_runs function to retrieve all runs from a pipeline

v0.1.3 (2019-10-01)


  • Added bdrk.v1.ModelApi with function get_artefact_details.
    from bdrk.v1 import ModelApi
    model_api = ModelApi(api_client)
    artefact = model_api.get_artefact_details(public_id=pipeline.model_id, artefact_id=run.artefact_id)
  • bdrk.v1.models.UserSchema.email_address made required.


  • Added utility functions for downloading and unzipping artefacts

    from bdrk.v1 import ApiClient, Configuration
    from bdrk.v1_util import download_and_unzip_artefact
    configuration = Configuration()
    configuration.api_key["X-Bedrock-Access-Token"] = "YOUR-TOKEN-HERE" = ""
    api_client = ApiClient(configuration)
    # There are other utility methods as well
    # `get_artefact_stream`, `download_stream`, `unzip_file_to_dir`

Lab run

The labrun feature allows you to run and interact with one-off training runs.

  • Changed command from bedrock labrun to bdrk labrun submit.
  • Added secrets using -s DUMMY_SECRET_A=foo flag.
  • Added downloading of logs and model artefacts.
    • bdrk labrun logs <run_id> <run_token>
    • bdrk labrun artefact <run_id> <run_token>

Project details

Download files

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

Files for bdrk, version 0.1.5
Filename, size File type Python version Upload date Hashes
Filename, size bdrk-0.1.5-py3-none-any.whl (154.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size bdrk-0.1.5.tar.gz (46.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page