Cloud Firestore Python Client

repository·main·Indexed 42 days ago

https://github.com/googleapis/python-firestore

A Python client library for interacting with Cloud Firestore, a fully-managed NoSQL document database. It provides strongly consistent data access and integrates with the Google Cloud and Firebase ecosystems. Supports Python >= 3.7.

Tokens
812
Snippets
3
Records
5
Agent score
4%

What's inside Cloud Firestore

  1. Configure logging for the Firestore client

    main

    The library uses standard Python logging to log RPC events. By default, logging events are not handled and must be explicitly configured.

    Important Notes:

    • Logs may contain sensitive information; restrict access if saving logs.
    • Do not depend on the immutability of log messages or levels.
    • By default, logging events do not propagate to the root logger. To enable propagation, set logging.getLogger("google").propagate = True.
  2. Install the Cloud Firestore Python client

    main

    Install the google-cloud-firestore library within a virtual environment to avoid dependency conflicts.

    Supported Python Versions:

    • Python >= 3.7 (including 3.14)
    • Python <= 3.6 is unsupported.

    Note: This repository is archived. The project has moved to google-cloud-python.

    ### Mac/Linux
    python3 -m venv <your-env>
    source <your-env>/bin/activate
    pip install google-cloud-firestore
    
    ### Windows
    py -m venv <your-env>
    .\<your-env>\Scripts\activate
    pip install google-cloud-firestore
  3. Enable logging via environment variables

    main

    You can enable logging without changing your code by setting the GOOGLE_SDK_PYTHON_LOGGING_SCOPE environment variable. This configures a default handler for events at logging.DEBUG or higher, emitting them in a structured format.

    A logging scope is a period-separated namespace starting with google (e.g., google, google.cloud.firestore).

    # Enabling the default handler for all Google-based loggers
    export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google
    
    # Enabling the default handler for a specific Google module
    export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.library_v1
  4. Configure logging via Python code

    main

    Use Python's standard logging module to configure handlers for specific Google modules or the entire google namespace.

    import logging
    from google.cloud import library_v1
    
    # Configuring a handler for all Google-based loggers
    base_logger = logging.getLogger("google")
    base_logger.addHandler(logging.StreamHandler())
    base_logger.setLevel(logging.DEBUG)
    
    # Configuring a handler for a specific Google module
    module_logger = logging.getLogger("google.cloud.library_v1")
    module_logger.addHandler(logging.StreamHandler())
    module_logger.setLevel(logging.DEBUG)