bailo.helper package
Note
All helper methods raise BailoException on
API errors. These exceptions include the HTTP status code, error message, and
full error context from the backend (e.g. per-field validation errors for
model card or datacard updates). See the bailo.core.exceptions module
documentation for details and usage examples.
- class bailo.helper.access_request.AccessRequest(client, model_id, schema_id, metadata, access_request_id, created_by, deleted=False)[source]
Bases:
objectRepresent an access request within Bailo.
- Parameters:
client (Client) – Bailo Client instance used for requests.
model_id (str) – Unique model ID.
schema_id (str) – ID of the schema used for the request.
metadata (Any) – Access request metadata.
access_request_id (str) – Unique ID for this access request.
created_by (str) – Username or ID of the request creator.
deleted (bool) – Whether the access request has been deleted, defaults to False.
- classmethod from_id(client, model_id, access_request_id)[source]
Return an existing access request from Bailo given its unique ID.
- Parameters:
client (Client) – A client object used to interact with Bailo
model_id (str) – A unique model ID within Bailo
access_request_id (str) – A unique ID for an access request
- Returns:
AccessRequest object
- Return type:
- classmethod create(client, model_id, metadata, schema_id=MinimalSchema.ACCESS_REQUEST)[source]
Make an access request for the model.
Posts an access request to Bailo to be reviewed
- Parameters:
client (Client) – A client object used to interact with Bailo
model_id (str) – A unique model ID within Bailo
metadata (Any) – Access request metadata.
schema_id (str) – A unique schema ID, defaults to minimal-access-request-general-v10
- Returns:
AccessRequest object
- Return type:
- class bailo.helper.datacard.Datacard(client, datacard_id, name, description, organisation=None, state=None, tags=None, collaborators=None, visibility=None)[source]
Bases:
EntryRepresent a datacard within Bailo.
- Parameters:
client (Client) – A client object used to interact with Bailo
datacard_id (str) – A unique ID for the datacard
name (str) – Name of datacard
description (str) – Description of datacard
organisation (str | None) – Organisation responsible for the datacard, defaults to None
state (str | None) – Development readiness of the datacard, defaults to None
tags (list[str] | None) – Tags to assign to the datacard, defaults to None
collaborators (list[CollaboratorEntry] | None) – List of CollaboratorEntry to define who the datacard’s collaborators (a.k.a. model access) are, defaults to None
visibility (ModelVisibility | None) – Visibility of datacard, using ModelVisibility enum (e.g Public or Private), defaults to None
- classmethod create(client, name, description, organisation=None, state=None, tags=None, collaborators=None, visibility=None)[source]
Build a datacard from Bailo and upload it.
- Parameters:
client (Client) – A client object used to interact with Bailo
name (str) – Name of datacard
description (str) – Description of datacard
organisation (str | None) – Organisation responsible for the datacard, defaults to None
state (str | None) – Development readiness of the datacard, defaults to None
tags (list[str] | None) – Tags to assign to the datacard, defaults to None
collaborators (list[CollaboratorEntry] | None) – List of CollaboratorEntry to define who the datacard’s collaborators (a.k.a. datacard access) are, defaults to None
visibility (ModelVisibility | None) – Visibility of datacard, using ModelVisibility enum (e.g Public or Private), defaults to None
- Returns:
Datacard object
- Return type:
- update_data_card(data_card=None)[source]
Upload and retrieve any changes to the datacard on Bailo.
- Parameters:
data_card (dict[str, Any] | None) – Datacard dictionary, defaults to None
- Return type:
None
Note
If a datacard is not provided, the current datacard attribute value is used
- property data_card
Get the datacard metadata.
- Returns:
Datacard as a dictionary.
- property data_card_version
Get the version of the datacard.
- Returns:
Datacard version.
- property data_card_schema
Get the schema ID associated with the datacard.
- Returns:
Schema ID of the datacard.
- class bailo.helper.entry.Entry(client, id, name, description, kind, visibility=None, organisation=None, state=None, tags=None, collaborators=None)[source]
Bases:
objectRepresent an entry in Bailo
- Parameters:
client (Client) – A client object used to interact with Bailo
id (str) – A unique ID for the entry
name (str) – Name of the entry
description (str) – Description of the entry
kind (EntryKind) – Represents whether entry type (i.e. Model, Mirrored Model or Datacard)
visibility (ModelVisibility | None) – Visibility of entry, using ModelVisibility enum (i.e. Public or Private), defaults to None
organisation (str | None) – Organisation responsible for the entry, defaults to None
state (str | None) – Development readiness of the entry, defaults to None
tags (list[str] | None) – Tags to assign to the entry, defaults to None
collaborators (list[CollaboratorEntry] | None) – List of CollaboratorEntry to define who the entry’s collaborators (a.k.a. entry access) are, defaults to None
- card_from_schema(schema_id=None)[source]
Create a card using a schema on Bailo.
- Parameters:
schema_id (str | None) – A unique schema ID, defaults to None. If None, either minimal-general-v10 or minimal-data-card-v10 is used
- Return type:
None
- card_from_template(template_id)[source]
Create a card using a template.
- Parameters:
template_id (str) – Previous model’s unique ID to be used as template
- Return type:
None
- get_card_revision(version)[source]
Get a specific entry card revision from Bailo.
- Parameters:
version (str) – Entry card version
- Return type:
None
- _update_card(card=None)[source]
Update the card metadata for this entry on the Bailo server.
- Parameters:
card (dict[str, Any] | None) – Metadata dictionary to update, defaults to None to use existing card.
- Return type:
None
- class bailo.helper.mirroredModel.MirroredModel(client, model_id, name, description, sourceModelId, organisation=None, state=None, tags=None, collaborators=None, visibility=None)[source]
Bases:
EntryRepresent a mirrored model within Bailo.
- Parameters:
client (Client) – A client object used to interact with Bailo
model_id (str) – A unique ID for the mirrored model
name (str) – Name of mirrored model
description (str) – Description of mirrored model
sourceModelId (str) – Used for linking a mirrored model to its source model
organisation (str | None) – Organisation responsible for the mirrored model, defaults to None
state (str | None) – Development readiness of the mirrored model, defaults to None
tags (list[str] | None) – Tags to assign to the mirrored model, defaults to None
collaborators (list[CollaboratorEntry] | None) – List of CollaboratorEntry to define who the mirrored model’s collaborators (a.k.a. mirrored model access) are, defaults to None
visibility (ModelVisibility | None) – Visibility of the mirrored model, using ModelVisibility enum (e.g Public or Private), defaults to None
- classmethod create(client, name, description, sourceModelId, organisation=None, state=None, tags=None, collaborators=None, visibility=None)[source]
Build a mirrored model from Bailo and upload it.
- Parameters:
client (Client) – A client object used to interact with Bailo
name (str) – Name of mirrored model
description (str) – Description of mirrored model
sourceModelId (str) – Used for linking a mirrored model to its source model
organisation (str | None) – Organisation responsible for the mirrored model, defaults to None
state (str | None) – Development readiness of the mirrored model, defaults to None
tags (list[str] | None) – Tags to assign to the mirrored model, defaults to None
collaborators (list[CollaboratorEntry] | None) – List of CollaboratorEntry to define who the mirrored model’s collaborators (a.k.a. model access) are, defaults to None
visibility (ModelVisibility | None) – Visibility of the mirrored model, using ModelVisibility enum (e.g Public or Private), defaults to None
- Returns:
MirroredModel object
- Return type:
- update()[source]
Upload and retrieve any changes to the mirrored model summary on Bailo.
Merges the sourceModelId into settings when it has changed, then delegates to the base update.
- Return type:
None
- _unpack(res)[source]
Update mirrored model attributes from API response.
- Parameters:
res – Response dictionary containing model information.
- classmethod from_id(client, model_id)[source]
Return an existing mirrored model from Bailo.
- Parameters:
client (Client) – A client object used to interact with Bailo
model_id (str) – A unique mirrored model ID
- Returns:
A mirrored model object
- Return type:
- classmethod search(client, task=None, libraries=None, filters=None, search='', organisations=None, states=None, allow_templating=None, schema_id=None, admin_access=None, peers=None, title_only=None)[source]
Return a list of mirrored model objects from Bailo, based on search parameters.
- Parameters:
client (Client) – A client object used to interact with Bailo
task (str | None) – Mirrored model task (e.g. image classification), defaults to None
libraries (list[str] | None) – Mirrored model library (e.g. TensorFlow), defaults to None
filters (list[str] | None) – List of collaborator role filters. Special value “mine” restricts results to models where the current user is a collaborator. Otherwise, values are treated as collaborator roles, defaults to None
search (str) – Free-text search string. Always performs a partial, case-insensitive match against the mirrored model name. If title_only is False, a full-text search across mirrored model content is also performed, defaults to “”
organisations (list[str] | None) – List of organisation identifiers to restrict results, defaults to None
states (list[str] | None) – List of mirrored model lifecycle states to restrict results, defaults to None
allow_templating (bool | None) – If True, restricts results to models with templating enabled, defaults to None
schema_id (str | None) – Schema ID to restrict results to models using that schema, defaults to None
admin_access (bool | None) – If True, returns models requiring admin access. The caller must have the Admin role or the request will be rejected by the backend, defaults to None
peers (list[str] | None) – List of peer identifiers to include remote search results from, defaults to None
title_only (bool | None) – If True, limits searching to mirrored model titles only and disables full-text search, defaults to None
- Returns:
List of mirrored model objects
- Return type:
list[MirroredModel]
- get_releases()[source]
Get all releases for the mirrored model.
- Returns:
List of Release objects
- Return type:
list[Release]
- get_release(version)[source]
Call the Release.from_version method to return an existing release from Bailo.
- Parameters:
version (Version | str) – A semantic version for the release
- Returns:
Release object
- Return type:
- get_latest_release()[source]
Get the latest release for the mirrored model from Bailo.
- Returns:
Release object
- get_images()[source]
Get all model image references for the mirrored model.
- Returns:
List of images
- get_image()[source]
Get a model image reference.
- Raises:
NotImplementedError – Not implemented error.
- update_model_card(model_card=None)[source]
Upload and retrieve any changes to the editable mirrored model card on Bailo.
- Parameters:
model_card (dict[str, Any] | None) – Model card dictionary, defaults to None
- Return type:
None
Note
If a model card is not provided, the current model card attribute value is used
- property model_card
Get the data of the model card.
- Returns:
Model card data.
- property model_card_version
Get the version of the mirrored model card.
- Returns:
Model card version.
- property model_card_schema
Get the schema of the mirrored model card.
- Returns:
Model card schema.
- class bailo.helper.model.Model(client, model_id, name, description, organisation=None, state=None, tags=None, collaborators=None, visibility=None)[source]
Bases:
EntryRepresent a model within Bailo.
- Parameters:
client (Client) – A client object used to interact with Bailo
model_id (str) – A unique ID for the model
name (str) – Name of model
description (str) – Description of model
organisation (str | None) – Organisation responsible for the model, defaults to None
state (str | None) – Development readiness of the model, defaults to None
tags (list[str] | None) – Tags to assign to the model, defaults to None
collaborators (list[CollaboratorEntry] | None) – List of CollaboratorEntry to define who the model’s collaborators (a.k.a. model access) are, defaults to None
visibility (ModelVisibility | None) – Visibility of model, using ModelVisibility enum (e.g Public or Private), defaults to None
- classmethod create(client, name, description, organisation=None, state=None, tags=None, collaborators=None, visibility=None)[source]
Build a model from Bailo and upload it.
- Parameters:
client (Client) – A client object used to interact with Bailo
name (str) – Name of model
description (str) – Description of model
organisation (str | None) – Organisation responsible for the model, defaults to None
state (str | None) – Development readiness of the model, defaults to None
tags (list[str] | None) – Tags to assign to the model, defaults to None
collaborators (list[CollaboratorEntry] | None) – List of CollaboratorEntry to define who the model’s collaborators (a.k.a. model access) are, defaults to None
visibility (ModelVisibility | None) – Visibility of model, using ModelVisibility enum (e.g Public or Private), defaults to None
- Returns:
Model object
- Return type:
- classmethod search(client, task=None, libraries=None, filters=None, search='', organisations=None, states=None, allow_templating=None, schema_id=None, admin_access=None, peers=None, title_only=None)[source]
Return a list of model objects from Bailo, based on search parameters.
- Parameters:
client (Client) – A client object used to interact with Bailo
task (str | None) – Model task (e.g. image classification), defaults to None
libraries (list[str] | None) – Model library (e.g. TensorFlow), defaults to None
filters (list[str] | None) – List of collaborator role filters. Special value “mine” restricts results to models where the current user is a collaborator. Otherwise, values are treated as collaborator roles, defaults to None
search (str) – Free-text search string. Always performs a partial, case-insensitive match against the model name. If title_only is False, a full-text search across model content is also performed, defaults to “”
organisations (list[str] | None) – List of organisation identifiers to restrict results, defaults to None
states (list[str] | None) – List of model lifecycle states to restrict results, defaults to None
allow_templating (bool | None) – If True, restricts results to models with templating enabled, defaults to None
schema_id (str | None) – Schema ID to restrict results to models using that schema, defaults to None
admin_access (bool | None) – If True, returns models requiring admin access. The caller must have the Admin role or the request will be rejected by the backend, defaults to None
peers (list[str] | None) – List of peer identifiers to include remote search results from, defaults to None
title_only (bool | None) – If True, limits searching to model titles only and disables full-text search, defaults to None
- Returns:
List of model objects
- Return type:
list[Model]
- classmethod from_mlflow(client, mlflow_uri, name, schema_id=MinimalSchema.MODEL, version=None, files=True, visibility=None, organisation=None, state=None, tags=None, collaborators=None)[source]
Import an MLFlow Model into Bailo.
- Parameters:
client (Client) – A client object used to interact with Bailo
mlflow_uri (str) – MLFlow server URI
name (str) – Name of model (on MLFlow). Same name will be used on Bailo
schema_id (str) – A unique schema ID, only required when files is True, defaults to minimal-general-v10
version (str | None) – Specific MLFlow model version to import, defaults to None
files (bool) – Import files?, defaults to True
visibility (ModelVisibility | None) – Visibility of model on Bailo, using ModelVisibility enum (e.g Public or Private), defaults to None
organisation (str | None) – Organisation responsible for the model, defaults to None
state (str | None) – Development readiness of the model, defaults to None
tags (list[str] | None) – Tags to assign to the model, defaults to None
collaborators (list[CollaboratorEntry] | None) – List of CollaboratorEntry to define who the model’s collaborators (a.k.a. model access) are, defaults to None
- Returns:
A model object
- Return type:
- update_model_card(model_card=None)[source]
Upload and retrieve any changes to the model card on Bailo.
- Parameters:
model_card (dict[str, Any] | None) – Model card dictionary, defaults to None
- Return type:
None
Note
If a model card is not provided, the current model card attribute value is used
- create_experiment()[source]
Create an experiment locally
- Returns:
An experiment object
- Return type:
- create_release(version, notes, files=None, images=None, minor=False, draft=True)[source]
Call the Release.create method to build a release from Bailo and upload it.
- Parameters:
version (Version | str) – A semantic version for the release
notes (str) – Notes on release
files (list[str] | None) – A list of files for release, defaults to None
images (list[str] | None) – A list of images for release, defaults to None
minor (bool) – Is a minor release?, defaults to False
draft (bool) – Is a draft release?, defaults to True
- Returns:
Release object
- Return type:
- get_releases()[source]
Get all releases for the model.
- Returns:
List of Release objects
- Return type:
list[Release]
- get_release(version)[source]
Call the Release.from_version method to return an existing release from Bailo.
- Parameters:
version (Version | str) – A semantic version for the release
- Returns:
Release object
- Return type:
- get_latest_release()[source]
Get the latest release for the model from Bailo.
- Returns:
Release object
- get_image()[source]
Get a model image reference.
- Raises:
NotImplementedError – Not implemented error.
- property model_card
Get the data of the model card.
- Returns:
Model card data.
- property model_card_version
Get the version of the model card.
- Returns:
Model card version.
- property model_card_schema
Get the schema of the model card.
- Returns:
Model card schema.
- class bailo.helper.model.Experiment(model)[source]
Bases:
objectRepresent an experiment locally.
- Parameters:
model (Model) – A Bailo model object which the experiment is being run on
raw – Raw information about the experiment runs
experiment = model.create_experiment() for x in range(5): experiment.start_run() experiment.log_params({"lr": 0.01}) ### INSERT MODEL TRAINING HERE ### experiment.log_metrics("accuracy": 0.86) experiment.log_artifacts(["weights.pth"]) experiment.publish(mc_loc="performance.performanceMetrics", run_id=1)
- classmethod create(model)[source]
Create an experiment locally.
- Parameters:
model (Model) – A Bailo model object which the experiment is being run on
- Returns:
Experiment object
- Return type:
- start_run(is_mlflow=False)[source]
Starts a new experiment run.
- Parameters:
is_mlflow (bool) – Marks a run as MLFlow
- log_params(params)[source]
Logs parameters to the current run.
- Parameters:
params (dict[str, Any]) – Dictionary of parameters to be logged
- log_metrics(metrics)[source]
Logs metrics to the current run.
- Parameters:
metrics (dict[str, Any]) – Dictionary of metrics to be logged
- log_artifacts(artifacts)[source]
Logs artifacts to the current run.
- Parameters:
artifacts (list) – A list of artifact paths to be logged
- log_dataset(dataset)[source]
Logs a dataset to the current run.
- Parameters:
dataset (str) – Arbitrary title of dataset
- from_mlflow(tracking_uri, experiment_id)[source]
Imports information from an MLFlow Tracking experiment.
- Parameters:
tracking_uri (str) – MLFlow Tracking server URI
experiment_id (str) – MLFlow Tracking experiment ID
- Raises:
ImportError – Import error if MLFlow not installed
- publish(mc_loc, semver='0.1.0', notes='', run_id=None, select_by=None)[source]
Publishes a given experiments results to the model card.
- Parameters:
mc_loc (str) – Location of metrics in the model card (e.g. performance.performanceMetrics)
semver (str) – Semantic version of release to create (if artifacts present), defaults to 0.1.0 or next
notes (str) – Notes for release, defaults to “”
run_id (str | None) – Local experiment run ID to be selected, defaults to None
select_by (str | None) – String describing experiment to be selected (e.g. “accuracy MIN|MAX”), defaults to None
Note
mc_loc is dependent on the model card schema being used
Warning
User must specify either run_id or select_by, otherwise the code will error
- class bailo.helper.release.Release(client, model_id, version, model_card_version, notes='', files=None, images=None, minor=False, draft=True)[source]
Bases:
object- Parameters:
client (Client)
model_id (str)
version (Version | str)
model_card_version (int)
notes (str)
files (list[str] | None)
images (list[str] | None)
minor (bool)
draft (bool)
- __init__(client, model_id, version, model_card_version, notes='', files=None, images=None, minor=False, draft=True)[source]
Represent a release within Bailo.
- Parameters:
client (Client) – A client object used to interact with Bailo
model_id (str) – A unique model ID
version (Version | str) – A semantic version for the release
model_card_version (int) – Version of the model card
notes (str) – Notes on release
files (list[str] | None) – (optional) A list of files for release
images (list[str] | None) – (optional) A list of images for release
minor (bool) – Is a minor release?
draft (bool) – Is a draft release?
- Return type:
None
Note
Currently files and images are stored as string references
- classmethod create(client, model_id, version, notes, model_card_version, files=None, images=None, minor=False, draft=True)[source]
Build a release from Bailo and uploads it.
- Parameters:
client (Client) – A client object used to interact with Bailo
model_id (str) – A Unique Model ID
version (Version | str) – A semantic version of a model release
notes (str) – Notes on release
model_card_version (int) – Model card version
files (list[str] | None) – Files for release, defaults to None
images (list[str] | None) – Images for release, defaults to None
minor (bool) – Signifies a minor release, defaults to False
draft (bool) – Signifies a draft release, defaults to False
- Returns:
Release object
- Return type:
- download(filename, write=True, path=None)[source]
Returns a response object given the file name and optionally writes file to disk.
- Parameters:
filename (str) – The name of the file to retrieve
write (bool) – Bool to determine if writing file to disk, defaults to True
path (str | None) – Local path to write file to (if write set to True)
- Returns:
A JSON response object
- Return type:
Any
- download_all(path='/home/runner/work/Bailo/Bailo/backend/docs', include=None, exclude=None)[source]
Writes all files in a release to disk at the given path, applying inclusion/exclusion filters.
- Parameters:
path (str) – Local directory to output files.
include (list | str | None) – List of glob patterns (str) or single string to include, defaults to None
exclude (list | str | None) – List of glob patterns (str) or single string to exclude, defaults to None
- Raises:
BailoException – If the release has no files assigned.
Note
Fnmatch statements support Unix shell-style wildcards.
- upload(path, data=None)[source]
Upload a file to the release.
- Parameters:
path (str) – The path, or name of file or directory to be uploaded
data (BytesIO | None) – A BytesIO object if not loading from disk, defaults to None
- Returns:
The unique file ID of the file uploaded
- Return type:
str
Note
If path provided is a directory, it will be uploaded as a zip
- update()[source]
Update the any changes to this release on Bailo.
- Returns:
JSON Response object
- Return type:
Any
- property version
- class bailo.helper.schema.Schema(client, schema_id, name, description, kind, json_schema, review_roles)[source]
Bases:
objectRepresent a schema within Bailo.
- Parameters:
client (Client) – A client object used to interact with Bailo
schema_id (str) – A unique schema ID
name (str) – Name of schema
description (str) – Description of the schema
kind (SchemaKind) – Kind of schema, using SchemaKind enum (e.g Model or AccessRequest)
json_schema (dict[str, Any]) – Schema JSON
review_roles (list[str]) – List made up of the “shortName” property from a Review Role object
- classmethod create(client, schema_id, name, description, kind, json_schema, review_roles)[source]
Build a schema from Bailo and uploads it.
- Parameters:
client (Client) – A client object used to interact with Bailo
schema_id (str) – A unique schema ID
name (str) – Name of schema
description (str) – Description of schema
kind (SchemaKind) – Kind of schema, using SchemaKind enum (e.g Model or AccessRequest)
json_schema (dict[str, Any]) – Schema JSON
review_roles (list[str]) – List made up of the “shortName” property from a Review Role object
- Returns:
Schema object
- Return type:
- static get_all_schema_ids(client, kind=None)[source]
Return all schema ids for a given type.
- Parameters:
client (Client) – A client object used to interact with Bailo
kind (SchemaKind | None) – Enum to define schema kind (e.g. Model or AccessRequest), defaults to None
- Returns:
List of schema IDs
- Return type:
list[str]