Registry / gcp / mock-firestore

mock-firestore

JSON →
library0.11.0pypypi✓ verified 80d ago

In-memory implementation of Google Cloud Firestore for use in tests. Currently at version 0.11.0. Release cadence is irregular; last update was a while ago but library is stable.

pip install mock-firestore
INSTALL
IMPORT
SIG · MOCK-FIRESTORE
M
mock-firestore
gcppythonv0.11.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.11.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MockFirestore
from mockfirestore import MockFirestore
from mock_firestore import MockFirestore

Create a MockFirestore instance and use it like the real Firestore client.

from mock_firestore import MockFirestore firestore = MockFirestore() # Add a document doc_ref = firestore.collection('users').document('user1') doc_ref.set({'name': 'Alice', 'email': 'alice@example.com'}) # Query docs = firestore.collection('users').where('name', '==', 'Alice').stream() for doc in docs: print(doc.id, doc.to_dict()) # Output: user1 {'name': 'Alice', 'email': 'alice@example.com'}
Debug
Known issues
gotchaMockFirestore does not enforce real Firestore constraints like unique document IDs within a collection (auto-ID generation) or transactional isolation. Do not assume identical behavior to production Firestore.
fix
Only use for unit tests where exact constraint emulation is not required.
affects: all
deprecatedThe `MockFirestore` constructor no longer accepts `project` or `credentials` arguments in recent versions (0.11.0). Previously you could pass a project ID.
fix
Simply instantiate without arguments: `MockFirestore()`
affects: >=0.11.0
gotchaThe `collection()` and `document()` methods return references but do not actually create the underlying data until a write operation (like `.set()` or `.add()`) is performed. Methods like `.get()` on a non-existent document will raise an exception (simulating real Firestore).
fix
Always perform a write before reading a document that may not exist, or use `document_ref.get().exists` to check.
affects: all
Upgrade
Version history
0.11.0latest on PyPI · released Jan 24, 2022
Audit
Dependencies
google-cloud-firestorerequiredRequired for Firestore protocol types and data structures
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
mock-firestore — pip install mock-firestore · libregistry