Client(project=None, credentials=None, database='(default)', client_info=<google.api_core.gapic_v1.client_info.ClientInfo object>, client_options=None)
Client for interacting with Google Cloud Firestore API.
.. note::
Since the Cloud Firestore API requires the gRPC transport, no
``_http`` argument is accepted by this class.
Parameters
Name | Description |
project |
Optional[str]
The project which the client acts on behalf of. If not passed, falls back to the default inferred from the environment. |
credentials |
Optional[`google.auth.credentials.Credentials`]
The OAuth2 Credentials to use for this client. If not passed, falls back to the default inferred from the environment. |
database |
Optional[str]
The database name that the client targets. For now, |
client_info |
Optional[google.api_core.gapic_v1.client_info.ClientInfo]
The client info used to send a user-agent string along with API requests. If |
client_options |
Union[dict, google.api_core.client_options.ClientOptions]
Client options used to set user options on the client. API Endpoint should be set through client_options. |
Inheritance
builtins.object > google.cloud.client._ClientFactoryMixin > google.cloud.client.Client > builtins.object > google.cloud.client._ClientProjectMixin > google.cloud.client.ClientWithProject > ClientMethods
batch
batch()
Get a batch instance from this client.
Type | Description |
WriteBatch | A "write" batch to be used for accumulating document changes and sending the changes all at once. |
collection
collection(*collection_path)
Get a reference to a collection.
For a top-level collection:
>>> client.collection('top')
For a sub-collection:
>>> client.collection('mydocs/doc/subcol')
>>> # is the same as
>>> client.collection('mydocs', 'doc', 'subcol')
Sub-collections can be nested deeper in a similar fashion.
Name | Description |
collection_path |
Tuple[str, ...]
Can either be * A single |
Type | Description |
CollectionReference | A reference to a collection in the Firestore database. |
collection_group
collection_group(collection_id)
Creates and returns a new Query that includes all documents in the database that are contained in a collection or subcollection with the given collection_id.
>>> query = client.collection_group('mygroup')
@param {string} collectionId Identifies the collections to query over. Every collection or subcollection with this ID as the last segment of its path will be included. Cannot contain a slash. @returns {Query} The created Query.
collections
collections()
List top-level collections of the client's database.
Type | Description |
Sequence[CollectionReference] | iterator of subcollections of the current document. |
document
document(*document_path)
Get a reference to a document in a collection.
For a top-level document:
>>> client.document('collek/shun')
>>> # is the same as
>>> client.document('collek', 'shun')
For a document in a sub-collection:
>>> client.document('mydocs/doc/subcol/child')
>>> # is the same as
>>> client.document('mydocs', 'doc', 'subcol', 'child')
Documents in sub-collections can be nested deeper in a similar fashion.
Name | Description |
document_path |
Tuple[str, ...]
Can either be * A single |
Type | Description |
DocumentReference | A reference to a document in a collection. |
field_path
field_path(*field_names)
Create a field path from a list of nested field names.
A field path is a .
-delimited concatenation of the field
names. It is used to represent a nested field. For example,
in the data
data = {
'aa': {
'bb': {
'cc': 10,
},
},
}
the field path 'aa.bb.cc'
represents the data stored in
data['aa']['bb']['cc']
.
Name | Description |
field_names |
Tuple[str, ...]
The list of field names. |
Type | Description |
str | The ``.``-delimited field path. |
get_all
get_all(references, field_paths=None, transaction=None)
Retrieve a batch of documents.
.. note::
Documents returned by this method are not guaranteed to be
returned in the same order that they are given in references
.
.. note::
If multiple references
refer to the same document, the server
will only return one result.
See xref_field_path for more information on field paths.
If a transaction
is used and it already has write operations
added, this method cannot be used (i.e. read-after-write is not
allowed).
Name | Description |
references |
List[.DocumentReference, ...]
Iterable of document references to be retrieved. |
field_paths |
Optional[Iterable[str, ...]]
An iterable of field paths ( |
transaction |
Optional[Transaction] :Yields: *.DocumentSnapshot* -- The next document snapshot that fulfills the query, or :data:`None` if the document does not exist.
An existing transaction that these |
transaction
transaction(**kwargs)
Get a transaction that uses this client.
See xref_Transaction for more information on transactions and the constructor arguments.
Name | Description |
kwargs |
Dict[str, Any]
The keyword arguments (other than |
Type | Description |
Transaction | A transaction attached to this client. |
write_option
write_option(**kwargs)
Create a write option for write operations.
Write operations include xref_set, xref_update and xref_delete.
One of the following keyword arguments must be provided:
last_update_time
(google.protobuf.timestamp_pb2. Timestamp
): A timestamp. When set, the target document must exist and have been last updated at that time. Protobufupdate_time
timestamps are typically returned from methods that perform write operations as part of a "write result" protobuf or directly.exists
(bool
): Indicates if the document being modified should already exist.
Providing no argument would make the option have no effect (so
it is not allowed). Providing multiple would be an apparent
contradiction, since last_update_time
assumes that the
document was updated (it can't have been updated if it
doesn't exist) and exists
indicate that it is unknown if the
document exists or not.
Name | Description |
kwargs |
Dict[str, Any]
The keyword arguments described above. |
Type | Description |
TypeError | If anything other than exactly one argument is provided by the caller. |
Type | Description |
WriteOption | The option to be used to configure a write message. |