bailo.core package

The Bailo core package contains suppport with one to one endpoints with Bailo. It is recommended to use the helper package for most use

class bailo.core.agent.Agent(verify: str | bool = True)[source]

Bases: object

Base API Agent for talking with Bailo.

Wraps each request in an exception handler that maps API errors to Python Bailo errors, among status codes less than 400.

__init__(verify: str | bool = True)[source]

Initiate a standard agent.

Parameters:

verify – Path to certificate authority file, or bool for SSL verification.

delete(*args, **kwargs)[source]
get(*args, **kwargs)[source]
patch(*args, **kwargs)[source]
post(*args, **kwargs)[source]
push(*args, **kwargs)[source]
put(*args, **kwargs)[source]
class bailo.core.agent.PkiAgent(cert: str, key: str, auth: str)[source]

Bases: Agent

__init__(cert: str, key: str, auth: str)[source]

Initiate an agent for PKI authentication.

Parameters:
  • cert – Path to cert file

  • key – Path to key file

  • auth – Path to certificate authority file

delete(*args, **kwargs)[source]
get(*args, **kwargs)[source]
patch(*args, **kwargs)[source]
post(*args, **kwargs)[source]
put(*args, **kwargs)[source]
class bailo.core.agent.TokenAgent(access_key: str | None = None, secret_key: str | None = None)[source]

Bases: Agent

__init__(access_key: str | None = None, secret_key: str | None = None)[source]

Initiate an agent for API token authentication.

Parameters:
  • access_key – Access key

  • secret_key – Secret key

delete(*args, **kwargs)[source]
get(*args, **kwargs)[source]
patch(*args, **kwargs)[source]
post(*args, **kwargs)[source]
put(*args, **kwargs)[source]
class bailo.core.client.Client(url: str, agent: ~bailo.core.agent.Agent = <bailo.core.agent.Agent object>)[source]

Bases: object

Create a Client object that can be used to talk to the website.

Parameters:
  • url – Url of bailo website

  • agent – An agent object to handle requests

delete_access_request(model_id: str, access_request_id: str)[source]

Delete a specific access request associated with a model.

Parameters:
  • model_id – Unique model ID

  • access_request_id – Unique access request ID

Returns:

JSON response object

delete_file(model_id: str, file_id: str)[source]

Delete a specific file associated with a model.

Parameters:
  • model_id – Unique model ID

  • file_id – Unique file ID

Returns:

JSON response object

delete_release(model_id: str, release_version: str)[source]

Delete a specific model release.

Parameters:
  • model_id – Unique model ID

  • release_version – Release version

Returns:

JSON response object

get_access_request(model_id: str, access_request_id: str)[source]

Retrieve a specific access request given its unique ID.

Parameters:
  • model_id – Unique model ID

  • access_request_id – Unique access request ID

Returns:

JSON response object

get_access_requests(model_id: str)[source]

Retrieve all access requests given a specific model.

Parameters:
  • model_id – Unique model ID

  • access_request_id – Unique access request ID

Returns:

JSON response object

get_all_images(model_id: str)[source]

Get all images.

Parameters:

model_id – A unique model ID

Returns:

JSON response object

get_all_releases(model_id: str)[source]

Get all releases for a model.

Parameters:

model_id – Unique model ID

Returns:

JSON response object

get_all_schemas(kind: SchemaKind | None = None)[source]

Get all schemas.

Parameters:

kind – Enum to define schema kind (e.g. Model or AccessRequest), defaults to None

Returns:

JSON response object

get_all_teams()[source]

Get all teams.

Returns:

JSON response object

get_download_by_filename(model_id: str, semver: str, filename: str)[source]

Download a specific file.

Parameters:
  • model_id – Unique model ID

  • semver – Semver of the release

  • filename – The filename trying to download from

Returns:

The filename

get_download_file(model_id: str, file_id: str)[source]

Download a specific file by it’s id.

Parameters:
  • model_id – Unique model ID

  • file_id – Unique file ID

Returns:

The unique file ID

get_files(model_id: str)[source]

Get files for a model.

Parameters:

model_id – Unique model ID

Returns:

JSON response object

get_model(model_id: str)[source]

Retrieve a specific model using its unique ID.

Parameters:

model_id – Unique model ID

Returns:

JSON response object

get_model_card(model_id: str, version: str)[source]

Retrieve a specific model card, using the unique model ID and version.

Parameters:
  • model_id – Unique model ID

  • version – Model card version

Returns:

JSON response object

get_model_roles(model_id: str)[source]

Get roles for a model.

Parameters:

model_id – Unique model ID

Returns:

JSON response object

get_model_user_roles(model_id: str)[source]

Get current users roles for a model.

Parameters:

model_id – Unique model ID

Returns:

JSON response object

get_models(kind: EntryKind = EntryKind.MODEL, task: str | None = None, libraries: list[str] | None = None, filters: list[str] | None = None, search: str = '')[source]

Find and returns a list of models based on provided search terms.

Parameters:
  • kind – Either a Model or a Datacard

  • task – Model task (e.g. image classification), defaults to None

  • libraries – Model library (e.g. TensorFlow), defaults to None

  • filters – Custom filters, defaults to None

  • search – String to be located in model cards, defaults to “”

Returns:

JSON response object

get_release(model_id: str, release_version: str)[source]

Get a specific model release.

Parameters:
  • model_id – Unique model ID

  • release_version – Release version

Returns:

JSON response object

get_reviews(active: bool, model_id: str | None = None, version: str | None = None)[source]

Get all reviews within given parameters.

Parameters:
  • active – Boolean representing status of review

  • model_id – Unique model ID, defaults to None

  • version – Model version, defaults to None

Returns:

JSON response object.

get_schema(schema_id: str)[source]

Retrieve a specific schema using its unique ID.

Parameters:

schema_id – Unique schema ID

Returns:

JSON response object.

get_team(team_id: str)[source]

Retrieve a specific team given its unique ID.

Parameters:

team_id – Unique team ID

Returns:

JSON response object

get_user_teams()[source]

Get user teams.

Returns:

JSON response object

model_card_from_schema(model_id: str, schema_id: str)[source]

Create a model card using a given schema ID.

Parameters:
  • model_id – Unique model ID

  • schema_id – Unique model card schema ID

Returns:

JSON response object

patch_access_request(model_id: str, access_request_id: str, metadata: Any, schema_id: str | None = None)[source]

Update an access request given its unique ID.

Parameters:
  • model_id – Unique model ID

  • access_request_id – Unique access request ID

Metadata:

Metadata object, defined by access request schemas

Returns:

JSON response object

patch_model(model_id: str, name: str | None = None, kind: str | None = None, description: str | None = None, visibility: str | None = None)[source]

Update a specific model using its unique ID.

Parameters:
  • model_id – Unique model ID

  • name – Name of the model, defaults to None

  • kind – Either a Model or a Datacard

  • description – Description of the model, defaults to None

  • visibility – Enum to define model visibility (e.g. public or private), defaults to None

Returns:

JSON response object

patch_team(team_id: str, name: str | None = None, description: str | None = None)[source]

Update a team given its unique ID.

Parameters:
  • team_id – Unique team ID

  • name – Name of team, defaults to None

  • description – Description of team, defaults to None

Returns:

JSON response object

post_access_request(model_id: str, metadata: Any, schema_id: str)[source]

Create an access request given a model ID.

Parameters:
  • model_id – Unique model ID

  • metadata – Metadata object, defined by access request schema

  • schema_id – Unique schema ID

Returns:

JSON response object

post_model(name: str, kind: EntryKind, description: str, team_id: str, visibility: ModelVisibility | None = None)[source]

Create a model.

Parameters:
  • name – Name of the model

  • kind – Either a Model or a Datacard

  • description – Description of the model

  • visibility – Enum to define model visibility (e.g public or private)

Returns:

JSON response object

post_release(model_id: str, release_version: str, notes: str, file_ids: list[str], images: list[str], model_card_version: int | None = None, minor: bool | None = False, draft: bool | None = False)[source]

Create a new model release.

Parameters:
  • model_id – Unique model ID

  • model_card_version – Model card version

  • release_version – Release version

  • notes – Notes on release

  • file_ids – Files for release

  • images – Images for release

  • minor – Signifies a minor release, defaults to False

  • draft – Signifies a draft release, defaults to False

Returns:

JSON response object

post_review(model_id: str, role: str, decision: str, version: str | None = None, comment: str | None = None)[source]

Create a review for a release.

Parameters:
  • model_id – A unique model ID

  • version – A semantic version for a release

  • role – The role of the user making the review

  • decision – Either approve or request changes

  • comment – A comment to go with the review

post_schema(schema_id: str, name: str, description: str, kind: SchemaKind, json_schema: dict[str, Any])[source]

Create a schema.

Parameters:
  • schema_id – Unique schema ID

  • name – Name of the schema

  • description – Description for the schema

  • kind – Enum to define schema kind (e.g. Model or AccessRequest)

  • json_schema – JSON schema

Returns:

JSON response object

post_team(team_id: str, name: str, description: str)[source]

Create new team.

Parameters:
  • team_id – Unique team ID

  • name – Team name

  • description – Team description

Returns:

JSON response object

put_model_card(model_id: str, metadata: Any)[source]

Update the latest model card, using the unique model ID.

Parameters:
  • model_id – Unique model ID

  • metadata – Metadata object, defined by model card schema

Returns:

JSON response object

put_release(model_id: str, release_version: str, notes: str, draft: bool, file_ids: list[str], images: list[str])[source]

Create a new model release.

Parameters:
  • model_id – Unique model ID

  • model_card_version – Model card version

  • release_version – Release version

  • notes – Notes on release

  • file_ids – Files for release

  • images – Images for release

  • minor – Signifies a minor release, defaults to False

  • draft – Signifies a draft release, defaults to False

Returns:

JSON response object

simple_upload(model_id: str, name: str, buffer: BytesIO)[source]

Create a simple file upload.

Parameters:
  • model_id – Unique model ID

  • name – File name

Returns:

JSON response object

class bailo.core.enums.EntryKind(value)[source]

The type of model.

DATACARD = 'data-card'
MODEL = 'model'
class bailo.core.enums.MinimalSchema(value)[source]

A minimal schema.

ACCESS_REQUEST = 'minimal-access-request-general-v10'
DATACARD = 'minimal-data-card-v10'
MODEL = 'minimal-general-v10'
class bailo.core.enums.ModelVisibility(value)[source]

Whether a model is publicly visible or not.

PRIVATE = 'private'
PUBLIC = 'public'
class bailo.core.enums.Role(value)[source]

A reviewing role.

MODEL_SENIOR_RESPONSIBLE_OFFICER = 'msro'
MODEL_TECHNICAL_REVIEWER = 'mtr'
OWNER = 'owner'
class bailo.core.enums.SchemaKind(value)[source]

A type of schema.

ACCESS_REQUEST = 'accessRequest'
MODEL = 'model'
exception bailo.core.exceptions.BailoException[source]

General exception for Bailo response errors.

exception bailo.core.exceptions.ResponseException[source]

Exception used if an endpoint gave no response.