bailo.helper package
- class bailo.helper.access_request.AccessRequest(client: Client, model_id: str, schema_id: str, metadata: Any, access_request_id: str, created_by: str, deleted: bool = False)[source]
Bases:
object
Represent a review within Bailo.
A review can either be access to a model or to a specific release.
- Parameters:
client – A client object that is used to make requests to bailo
name – The name of the access request
model_id – The unique model id of the model that the access request is being made with
schema_id – An ID for the schema within Bailo
metadata – A metadata object
access_request_id – The Unique ID for this access request
deleted – Whether the access request has been deleted
- classmethod create(client: Client, model_id: str, metadata: Any, schema_id: str = MinimalSchema.ACCESS_REQUEST) AccessRequest [source]
Make an access request for the model.
Posts an access request to Bailo to be reviewed
- Parameters:
client – A client object used to interact with Bailo
name – The name of the access request
model_id – A unique model ID within Bailo
schema_id – A unique schema ID, defaults to minimal-access-request-general-v10
- Returns:
JSON response object
- delete() bool [source]
Delete the access request on Bailo.
- Returns:
A message confirming the removal of the access request.
- classmethod from_id(client: Client, model_id: str, access_request_id: str) AccessRequest [source]
Return an existing review from Bailo given it’s unique ID.
- Parameters:
client – A client object used to interact with Bailo
model_id – A unique model ID within Bailo
access_request_id – A unique ID for an access request
- class bailo.helper.datacard.Datacard(client: Client, datacard_id: str, name: str, description: str, visibility: ModelVisibility | None = None)[source]
Bases:
Entry
Represent a datacard within Bailo.
- Parameters:
client – A client object used to interact with Bailo
datacard_id – A unique ID for the datacard
name – Name of datacard
description – Description of datacard
visibility – Visibility of datacard, using ModelVisibility enum (e.g Public or Private), defaults to None
- classmethod create(client: Client, name: str, description: str, team_id: str, visibility: ModelVisibility | None = None) Datacard [source]
Build a datacard from Bailo and upload it.
- Parameters:
client – A client object used to interact with Bailo
name – Name of datacard
description – Description of datacard
team_id – A unique team ID
visibility – Visibility of datacard, using ModelVisibility enum (e.g Public or Private), defaults to None
- Returns:
Datacard object
- property data_card
- property data_card_schema
- property data_card_version
- class bailo.helper.entry.Entry(client: Client, id: str, name: str, description: str, kind: EntryKind, visibility: ModelVisibility | None = None)[source]
Bases:
object
- card_from_schema(schema_id: str | None = None) None [source]
Create a card using a schema on Bailo.
- Parameters:
schema_id – A unique schema ID, defaults to None. If None, either minimal-general-v10 or minimal-data-card-v10 is used
- card_from_template()[source]
Create a card using a template (not yet implemented).
- Raises:
NotImplementedError – Not implemented error
- class bailo.helper.model.Experiment(model: Model)[source]
Bases:
object
Represent an experiment locally.
- Parameters:
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: Model) Experiment [source]
Create an experiment locally.
- Parameters:
model – A Bailo model object which the experiment is being run on
- Returns:
Experiment object
- from_mlflow(tracking_uri: str, experiment_id: str)[source]
Imports information from an MLFlow Tracking experiment.
- Parameters:
tracking_uri – MLFlow Tracking server URI
experiment_id – MLFlow Tracking experiment ID
- Raises:
ImportError – Import error if MLFlow not installed
- log_artifacts(artifacts: list)[source]
Logs artifacts to the current run.
- Parameters:
artifacts – A list of artifact paths to be logged
- log_dataset(dataset: str)[source]
Logs a dataset to the current run.
- Parameters:
dataset – Arbitrary title of dataset
- log_metrics(metrics: dict[str, Any])[source]
Logs metrics to the current run.
- Parameters:
metrics – Dictionary of metrics to be logged
- log_params(params: dict[str, Any])[source]
Logs parameters to the current run.
- Parameters:
params – Dictionary of parameters to be logged
- publish(mc_loc: str, semver: str = '0.1.0', notes: str = '', run_id: str | None = None, select_by: str | None = None)[source]
Publishes a given experiments results to the model card.
- Parameters:
mc_loc – Location of metrics in the model card (e.g. performance.performanceMetrics)
semver – Semantic version of release to create (if artifacts present), defaults to 0.1.0 or next
notes – Notes for release, defaults to “”
run_id – Local experiment run ID to be selected, defaults to None
select_by – 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.model.Model(client: Client, model_id: str, name: str, description: str, visibility: ModelVisibility | None = None)[source]
Bases:
Entry
Represent a model within Bailo.
- Parameters:
client – A client object used to interact with Bailo
model_id – A unique ID for the model
name – Name of model
description – Description of model
visibility – Visibility of model, using ModelVisibility enum (e.g Public or Private), defaults to None
- classmethod create(client: Client, name: str, description: str, team_id: str, visibility: ModelVisibility | None = None) Model [source]
Build a model from Bailo and upload it.
- Parameters:
client – A client object used to interact with Bailo
name – Name of model
description – Description of model
team_id – A unique team ID
visibility – Visibility of model, using ModelVisibility enum (e.g Public or Private), defaults to None
- Returns:
Model object
- create_experiment() Experiment [source]
Create an experiment locally
- Returns:
An experiment object
- create_release(version: Version | str, notes: str, files: list[str] | None = None, images: list[str] | None = None, minor: bool = False, draft: bool = True) Release [source]
Call the Release.create method to build a release from Bailo and upload it.
- Parameters:
version – A semantic version for the release
notes – Notes on release, defaults to “”
files – A list of files for release, defaults to []
images – A list of images for release, defaults to []
minor – Is a minor release?, defaults to False
draft – Is a draft release?, defaults to True
- Returns:
Release object
- classmethod from_id(client: Client, model_id: str) Model [source]
Return an existing model from Bailo.
- Parameters:
client – A client object used to interact with Bailo
model_id – A unique model ID
- Returns:
A model object
- classmethod from_mlflow(client: Client, mlflow_uri: str, team_id: str, name: str, schema_id: str = MinimalSchema.MODEL, version: str | None = None, files: bool = True, visibility: ModelVisibility | None = None) Model [source]
Import an MLFlow Model into Bailo.
- Parameters:
client – A client object used to interact with Bailo
mlflow_uri – MLFlow server URI
team_id – A unique team ID
name – Name of model (on MLFlow). Same name will be used on Bailo
schema_id – A unique schema ID, only required when files is True, defaults to minimal-general-v10
version – Specific MLFlow model version to import, defaults to None
files – Import files?, defaults to True
visibility – Visibility of model on Bailo, using ModelVisibility enum (e.g Public or Private), defaults to None
- Returns:
A model object
- get_image()[source]
Get a model image reference.
- Raises:
NotImplementedError – Not implemented error.
- get_latest_release()[source]
Get the latest release for the model from Bailo.
- Returns:
Release object
- get_release(version: Version | str) Release [source]
Call the Release.from_version method to return an existing release from Bailo.
- Parameters:
version – A semantic version for the release
- Returns:
Release object
- get_releases() list[Release] [source]
Get all releases for the model.
- Returns:
List of Release objects
- property model_card
- property model_card_schema
- property model_card_version
- classmethod search(client: Client, task: str | None = None, libraries: list[str] | None = None, filters: list[str] | None = None, search: str = '') list[Model] [source]
Return a list of model objects from Bailo, based on search parameters.
- Parameters:
client – A client object used to interact with Bailo
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:
List of model objects
- class bailo.helper.release.Release(client: Client, model_id: str, version: Version | str, model_card_version: int | None = None, notes: str = '', files: list[str] | None = None, images: list[str] | None = None, minor: bool = False, draft: bool = True)[source]
Bases:
object
- __init__(client: Client, model_id: str, version: Version | str, model_card_version: int | None = None, notes: str = '', files: list[str] | None = None, images: list[str] | None = None, minor: bool = False, draft: bool = True) None [source]
Represent a release within Bailo.
- Parameters:
client – A client object used to interact with Bailo
model_id – A unique model ID
version – A semantic version for the release
model_card_version – Version of the model card
notes – Notes on release
files – (optional) A list of files for release
images – (optional) A list of images for release
minor – Is a minor release?
draft – Is a draft release?
..note:: Currently files and images are stored as string references
- classmethod create(client: Client, model_id: str, version: Version | str, notes: str, model_card_version: int | None = None, files: list[str] | None = None, images: list[str] | None = None, minor: bool = False, draft: bool = True) Release [source]
Build a release from Bailo and uploads it.
- Parameters:
client – A client object used to interact with Bailo
model_id – A Unique Model ID
version – A semantic version of a model release
- download(filename: str, write: bool = True, path: str | None = None) Any [source]
Returns a response object given the file name and optionally writes file to disk.
- Parameters:
filename – The name of the file to retrieve
write – Bool to determine if writing file to disk, defaults to True
path – Local path to write file to (if write set to True)
- Returns:
A JSON response object
- download_all(path: str = '/home/runner/work/Bailo/Bailo/backend/docs', include: list | str | None = None, exclude: list | str | None = None)[source]
Writes all files to disk given a local directory.
- Parameters:
include – List or string of fnmatch statements for file names to include, defaults to None
exclude – List or string of fnmatch statements for file names to exclude, defaults to None
path – Local directory to write files to
- Raises:
BailoException – If the release has no files assigned to it
..note:: Fnmatch statements support Unix shell-style wildcards.
- classmethod from_version(client: Client, model_id: str, version: Version | str) Release [source]
Return an existing release from Bailo.
- Parameters:
client – A client object used to interact with Bailo
model_id – A Unique Model ID
version – A semantic version of a model release
- update() Any [source]
Update the any changes to this release on Bailo.
- Returns:
JSON Response object
- upload(path: str, data: BytesIO | None = None) str [source]
Upload a file to the release.
- Parameters:
path – The path, or name of file or directory to be uploaded
data – A BytesIO object if not loading from disk, defaults to None
- Returns:
The unique file ID of the file uploaded
..note:: If path provided is a directory, it will be uploaded as a zip
- property version
- class bailo.helper.schema.Schema(client: Client, schema_id: str, name: str, description: str, kind: SchemaKind, json_schema: dict[str, Any])[source]
Represent a schema within Bailo.
- Parameters:
client – A client object used to interact with Bailo
schema_id – A unique schema ID
name – Name of schema
description – Description of the schema
kind – Kind of schema, using SchemaKind enum (e.g Model or AccessRequest)
json_schema – Schema JSON
- classmethod create(client: Client, schema_id: str, name: str, description: str, kind: SchemaKind, json_schema: dict[str, Any]) Schema [source]
Build a schema from Bailo and uploads it.
- Parameters:
client – A client object used to interact with Bailo
schema_id – A unique schema ID
name – Name of schema
description – Description of schema
kind – Kind of schema, using SchemaKind enum (e.g Model or AccessRequest)
json_schema – Schema JSON
- Returns:
Schema object
- classmethod from_id(client: Client, schema_id: str) Schema [source]
Return an existing schema from Bailo.
- Parameters:
client – A client object used to interact with Bailo
schema_id – A unique schema ID
- Returns:
Schema object
- static get_all_schema_ids(client: Client, kind: SchemaKind | None = None) list[str] [source]
Return all schema ids for a given type.
- Parameters:
client – A client object used to interact with Bailo
kind – Enum to define schema kind (e.g. Model or AccessRequest), defaults to None
- Returns:
List of schema IDs