### Prerequisites Setup Steps Source: https://context7.com/googleapis/python-firestore/llms.txt Steps to set up your Google Cloud project before using the Firestore client library. This includes project selection, billing enablement, API activation, and authentication setup. ```bash # 1. Select or create a Cloud Platform project # Visit: https://console.cloud.google.com/project # 2. Enable billing for your project # Visit: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project # 3. Enable the Cloud Firestore API # Visit: https://cloud.google.com/firestore # 4. Set up Authentication # Visit: https://googleapis.dev/python/google-api-core/latest/auth.html ``` -------------------------------- ### Install Firestore Client Library Source: https://github.com/googleapis/python-firestore/blob/main/README.rst Commands to create a virtual environment and install the google-cloud-firestore package. ```console python3 -m venv source /bin/activate pip install google-cloud-firestore ``` ```console py -m venv .\\Scripts\activate pip install google-cloud-firestore ``` -------------------------------- ### Install google-cloud-firestore Source: https://context7.com/googleapis/python-firestore/llms.txt Install the library in a virtual environment using pip. Ensure you activate your virtual environment before installation. ```bash # Mac/Linux python3 -m venv source /bin/activate pip install google-cloud-firestore # Windows py -m venv .\\Scripts\activate pip install google-cloud-firestore ``` -------------------------------- ### Configure Handler for All Google-Based Loggers (Python) Source: https://github.com/googleapis/python-firestore/blob/main/README.rst Configure a logging handler for all Google-based loggers programmatically. This involves getting the 'google' logger, adding a StreamHandler, and setting the logging level to DEBUG. ```python import logging from google.cloud import library_v1 base_logger = logging.getLogger("google") base_logger.addHandler(logging.StreamHandler()) base_logger.setLevel(logging.DEBUG) ``` -------------------------------- ### Update Firestore Database - Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Demonstrates updating a Firestore database using the FirestoreAdminClient. This example creates a client, initializes a request object, makes the update request, and prints the response. It requires the google-cloud-firestore-admin library to be installed. ```Python from google.cloud import firestore_admin_v1 def sample_update_database(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.UpdateDatabaseRequest() # Make the request operation = client.update_database(request=request) print("Waiting for operation to complete...") response = operation.result() # Handle the response print(response) ``` -------------------------------- ### Get Firestore Field - Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Demonstrates how to retrieve a single field from Firestore database using the Admin Client. The example shows client initialization, request setup with field name, and response handling. Requires valid project and field identifiers in the name parameter. ```python # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import firestore_admin_v1 def sample_get_field(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.GetFieldRequest( name="name_value", ) # Make the request response = client.get_field(request=request) # Handle the response print(response) ``` -------------------------------- ### GET /v1/{parent}/databases Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Lists all databases in the specified project. Provides information about each database's configuration and state. ```APIDOC ## GET /v1/{parent}/databases ### Description Lists all databases in the specified project. Provides information about each database's configuration and state. ### Method GET ### Endpoint /v1/{parent}/databases ### Parameters #### Path Parameters - **parent** (string) - Required - The project to list databases from. Format is `projects/{project}` #### Query Parameters - **retry** (Retry) - Optional - Designation of what errors should be retried - **timeout** (float) - Optional - The timeout for this request - **metadata** (Sequence[Tuple[str, str|bytes]]) - Optional - Additional metadata to send with the request ### Request Example { "parent": "projects/my-project" } ### Response #### Success Response (200) - **databases** (ListDatabase) - List of database resources #### Response Example { "databases": [ { "name": "projects/my-project/databases/(default)", "type": "FIRESTORE_NATIVE", "concurrencyMode": "OPTIMISTIC" } ] } ``` -------------------------------- ### Create Firestore Index - Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md This code snippet demonstrates how to create a Firestore index using the Google Cloud Python client library. The example initializes a FirestoreAdminClient, constructs a CreateIndexRequest, and then calls the create_index method to create the index. It then waits for the operation to complete and prints the response. ```Python from google.cloud import firestore_admin_v1 def sample_create_index(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.CreateIndexRequest( parent="parent_value", ) # Make the request operation = client.create_index(request=request) print("Waiting for operation to complete...") response = operation.result() # Handle the response print(response) ``` -------------------------------- ### GET /v1/{parent=projects/*/databases/*/backupSchedules/*} Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Lists all backup schedules for a given Firestore database. This allows you to review existing backup configurations. ```APIDOC ## GET /v1/{parent=projects/*/databases/*/backupSchedules/*} ### Description Lists all backup schedules for a given Firestore database. This allows you to review existing backup configurations. ### Method GET ### Endpoint `/v1/{parent=projects/*/databases/*/backupSchedules/*}` ### Parameters #### Path Parameters - **parent** (string) - Required - The database name. Should be of the form: `projects/{project_id}/databases/{database_id}`. #### Query Parameters None #### Request Body None ### Request Example ``` (No request body for GET request) ``` ### Response #### Success Response (200) - **backup_schedules** (array of objects) - A list of backup schedule resources. - **name** (string) - The unique identifier for the backup schedule. - **retention** (string) - The retention period for the backups. - **start_time** (object) - The time the backup schedule starts. - **seconds** (integer) - Seconds part of the timestamp. - **nanos** (integer) - Nanoseconds part of the timestamp. #### Response Example ```json { "backupSchedules": [ { "name": "projects/your-project-id/databases/(default)/backupSchedules/your-schedule-id", "retention": "7d", "startTime": { "seconds": 1678886400, "nanos": 0 } } ] } ``` ``` -------------------------------- ### GET /v1/{parent}/backups Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Lists all backups for a given project and location. Can list backups from a single location or all locations. ```APIDOC ## GET /v1/{parent}/backups ### Description Lists all backups for a given project and location. Can list backups from a single location or all locations. ### Method GET ### Endpoint /v1/{parent}/backups ### Parameters #### Path Parameters - **parent** (string) - Required - The location to list backups from. Format is `projects/{project}/locations/{location}`. Use `{location} = '-'` to list backups from all locations. #### Query Parameters - **retry** (Retry) - Optional - Designation of what errors should be retried - **timeout** (float) - Optional - The timeout for this request - **metadata** (Sequence[Tuple[str, str|bytes]]) - Optional - Additional metadata to send with the request ### Request Example { "parent": "projects/my-project/locations/us-central1" } ### Response #### Success Response (200) - **backups** (ListBackup) - List of backup resources #### Response Example { "backups": [ { "name": "projects/my-project/locations/us-central1/backups/backup-1", "database": "projects/my-project/databases/(default)", "state": "READY" } ] } ``` -------------------------------- ### Get Backup Schedule from Firestore Admin API Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Retrieves a backup schedule for a Cloud Firestore Database using the Firestore Admin API. The backup schedule is owned by the database it backs up and gets deleted when the database is deleted. Requires a properly formatted name parameter in the format 'projects/{project}/databases/{database}/backupSchedules/{backup_schedule}'. ```python from google.cloud import firestore_admin_v1 def sample_get_backup_schedule(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.GetBackupScheduleRequest( name="name_value", ) # Make the request response = client.get_backup_schedule(request=request) # Handle the response print(response) ``` -------------------------------- ### Get Backup in Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Retrieves information about a backup in Firestore. This function requires the Firestore Admin Client to be initialized and a valid request object. Ensure proper error handling and regional endpoint configuration. ```Python from google.cloud import firestore_admin_v1 def sample_get_backup(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.GetBackupRequest( name="name_value", ) # Make the request response = client.get_backup(request=request) # Handle the response print(response) ``` -------------------------------- ### Get Mutual TLS Endpoint in Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md This snippet shows how to get the mutual TLS endpoint and client certificate source for the Firestore Admin Client. It checks environment variables and client options to determine the appropriate endpoint and cert source. ```python @classmethod def get_mtls_endpoint_and_cert_source(client_options: ClientOptions | None = None): """ Deprecated. Return the API endpoint and client cert source for mutual TLS. The client cert source is determined in the following order: (1) if GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable is not "true", the client cert source is None. (2) if client_options.client_cert_source is provided, use the provided one; if the default client cert source exists, use the default one; otherwise the client cert source is None. The API endpoint is determined in the following order: (1) if client_options.api_endpoint if provided, use the provided one. (2) if GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable is "always", use the default mTLS endpoint; if the environment variable is "never", use the default API endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise use the default API endpoint. More details can be found at https://google.aip.dev/auth/4114. Args: client_options (google.api_core.client_options.ClientOptions): Custom options for the client. Only the api_endpoint and client_cert_source properties may be used in this method. Returns: Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the client cert source to use. Raises: google.auth.exceptions.MutualTLSChannelError: If any errors happen. """ ``` -------------------------------- ### List Firestore Indexes in Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md This Python code sample demonstrates how to list indexes in a Firestore collection group using the Google Cloud Firestore Admin API. It requires the google-cloud-firestore library and valid project credentials. The function takes a parent parameter specifying the collection group and returns an iterator over index responses; note that it assumes a simple setup and may need error handling in production. ```python # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import firestore_admin_v1 def sample_list_indexes(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.ListIndexesRequest( parent="parent_value", ) # Make the request page_result = client.list_indexes(request=request) # Handle the response for response in page_result: print(response) ``` -------------------------------- ### GET /userCreds Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Retrieves user credentials from Firestore. Requires project, database, and user credentials ID. ```APIDOC ## GET /userCreds ### Description Retrieves user credentials from a Firestore database. ### Method GET ### Endpoint `projects/{project_id}/databases/{database_id}/userCreds/{user_creds_id}` ### Parameters #### Path Parameters - **project_id** (string) - Required - The Google Cloud project ID - **database_id** (string) - Required - The Firestore database ID - **user_creds_id** (string) - Required - The user credentials ID #### Query Parameters - **retry** (Retry) - Optional - Error retry configuration - **timeout** (float) - Optional - Request timeout in seconds - **metadata** (Sequence[Tuple[str, str|bytes]]) - Optional - Additional metadata ### Request Example ```python request = firestore_admin_v1.GetUserCredsRequest( name="projects/my-project/databases/default/userCreds/user-123" ) ``` ### Response #### Success Response (200) - Returns: UserCreds object containing the credentials #### Response Example ```python { "name": "projects/my-project/databases/default/userCreds/user-123", "credentials": { "type": "service_account", "client_email": "user@project.iam.gserviceaccount.com" } } ``` ``` -------------------------------- ### GET /userCreds/{name} Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Gets a user credentials resource. Note that the returned resource does not contain the secret value itself, only metadata about the credentials. ```APIDOC ## GET /userCreds/{name} ### Description Gets a user credentials resource. Note that the returned resource does not contain the secret value itself, only metadata about the credentials. ### Method GET ### Endpoint /userCreds/{name} ### Parameters #### Path Parameters - **name** (string) - Required - The resource name of the user creds #### Query Parameters - **timeout** (float) - Optional - The timeout for this request #### Request Body No request body required ### Request Example ``` GET /userCreds/user123?timeout=30 ``` ### Response #### Success Response (200) - **name** (string) - The resource name of the user creds - **create_time** (string) - The creation time of the credentials - **update_time** (string) - The last update time of the credentials - **state** (string) - The current state of the credentials #### Response Example { "name": "userCreds/user123", "create_time": "2023-01-01T00:00:00Z", "update_time": "2023-01-01T00:00:00Z", "state": "ACTIVE" } ``` -------------------------------- ### Get Firestore Database Information Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Retrieves metadata and configuration for a Firestore database. Requires a properly formatted database name in the format 'projects/{project_id}/databases/{database_id}'. The function returns a Cloud Firestore Database object with the database configuration details. ```python from google.cloud import firestore_admin_v1 def sample_get_database(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.GetDatabaseRequest( name="name_value", ) # Make the request response = client.get_database(request=request) # Handle the response print(response) ``` -------------------------------- ### GET /v1/{parent}/fields Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Lists all fields for a given collection group in a Firestore database. ```APIDOC ## GET /v1/{parent}/fields ### Description Lists all fields for a given collection group in a Firestore database. ### Method GET ### Endpoint /v1/{parent}/fields ### Parameters #### Path Parameters - **parent** (string) - Required - A parent name of the form `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}` #### Query Parameters - **retry** (Retry) - Optional - Designation of what errors, if any, should be retried. - **timeout** (float) - Optional - The timeout for this request. - **metadata** (Sequence[Tuple[str, str | bytes]]) - Optional - Key/value pairs which should be sent along with the request as metadata. ### Response #### Success Response (200) - Returns an iterable of Field objects #### Response Example { "fields": [ { "name": "projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/fields/{field_id}", "indexConfig": { "indexes": [] } } ] } ``` -------------------------------- ### GET /v1/{parent}/indexes Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Lists composite indexes for a given collection group in a Firestore database. ```APIDOC ## GET /v1/{parent}/indexes ### Description Lists composite indexes for a given collection group in a Firestore database. ### Method GET ### Endpoint /v1/{parent}/indexes ### Parameters #### Path Parameters - **parent** (string) - Required - A parent name of the form `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}` #### Query Parameters - **retry** (Retry) - Optional - Designation of what errors, if any, should be retried. - **timeout** (float) - Optional - The timeout for this request. - **metadata** (Sequence[Tuple[str, str | bytes]]) - Optional - Key/value pairs which should be sent along with the request as metadata. ### Response #### Success Response (200) - Returns an iterable of Index objects #### Response Example { "indexes": [ { "name": "projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/indexes/{index_id}", "queryScope": "COLLECTION", "fields": [ { "fieldPath": "field_name", "order": "ASCENDING" } ] } ] } ``` -------------------------------- ### GET Index Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Retrieves details about a specific composite index in a Firestore database. ```APIDOC ## GET /v1/{name=projects/*/databases/*/collectionGroups/*/indexes/*} ### Description Retrieves configuration details for a specific composite index in Firestore. ### Method GET ### Endpoint `/v1/{name=projects/*/databases/*/collectionGroups/*/indexes/*}` ### Parameters #### Path Parameters - **name** (string) - Required - Resource name in format `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/indexes/{index_id}` #### Query Parameters - **retry** (Retry) - Optional - Retry configuration for the request - **timeout** (float) - Optional - Request timeout in seconds - **metadata** (Sequence[Tuple[str, str|bytes]]) - Optional - Additional metadata for the request ### Response #### Success Response (200) - Returns an Index object containing the index configuration details #### Response Example { "name": "projects/example-project/databases/(default)/collectionGroups/example-group/indexes/example-index", "queryScope": "COLLECTION", "fields": [ { "fieldPath": "field1", "order": "ASCENDING" } ] } ``` -------------------------------- ### Bulk Delete Documents - Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md This code snippet demonstrates how to bulk delete documents in Firestore using the Firestore Admin API in Python. It initializes a FirestoreAdminClient, constructs a BulkDeleteDocumentsRequest, and handles the resulting operation. This example provides a basic workflow for document deletion. ```python from google.cloud import firestore_admin_v1 def sample_bulk_delete_documents(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.BulkDeleteDocumentsRequest( name="name_value", ) # Make the request operation = client.bulk_delete_documents(request=request) print("Waiting for operation to complete...") response = operation.result() # Handle the response print(response) ``` -------------------------------- ### Get Database Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Retrieves information about a specific Cloud Firestore database. This is useful for inspecting the configuration and status of a database. ```APIDOC ## GET /v1/{name=projects/*/databases/*} ### Description Gets information about a database. This resource is owned by the project it is associated with. ### Method GET ### Endpoint `projects/{project}/databases/{database}` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the database to get. Format: `projects/{project}/databases/{database}` #### Query Parameters None #### Request Body None ### Request Example ```json { "name": "projects/your-project/databases/(default)" } ``` ### Response #### Success Response (200) - **name** (string) - The unique identifier for the database. - **location_id** (string) - The location of the database. - **type** (string) - The type of the database (e.g., `firestore-native`). - **create_time** (object) - The timestamp when the database was created. - **seconds** (integer) - Seconds part of the timestamp. - **nanos** (integer) - Nanoseconds part of the timestamp. - **update_time** (object) - The timestamp when the database was last updated. - **seconds** (integer) - Seconds part of the timestamp. - **nanos** (integer) - Nanoseconds part of the timestamp. #### Response Example ```json { "name": "projects/your-project/databases/(default)", "locationId": "us-central", "type": "firestore-native", "createTime": { "seconds": 1678886400, "nanos": 0 }, "updateTime": { "seconds": 1678886400, "nanos": 0 } } ``` ``` -------------------------------- ### GET Field Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Retrieves details about a specific field in a Firestore database collection group. ```APIDOC ## GET /v1/{name=projects/*/databases/*/collectionGroups/*/fields/*} ### Description Retrieves a specific field configuration from a Firestore collection group. ### Method GET ### Endpoint `/v1/{name=projects/*/databases/*/collectionGroups/*/fields/*}` ### Parameters #### Path Parameters - **name** (string) - Required - Resource name in format `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/fields/{field_id}` #### Query Parameters - **retry** (Retry) - Optional - Retry configuration for the request - **timeout** (float) - Optional - Request timeout in seconds - **metadata** (Sequence[Tuple[str, str|bytes]]) - Optional - Additional metadata for the request ### Response #### Success Response (200) - Returns a Field object containing the field configuration details #### Response Example { "name": "projects/example-project/databases/(default)/collectionGroups/example-group/fields/example-field", "indexConfig": { "indexes": [] } } ``` -------------------------------- ### Get Backup Schedule in Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Retrieves information about a backup schedule in Firestore. Requires the Firestore Admin Client and a valid request object. Remember to handle potential errors and configure regional endpoints. ```Python # This snippet has been automatically generated and should be regarded as a # code template only. # It will require modifications to work: # - It may require correct/in-range values for request initialization. ``` -------------------------------- ### GET /v1/projects/{project_id}/databases/{database_id} Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Retrieves a Cloud Firestore database's metadata via the Firestore Admin API. This endpoint returns the configuration and metadata for the specified database. ```APIDOC ## [GET] /v1/projects/{project_id}/databases/{database_id}\n\n### Description\nRetrieves a Cloud Firestore database metadata via the Firestore Admin API. This endpoint returns the configuration and metadata for the specified database.\n\n### Method\nGET\n\n### Endpoint\n/v1/projects/{project_id}/databases/{database_id}\n\n### Parameters\n#### Path Parameters\n- **name** (string) - Required - The resource name of the database. Format: projects/{project_id}/databases/{database_id}\n\n#### Query Parameters\n- **retry** (Retry) - Optional - Designation of retry behavior.\n- **timeout** (float) - Optional - Timeout for the request.\n- **metadata** (Sequence[Tuple[str, Union[str, bytes]]]) - Optional - Metadata to send with request.\n\n### Request Body\n- None for GET\n\n### Request Example\n{\n \"name\": \"projects/my-project/databases/(default)\"\n}\n\n### Response\n#### Success Response (200)\n- **name** (string) - Resource name of the database\n- **location_id** (string) - Location/region where the database is hosted\n\n#### Response Example\n{\n \"name\": \"projects/my-project/databases/(default)\",\n \"location_id\": \"us-central\"\n}\n ``` -------------------------------- ### Get Backup Schedule Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Retrieves the backup schedule for a Cloud Firestore database. This operation is useful for understanding the backup configuration of a database. ```APIDOC ## GET /v1/projects/{project}/databases/{database}/backupSchedules/{backup_schedule} ### Description Retrieves the backup schedule for a Cloud Firestore database. This resource is owned by the database it is backing up and is deleted along with the database, but the actual backups are not. ### Method GET ### Endpoint `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the backup schedule. Format: `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}` #### Query Parameters None #### Request Body None ### Request Example ```json { "name": "projects/your-project/databases/(default)/backupSchedules/your-backup-schedule" } ``` ### Response #### Success Response (200) - **name** (string) - The unique identifier for the backup schedule. - **retention_policy** (object) - The retention policy for the backup schedule. - **max_retention_days** (integer) - The maximum number of days to retain backups. - **keep_only_latest_period** (string) - The duration for which to keep only the latest backups. - **daily_schedule** (object) - The daily backup schedule. - **start_time** (object) - The start time for daily backups. - **hours** (integer) - Hours part of the time (0-23). - **minutes** (integer) - Minutes part of the time (0-59). - **seconds** (integer) - Seconds part of the time (0-59). - **nanos** (integer) - Nanoseconds part of the time (0-999,999,999). #### Response Example ```json { "name": "projects/your-project/databases/(default)/backupSchedules/your-backup-schedule", "retentionPolicy": { "maxRetentionDays": 30, "keepOnlyLatestPeriod": "7d" }, "dailySchedule": { "startTime": { "hours": 3, "minutes": 0, "seconds": 0, "nanos": 0 } } } ``` ``` -------------------------------- ### Reset User Password - Python Firestore Admin API Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Demonstrates how to reset a user password using the Firestore Admin client. The code creates a client, initializes a ResetUserPasswordRequest with the required name parameter, and makes the API call to reset the password. The example shows proper client initialization and request handling with response printing. ```python # This snippet has been automatically generated and should be regarded as a # code template only. # It will require modifications to work: # - It may require correct/in-range values for request initialization. # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import firestore_admin_v1 def sample_reset_user_password(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.ResetUserPasswordRequest( name="name_value", ) # Make the request response = client.reset_user_password(request=request) # Handle the response print(response) ``` -------------------------------- ### Export Firestore Documents using Python FirestoreAdminClient Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md The snippet defines a Python function that exports all documents from a Firestore database. It creates a FirestoreAdminClient, constructs an ExportDocumentsRequest with the required database name, starts the long‑running export operation, waits for it to finish, and prints the response. Dependencies include the google‑cloud‑firestore‑admin library and appropriate service‑account credentials. ```Python from google.cloud import firestore_admin_v1 def sample_export_documents(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.ExportDocumentsRequest( name="name_value", ) # Make the request operation = client.export_documents(request=request) print("Waiting for operation to complete...") response = operation.result() # Handle the response print(response) ``` -------------------------------- ### GET /v1/projects/{project_id}/databases/{database_id}/fields/{field_path} Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Retrieves metadata for a specific Field within a Firestore database using the GetField endpoint. ```APIDOC ## [GET] /v1/projects/{project_id}/databases/{database_id}/fields/{field_path}\n\n### Description\nGets the metadata and configuration for a Field.\n\n### Method\nGET\n\n### Endpoint\n/v1/projects/{project_id}/databases/{database_id}/fields/{field_path}\n\n### Parameters\n#### Path Parameters\n- **name** (string) - Required - The resource name of the Field. Example: projects/{project_id}/databases/{database_id}/fields/{field_path}\n\n#### Query Parameters\n- **retry** (Retry) - Optional\n- **timeout** (float) - Optional\n- **metadata** (Sequence[Tuple[str, Union[str, bytes]]]) - Optional\n\n### Request Body\n- None for GET\n\n### Request Example\n{\n \"name\": \"projects/my-project/databases/(default)/fields/title\"\n}\n\n### Response\n#### Success Response (200)\n- **name** (string) - Resource name of the Field\n- **index_config** (object) - Index configuration for the field\n\n#### Response Example\n{\n \"name\": \"projects/my-project/databases/(default)/fields/title\",\n \"index_config\": {}\n}\n ``` -------------------------------- ### Configure Firestore Logging via Environment Variables Source: https://context7.com/googleapis/python-firestore/llms.txt Enable logging for debugging and monitoring by setting environment variables. This approach is useful for quick configuration without code changes. ```bash # Enable default handler for all Google-based loggers export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google # Enable default handler for a specific Google module (e.g., firestore) export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.firestore_v1 ``` -------------------------------- ### Configure Handler for Specific Google Module (Python) Source: https://github.com/googleapis/python-firestore/blob/main/README.rst Configure a logging handler for a specific Google module, such as 'google.cloud.library_v1', using Python's logging module. This ensures logging events for that module are handled. ```python import logging from google.cloud import library_v1 base_logger = logging.getLogger("google.cloud.library_v1") base_logger.addHandler(logging.StreamHandler()) base_logger.setLevel(logging.DEBUG) ``` -------------------------------- ### GET /operations/{operation_id} Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Gets the latest state of a long-running operation. This endpoint is used to check the status of asynchronous operations in Firestore. ```APIDOC ## GET /operations/{operation_id} ### Description Gets the latest state of a long-running operation. This endpoint is used to check the status of asynchronous operations in Firestore. ### Method GET ### Endpoint /operations/{operation_id} ### Parameters #### Path Parameters - **operation_id** (string) - Required - The ID of the operation to retrieve #### Query Parameters - **timeout** (float) - Optional - The timeout for this request #### Request Body No request body required ### Request Example ``` GET /operations/12345?timeout=30 ``` ### Response #### Success Response (200) - **name** (string) - The server-assigned name of the operation - **metadata** (object) - Service-specific metadata associated with the operation - **done** (boolean) - If the value is false, it means the operation is still in progress - **error** (object) - The error result of the operation if it failed - **response** (object) - The normal response of the operation if it succeeded #### Response Example { "name": "operations/12345", "metadata": {}, "done": true, "response": {} } ``` -------------------------------- ### Enable Default Handler for Specific Google Module (Console) Source: https://github.com/googleapis/python-firestore/blob/main/README.rst Set the GOOGLE_SDK_PYTHON_LOGGING_SCOPE environment variable to a specific Google module path, like 'google.cloud.library_v1', to enable the default logging handler for that module. ```console export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.library_v1 ``` -------------------------------- ### Configure Firestore Logging Programmatically Source: https://context7.com/googleapis/python-firestore/llms.txt Configure logging using Python's standard logging mechanism for fine-grained control over handlers and log levels. This method allows for dynamic configuration within your application. ```python import logging from google.cloud import firestore # Configure handler for all Google-based loggers base_logger = logging.getLogger("google") base_logger.addHandler(logging.StreamHandler()) base_logger.setLevel(logging.DEBUG) # Or configure handler for firestore module specifically firestore_logger = logging.getLogger("google.cloud.firestore_v1") firestore_logger.addHandler(logging.StreamHandler()) firestore_logger.setLevel(logging.DEBUG) # Enable propagation to root logger if needed logging.getLogger("google").propagate = True ``` -------------------------------- ### Enable Default Handler for All Google Loggers (Console) Source: https://github.com/googleapis/python-firestore/blob/main/README.rst Set the GOOGLE_SDK_PYTHON_LOGGING_SCOPE environment variable to 'google' to enable the default logging handler for all Google-based loggers. This configures logging events at DEBUG level or higher. ```console export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google ``` -------------------------------- ### Create Firestore Database - Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Demonstrates how to create a new Firestore database using the FirestoreAdminClient. This function initializes a client, defines the request with parent and database ID, and initiates the creation operation. It then waits for the operation to complete and prints the response. ```python from google.cloud import firestore_admin_v1 def sample_create_database(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.CreateDatabaseRequest( parent="parent_value", database_id="database_id_value", ) # Make the request operation = client.create_database(request=request) print("Waiting for operation to complete...") response = operation.result() # Handle the response print(response) ``` -------------------------------- ### Create User Creds Sample in Python Firestore Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md This Python function sample demonstrates creating user credentials via the Firestore Admin API. It depends on the google-cloud-firestore package and requires valid project and database IDs as inputs. The output is a UserCreds object, but the sample limits to printing the response; no retries or timeouts are set here, making it a basic template. ```python # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import firestore_admin_v1 def sample_create_user_creds(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.CreateUserCredsRequest( parent="parent_value", user_creds_id="user_creds_id_value", ) # Make the request response = client.create_user_creds(request=request) # Handle the response print(response) ``` -------------------------------- ### List Firestore Databases in Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Demonstrates how to list all Firestore databases for a project using the Firestore Admin API. Requires google-cloud-firestore package. Takes a parent project ID as input and returns a list of databases. ```python from google.cloud import firestore_admin_v1 def sample_list_databases(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.ListDatabasesRequest( parent="parent_value", ) # Make the request response = client.list_databases(request=request) # Handle the response print(response) ``` -------------------------------- ### List Firestore Backups in Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Demonstrates how to list backups from a Firestore database using the Firestore Admin API. Requires a parent project and location. Handles the response by printing it. ```python from google.cloud import firestore_admin_v1 def sample_list_backups(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.ListBackupsRequest( parent="parent_value", ) # Make the request response = client.list_backups(request=request) # Handle the response print(response) ``` -------------------------------- ### Create Backup Schedule in Firestore using Python Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md This code demonstrates how to create a backup schedule for a Firestore database using the FirestoreAdminClient. It requires the google-cloud-firestore-admin-v1 library and initializes a request with a parent resource. The method returns a BackupSchedule object, with options for retry, timeout, and metadata; note that actual implementation needs valid parent values and may require regional endpoints. ```python from google.cloud import firestore_admin_v1 def sample_create_backup_schedule(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.CreateBackupScheduleRequest( parent="parent_value", ) # Make the request response = client.create_backup_schedule(request=request) # Handle the response print(response) ``` -------------------------------- ### List backup schedules with FirestoreAdminClient (Python) Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Demonstrates how to list backup schedules using FirestoreAdminClient. It creates a client, builds a ListBackupSchedulesRequest with a parent identifier, calls list_backup_schedules, and prints the response. Requires the google-cloud-firestore library. ```python from google.cloud import firestore_admin_v1 def sample_list_backup_schedules(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.ListBackupSchedulesRequest( parent="parent_value", ) # Make the request response = client.list_backup_schedules(request=request) # Handle the response print(response) ``` -------------------------------- ### POST /v1/projects/{project}/databases:list Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md This endpoint lists all Firestore databases across locations for a specified project. It allows administrators to retrieve database metadata and configurations. Use this to inventory project databases programmatically. ```APIDOC ## POST /v1/projects/{project}/databases:list ### Description Lists the Firestore Databases in all locations for a project. This method retrieves database details such as their names and statuses. ### Method POST ### Endpoint /v1/projects/{project}/databases:list ### Parameters #### Path Parameters - **project** (string) - Required - The ID of the project to list databases for, in the form projects/{project_id}. #### Request Body - No specific request body fields; the request object can include additional configurations if passed. ### Request Example { "parent": "projects/my-project" } ### Response #### Success Response (200) - **databases** (array) - List of database objects, each containing details like name and location. - **next_page_token** (string) - Token for paging through results if more databases exist. #### Response Example { "databases": [ { "name": "projects/my-project/databases/(default)", "locationId": "us-central1" } ] } #### Error Responses - 400 Bad Request: Invalid project ID. - 403 Forbidden: Insufficient permissions. - 500 Internal Server Error: Server-side issues. ``` -------------------------------- ### Path Utilities Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Utility methods for constructing and parsing resource paths for Firestore Admin API resources. ```APIDOC ## Utility Methods ### `location_path(project: str, location: str) -> str` Returns a fully-qualified location string. ### `operation_path(project: str, database: str, operation: str) -> str` Returns a fully-qualified operation string. ### `parse_backup_path(path: str) -> Dict[str, str]` Parses a backup path into its component segments. ### `parse_backup_schedule_path(path: str) -> Dict[str, str]` Parses a backup_schedule path into its component segments. ``` -------------------------------- ### POST create_backup_schedule Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Creates a backup schedule on a Firestore database. At most two backup schedules can be configured on a database, one daily backup schedule and one weekly backup schedule. ```APIDOC ## POST create_backup_schedule ### Description Creates a backup schedule on a database. At most two backup schedules can be configured on a database, one daily backup schedule and one weekly backup schedule. ### Method POST ### Endpoint create_backup_schedule ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **request** (CreateBackupScheduleRequest | dict | None) - Optional - The request object containing the parameters for creating a backup schedule - **parent** (str | None) - Optional - The parent resource where the backup schedule will be created - **backup_schedule** (BackupSchedule | None) - Optional - The BackupSchedule resource to create - **retry** (Retry | _MethodDefault | None) - Optional - The retry strategy to use when calling the API - **timeout** (float | object | None) - Optional - The timeout to use when calling the API - **metadata** (Sequence[Tuple[str, str | bytes]]) - Optional - Additional metadata to send with the API call ### Request Example { "request": null, "parent": "projects/{project_id}/databases/{database_id}", "backup_schedule": { "name": "backup-schedule-name", "recurrence": "DAILY" }, "retry": null, "timeout": null, "metadata": [] } ### Response #### Success Response (200) - **BackupSchedule** (object) - The created BackupSchedule resource #### Response Example { "name": "projects/{project_id}/databases/{database_id}/backupSchedules/{backup_schedule_id}", "recurrence": "DAILY", "retentionDuration": "86400s" } ``` -------------------------------- ### Enable User Creds with Firestore Admin API (Python) Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md This code snippet demonstrates how to enable user credentials using the Google Cloud Firestore Admin API with Python. It uses the `firestore_admin_v1` module to create a client, construct a request, and invoke the `enable_user_creds` method. The result of the operation is then printed to the console. ```python from google.cloud import firestore_admin_v1 def sample_enable_user_creds(): # Create a client client = firestore_admin_v1.FirestoreAdminClient() # Initialize request argument(s) request = firestore_admin_v1.EnableUserCredsRequest( name="name_value", ) # Make the request response = client.enable_user_creds(request=request) # Handle the response print(response) ``` -------------------------------- ### POST /firestore.v1.documents:bulk_delete_documents Source: https://github.com/googleapis/python-firestore/blob/main/docs/firestore_admin_v1/admin_client.md Bulk deletes a subset of documents from Google Cloud Firestore. Documents created or updated after the underlying system starts to process the request will not be deleted. The bulk delete occurs in the background. ```APIDOC ## POST /firestore.v1.documents:bulk_delete_documents ### Description Bulk deletes a subset of documents from Google Cloud Firestore. Documents created or updated after the underlying system starts to process the request will not be deleted. The bulk delete occurs in the background and its progress can be monitored and managed via the Operation resource that is created. ### Method POST ### Endpoint /firestore.v1.documents:bulk_delete_documents ### Parameters #### Request Body - `request` (BulkDeleteDocumentsRequest) - Required - The request body. - `name` (str) - Optional - The name of the resource to delete. #### Query Parameters None #### Path Parameters None ### Request Example { "request": { "documents": [ "projects/project-id/databases/(default)/documents/path/to/document1", "projects/project-id/databases/(default)/documents/path/to/document2" ] } } ### Response #### Success Response (200) - `Operation` - The Operation resource. #### Response Example { "name": "projects/project-id/operations/operation-id", "done": true, "result": { "operationType": "DELETE_DOCUMENTS", "targetId": "projects/project-id/databases/(default)/documents/path/to/document1" } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.