Install via pip
pip is the only supported package manager. Install the latest stable release with:Optional extras
| Extra | Installs | When to use |
|---|---|---|
emulator | google-cloud-firestore-emulator | Local development and CI against the Firestore emulator |
dev | black, ruff, pytest, pytest-asyncio, httpx | Contributing to the library itself |
Python Version Requirements
Firestore Pydantic ODM requires Python 3.8 or later. The test matrix covers Python 3.9 through 3.12 on every release. Python 3.8 is supported by the install configuration but not included in the CI matrix.The library relies on
async/await, typing.ClassVar, typing.Optional, and typing.AsyncGenerator—all of which are available from Python 3.8 onwards.Dependencies
The following packages are installed automatically when you runpip install firestore-pydantic-odm:
| Package | Required version | Purpose |
|---|---|---|
pydantic | >=1.5, <3.0.0 | Model definition, validation, and serialization |
google-cloud-firestore | >=2.11.0 | Async Firestore client; FieldFilter requires ≥ 2.11.0 |
packaging | latest | Runtime Pydantic version detection via packaging.version |
Google Cloud Credentials
Production and staging
Firestore Pydantic ODM delegates all authentication to the Google Cloud client libraries, which follow the Application Default Credentials (ADC) resolution chain:-
GOOGLE_APPLICATION_CREDENTIALSenvironment variable — set this to the absolute path of a service-account JSON key file: -
gclouduser credentials — rungcloud auth application-default loginon a developer machine to store user credentials that the library will pick up automatically. - Attached service account — when running on Google Cloud infrastructure (Cloud Run, GKE, Cloud Functions, App Engine, Compute Engine), the metadata server provides credentials without any additional setup.
credentials object directly to FirestoreDB:
Firestore emulator
For local development and CI, the Firestore emulator lets you run a full Firestore instance on your machine without a network connection or a real GCP project. Option 1 — environment variable (recommended for CI):FirestoreDB automatically routes all traffic to the emulator.
Option 2 — emulator_host= constructor argument:
emulator_host= sets FIRESTORE_EMULATOR_HOST in the process environment automatically, so subsequent client creations in the same process also point to the emulator.
Option 3 — use_emulator() at runtime:
db.clear_emulator() to switch back to the production endpoint.
Pydantic Version Compatibility
Both Pydantic v1 and Pydantic v2 are fully supported. The library ships an internalpydantic_compat module that inspects pydantic.VERSION at import time using packaging.version.Version and selects the correct shims automatically.
| Pydantic version | Supported | Notes |
|---|---|---|
v1 (>=1.5, <2.0) | ✅ Yes | Config class, __fields__, .dict() |
v2 (>=2.0, <3.0) | ✅ Yes | model_config, model_fields, .model_dump() |
model_dumpvs.dict()model_fieldsvs__fields__ConfigDictvs innerConfigclassPrivateAttrdeclaration differences
When running Pydantic v2, the library automatically sets
model_config = ConfigDict(populate_by_name=True) on BaseFirestoreModel so that both field names and aliases are accepted on construction. The equivalent Config.allow_population_by_field_name = True is set for Pydantic v1.Verify Your Installation
After installing, run the following snippet to confirm that the package imports correctly and that your credentials are configured:If you see
google.auth.exceptions.DefaultCredentialsError, either set GOOGLE_APPLICATION_CREDENTIALS to a valid service-account file or start the emulator and set FIRESTORE_EMULATOR_HOST=localhost:8080 before running the script.