Skip to main content

Firestore Session Manager for Google ADK

Project description

PyPI Python Tests Python 3.11+ License: Apache 2.0

Google ADK Firestore Session

A specialized implementation of the BaseSessionService that uses Google Cloud Firestore for persisting application sessions, user states, and event logs.

Overview

This package provides the FirestoreSessionService class, which handles the lifecycle of sessions within the Google ADK (Agent Development Kit) framework. It organizes data in a hierarchical Firestore structure:

  • apps/{app_name}: Global application state.
  • apps/{app_name}/users/{user_id}: Persistent user-specific state.
  • apps/{app_name}/users/{user_id}/sessions/{session_id}: Individual session data and state.
  • apps/{app_name}/users/{user_id}/sessions/{session_id}/events/{event_id}: Historical event logs for the session.

Installation

Using pip

pip install google-adk-firestore-session

Using uv

uv add google-adk-firestore-session

Configuration

The FirestoreSessionService can be configured via constructor arguments, environment variables, or through the built-in ADK factory.

Precedence

  1. Constructor Arguments: Explicit project and database passed to the class.
  2. Environment Variables: GOOGLE_CLOUD_PROJECT and GOOGLE_DATABASE.
  3. Default Credentials: Standard Google Cloud application default credentials.

Usage with Google ADK

To use the FirestoreSessionService with Google ADK, register the provided factory with the ADK ServiceRegistry. This allows you to point your agents to Firestore using a simple URI.

1. Register the Service

In your main entry point (e.g., serving.py), import and register the factory.

from google.adk.cli.service_registry import get_service_registry
from firestore_session import firestore_session_service_factory

# Register the "firestore" scheme
get_service_registry().register_session_service(
    "firestore", 
    firestore_session_service_factory
)

2. Configure the ADK App

Pass the URI to get_fast_api_app. The URI format is firestore://[project-id]/[database-name].

from google.adk.cli.fast_api import get_fast_api_app

app = get_fast_api_app(
    agents_dir="path/to/agents",
    # Connect to a specific project and database instance
    session_service_uri="firestore://my-project-id/my-database", 
    web=True
)

Standalone Usage

from firestore_session import FirestoreSessionService

# Explicitly passing project/database
session_service = FirestoreSessionService(
    project="my-project-id",
    database="my-database"
)

# Or use environment variables (GOOGLE_CLOUD_PROJECT, etc.)
session_service = FirestoreSessionService()

Dependencies

  • google-adk: Core agent framework.
  • google-cloud-firestore: Official Firestore client.

Development

Running Tests

Tests use pytest. Ensure you have a Firestore emulator or a project configured for testing.

pytest tests/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

google_adk_firestore_session-0.1.6.tar.gz (173.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

google_adk_firestore_session-0.1.6-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file google_adk_firestore_session-0.1.6.tar.gz.

File metadata

File hashes

Hashes for google_adk_firestore_session-0.1.6.tar.gz
Algorithm Hash digest
SHA256 0aead7800f594149a0019c7419be081dad71f001fe26b5b23177522e3e3e1ceb
MD5 3ebfec7cf45b7be32c3d76dc8ec269d3
BLAKE2b-256 04a0b5b6dcb0e70db637337b9c918b2975a50fcd2a2c7e6c106d38e214bcd644

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_adk_firestore_session-0.1.6.tar.gz:

Publisher: release.yml on mohammadshamma/google-adk-firestore-session

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file google_adk_firestore_session-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for google_adk_firestore_session-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9c7418d57d95a6796b3fe6a14c511bfe8db686bd23ee3c83f68add215d2528b3
MD5 1e77ac7cf4cf9197c1cc90068a21b82d
BLAKE2b-256 7d2ee6534c7d12ebf51f3c3d24de37ea2057e3a4fd479d390ab1862c8ab46655

See more details on using hashes here.

Provenance

The following attestation bundles were made for google_adk_firestore_session-0.1.6-py3-none-any.whl:

Publisher: release.yml on mohammadshamma/google-adk-firestore-session

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page