firebase_admin.ml module

Firebase ML module.

This module contains functions for creating, updating, getting, listing,deleting, publishing and unpublishing Firebase ML models.

Classes

ListModelsPage

classfirebase_admin.ml.ListModelsPage(list_models_func,list_filter,page_size,page_token,app)

Bases:object

Represents a page of models in a Firebase project.

Provides methods for traversing the models included in this page, as well asretrieving subsequent pages of models. The iterator returned byiterate_all() can be used to iterate through all the models in theFirebase project starting from this page.

get_next_page()

Retrieves the next page of models if available.

Returns:

Next page of models, or None if this is the last page.

Return type:

ListModelsPage

iterate_all()

Retrieves an iterator for Models.

Returned iterator will iterate through all the models in the Firebaseproject starting from this page. The iterator will never buffer more thanone page of models in memory at a time.

Returns:

An iterator of Model instances.

Return type:

iterator

propertyhas_next_page

True if more pages are available.

propertylist_filter

The filter string used to filter the models.

propertymodels

A list of Models from this page.

propertynext_page_token

Token identifying the next page of results.

Model

classfirebase_admin.ml.Model(display_name=None,tags=None,model_format=None)

Bases:object

A Firebase ML Model object.

Parameters:
  • display_name – The display name of your model - used to identify your model in code.

  • tags – Optional list of strings associated with your model. Can be used in list queries.

  • model_format – A subclass of ModelFormat. (e.g. TFLiteFormat) Specifies the model details.

classmethodfrom_dict(data,app=None)

Create an instance of the object from a dict.

as_dict(for_upload=False)

Returns a serializable representation of the object.

wait_for_unlocked(max_time_seconds=None)

Waits for the model to be unlocked. (All active operations complete)

Parameters:

max_time_seconds – The maximum number of seconds to wait for the model to unlock.(None for no limit)

Raises:

exceptions.DeadlineExceeded – If max_time_seconds passed and the model is still locked.

propertycreate_time

The time the model was created.

propertydisplay_name

The model’s display name, used to refer to the model in code and inthe Firebase console.

propertyetag

The entity tag (ETag) of the model resource.

propertylocked

True if the Model object is locked by an active operation.

propertymodel_format

The model’sModelFormat object, which represents the model’sformat and storage location.

propertymodel_hash

SHA256 hash of the model binary.

propertymodel_id

The model’s ID, unique to the project.

propertypublished

True if the model is published and available for clients todownload.

propertytags

Tag strings, used for filtering query results.

propertyupdate_time

The time the model was last updated.

propertyvalidation_error

Validation error message.

ModelFormat

classfirebase_admin.ml.ModelFormat

Bases:object

Abstract base class representing a Model Format such as TFLite.

as_dict(for_upload=False)

Returns a serializable representation of the object.

TFLiteFormat

classfirebase_admin.ml.TFLiteFormat(model_source=None)

Bases:ModelFormat

Model format representing a TFLite model.

Parameters:

model_source – A TFLiteModelSource sub class. Specifies the details of the model source.

classmethodfrom_dict(data)

Create an instance of the object from a dict.

as_dict(for_upload=False)

Returns a serializable representation of the object.

propertymodel_source

The TF Lite model’s location.

propertysize_bytes

The size in bytes of the TF Lite model.

TFLiteGCSModelSource

classfirebase_admin.ml.TFLiteGCSModelSource(gcs_tflite_uri,app=None)

Bases:TFLiteModelSource

TFLite model source representing a tflite model file stored in GCS.

classmethodfrom_keras_model(keras_model,model_file_name='firebase_ml_model.tflite',bucket_name=None,app=None)

Creates a Tensor Flow Lite model from the keras model, and uploads the model to GCS.

Parameters:
  • keras_model – A tf.keras model.

  • model_file_name – The name that the tflite model will be saved as in Cloud Storage.

  • bucket_name – The name of an existing bucket. None to use the default bucket configuredin the app.

  • app – Optional. A Firebase app instance (or None to use the default app)

Returns:

The source created from the keras_model

Return type:

TFLiteGCSModelSource

Raises:

ImportError – If the Tensor Flow or Cloud Storage Libraries have not been installed.

classmethodfrom_saved_model(saved_model_dir,model_file_name='firebase_ml_model.tflite',bucket_name=None,app=None)

Creates a Tensor Flow Lite model from the saved model, and uploads the model to GCS.

Parameters:
  • saved_model_dir – The saved model directory.

  • model_file_name – The name that the tflite model will be saved as in Cloud Storage.

  • bucket_name – The name of an existing bucket. None to use the default bucket configuredin the app.

  • app – Optional. A Firebase app instance (or None to use the default app)

Returns:

The source created from the saved_model_dir

Return type:

TFLiteGCSModelSource

Raises:

ImportError – If the Tensor Flow or Cloud Storage Libraries have not been installed.

classmethodfrom_tflite_model_file(model_file_name,bucket_name=None,app=None)

Uploads the model file to an existing Google Cloud Storage bucket.

Parameters:
  • model_file_name – The name of the model file.

  • bucket_name – The name of an existing bucket. None to use the default bucket configuredin the app.

  • app – A Firebase app instance (or None to use the default app).

Returns:

The source created from the model_file

Return type:

TFLiteGCSModelSource

Raises:

ImportError – If the Cloud Storage Library has not been installed.

as_dict(for_upload=False)

Returns a serializable representation of the object.

propertygcs_tflite_uri

URI of the model file in Cloud Storage.

TFLiteModelSource

classfirebase_admin.ml.TFLiteModelSource

Bases:object

Abstract base class representing a model source for TFLite format models.

as_dict(for_upload=False)

Returns a serializable representation of the object.

Functions

create_model

firebase_admin.ml.create_model(model,app=None)

Creates a model in the current Firebase project.

Parameters:
  • model – An ml.Model to create.

  • app – A Firebase app instance (or None to use the default app).

Returns:

The model that was created in Firebase ML.

Return type:

Model

delete_model

firebase_admin.ml.delete_model(model_id,app=None)

Deletes a model from the current project.

Parameters:
  • model_id – The id of the model you wish to delete.

  • app – A Firebase app instance (or None to use the default app).

get_model

firebase_admin.ml.get_model(model_id,app=None)

Gets the model specified by the given ID.

Parameters:
  • model_id – The id of the model to get.

  • app – A Firebase app instance (or None to use the default app).

Returns:

The requested model.

Return type:

Model

list_models

firebase_admin.ml.list_models(list_filter=None,page_size=None,page_token=None,app=None)

Lists the current project’s models.

Parameters:
  • list_filter – a list filter string such astags:'tag_1'. None will return all models.

  • page_size – A number between 1 and 100 inclusive that specifies the maximumnumber of models to return per page. None for default.

  • page_token – A next page token returned from a previous page of results. Nonefor first page of results.

  • app – A Firebase app instance (or None to use the default app).

Returns:

A (filtered) list of models.

Return type:

ListModelsPage

publish_model

firebase_admin.ml.publish_model(model_id,app=None)

Publishes a Firebase ML model.

A published model can be downloaded to client apps.

Parameters:
  • model_id – The id of the model to publish.

  • app – A Firebase app instance (or None to use the default app).

Returns:

The published model.

Return type:

Model

unpublish_model

firebase_admin.ml.unpublish_model(model_id,app=None)

Unpublishes a Firebase ML model.

Parameters:
  • model_id – The id of the model to unpublish.

  • app – A Firebase app instance (or None to use the default app).

Returns:

The unpublished model.

Return type:

Model

update_model

firebase_admin.ml.update_model(model,app=None)

Updates a model’s metadata or model file.

Parameters:
  • model – The ml.Model to update.

  • app – A Firebase app instance (or None to use the default app).

Returns:

The updated model.

Return type:

Model

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-17 UTC.