firebase.firestore package

A simple python wrapper for Google’s Firebase Cloud Firestore REST API

class firebase.firestore.Collection(collection_path, api_key, credentials, project_id, requests)[source]

Bases: object

A reference to a collection in a Firestore database.

Parameters:
  • collection_path (list) – Collective form of strings to create a Collection.

  • api_key (str) – apiKey from Firebase configuration

  • credentials (Credentials) – Service Account Credentials

  • project_id (str) – projectId from Firebase configuration

  • requests (Session) – Session to make HTTP requests

add(data, token=None)[source]

Create a document in the Firestore database with the provided data using an auto generated ID for the document.

Parameters:
  • data (dict) – Data to be stored in firestore.

  • token (str) – (Optional) Firebase Auth User ID Token, defaults to None.

Returns:

returns the auto generated document ID, used to store the data.

Return type:

str

document(document_id)[source]

A reference to a document in a collection.

Parameters:

document_id (str) – An ID of document inside a collection.

Returns:

Reference to a document.

Return type:

Document

end_at(document_fields)[source]

End query at a cursor with this collection as parent.

Parameters:

document_fields (dict) – A dictionary of fields representing a query results cursor. A cursor is a collection of values that represent a position in a query result set.

Returns:

A reference to the instance object.

Return type:

Collection

end_before(document_fields)[source]

End query before a cursor with this collection as parent.

Parameters:

document_fields (dict) – A dictionary of fields representing a query results cursor. A cursor is a collection of values that represent a position in a query result set.

Returns:

A reference to the instance object.

Return type:

Collection

get(token=None)[source]

Returns a list of dict’s containing document ID and the data stored within them.

Parameters:

token (str) – (Optional) Firebase Auth User ID Token, defaults to None.

Returns:

A list of document ID’s with the data they possess.

Return type:

list

limit_to_first(count)[source]

Create a limited query with this collection as parent.

Note

limit_to_first and limit_to_last are mutually exclusive. Setting limit_to_first will drop previously set limit_to_last.

Parameters:

count (int) – Maximum number of documents to return that match the query.

Returns:

A reference to the instance object.

Return type:

Collection

limit_to_last(count)[source]

Create a limited to last query with this collection as parent.

Note

limit_to_first and limit_to_last are mutually exclusive. Setting limit_to_first will drop previously set limit_to_last.

Parameters:

count (int) – Maximum number of documents to return that match the query.

Returns:

A reference to the instance object.

Return type:

Collection

list_of_documents(token=None)[source]

List all sub-documents of the current collection.

Parameters:

token (str) – (Optional) Firebase Auth User ID Token, defaults to None.

Returns:

A list of document ID’s.

Return type:

list

offset(num_to_skip)[source]

Skip to an offset in a query with this collection as parent.

Parameters:

num_to_skip (int) – The number of results to skip at the beginning of query results. (Must be non-negative.)

Returns:

A reference to the instance object.

Return type:

Collection

order_by(field_path, **kwargs)[source]

Create an “order by” query with this collection as parent.

Parameters:

field_path (str) – A field path (.-delimited list of field names) on which to order the query results.

Keyword Arguments:
  • direction ( str ) –

    Sort query results in ascending/descending order on a field.

Returns:

A reference to the instance object.

Return type:

Collection

select(field_paths)[source]

Create a “select” query with this collection as parent.

Parameters:

field_paths (list) – A list of field paths (.-delimited list of field names) to use as a projection of document fields in the query results.

Returns:

A reference to the instance object.

Return type:

Collection

start_after(document_fields)[source]

Start query after a cursor with this collection as parent.

Parameters:

document_fields (dict) – A dictionary of fields representing a query results cursor. A cursor is a collection of values that represent a position in a query result set.

Returns:

A reference to the instance object.

Return type:

Collection

start_at(document_fields)[source]

Start query at a cursor with this collection as parent.

Parameters:

document_fields (dict) – A dictionary of fields representing a query results cursor. A cursor is a collection of values that represent a position in a query result set.

Returns:

A reference to the instance object.

Return type:

Collection

where(field_path, op_string, value)[source]

Create a “where” query with this collection as parent.

Parameters:
  • field_path (str) – A field path (.-delimited list of field names) for the field to filter on.

  • op_string (str) – A comparison operation in the form of a string. Acceptable values are <, <=, ==, != , >=, >, in, not-in, array_contains and array_contains_any.

  • value (Any) – The value to compare the field against in the filter. If value is None or a NaN, then == is the only allowed operation. If op_string is in, value must be a sequence of values.

Returns:

A reference to the instance object.

Return type:

Collection

class firebase.firestore.Document(document_path, api_key, credentials, project_id, requests)[source]

Bases: object

A reference to a document in a Firestore database.

Parameters:
  • document_path (list) – Collective form of strings to create a Document.

  • api_key (str) – apiKey from Firebase configuration

  • credentials (Credentials) – Service Account Credentials

  • project_id (str) – projectId from Firebase configuration

  • requests (Session) – Session to make HTTP requests

collection(collection_id)[source]

A reference to a collection in a Firestore database.

Parameters:

collection_id (str) – An ID of collection in firestore.

Returns:

Reference to a collection.

Return type:

Collection

delete(token=None)[source]

Deletes the current document from firestore.

Parameters:

token (str) – (Optional) Firebase Auth User ID Token, defaults to None.

get(field_paths=None, token=None)[source]

Read data from a document in firestore.

Parameters:
  • field_paths (list) – (Optional) A list of field paths (.-delimited list of field names) to filter data, and return the filtered values only, defaults to None.

  • token (str) – (Optional) Firebase Auth User ID Token, defaults to None.

Returns:

The whole data stored in the document unless filtered to retrieve specific fields.

Return type:

dict

set(data, token=None)[source]

Add data to a document in firestore.

Parameters:
  • data (dict) – Data to be stored in firestore.

  • token (str) – (Optional) Firebase Auth User ID Token, defaults to None.

update(data, token=None)[source]

Update stored data inside a document in firestore.

Parameters:
  • data (dict) – Data to be stored in firestore.

  • token (str) – (Optional) Firebase Auth User ID Token, defaults to None.

class firebase.firestore.Firestore(api_key, credentials, project_id, requests)[source]

Bases: object

Firebase Firestore Service

Parameters:
  • api_key (str) – apiKey from Firebase configuration

  • credentials (Credentials) – Service Account Credentials

  • project_id (str) – projectId from Firebase configuration

  • requests (Session) – Session to make HTTP requests

collection(collection_id)[source]

Get reference to a collection in a Firestore database.

Parameters:

collection_id (str) – An ID of collection in firestore.

Returns:

Reference to a collection.

Return type:

Collection