A CLI and library for Firestore batch operations
Project description
:coffee: Open-source tools thrive on caffeine. If you like this project, please consider supporting it.
Firebatch: Advanced Firestore CLI Tool
Firebatch streamlines batch operations on Firestore, offering developers a robust CLI tool for managing Google Firestore databases. It simplifies CRUD operations, supports advanced data type conversions, and facilitates efficient data manipulation directly from your command line.
Key Features
Read/Download
Fetch documents with customizable query conditions, ordering, and limits. Supports raw mode and Firestore type conversions.
Write
Batch upload documents with server timestamp support and automatic format detection.
Update
Perform batch updates with upsert functionality and optional data validation.
Delete
Bulk delete documents, with support for recursive subcollection deletion.
Validation
Validate documents against custom Pydantic models before writing or updating.
Verbose and Dry Run Modes
Enable detailed operation logs and simulate write operations without database changes.
Flexible Input Formats
Supports JSON, JSONL, and auto-detects input data formats.
Timestamp and Geopoint Conversion
Automatically converts Python datetime and geopoint data to Firestore's Timestamp and GeoPoint types.
Collection Group Queries
Query across all collections with the same name, regardless of their database location.
List Collections
Quickly list all top-level collections in your Firestore database.
Installation
:warning: Ensure you have Python 3.6 or newer installed before proceeding.
Install Firebatch using pip:
pip install firebatch
# For additional validation support:
pip install firebatch[validation]
Examples
Workflow 1: Geotagging User Posts
Suppose you want to add location data to user posts that lack this information. You can use Firebatch to read, update, and validate geopoint data in bulk.
- Export posts lacking geotags to a JSONL file for review:
firebatch read --collection posts --where "location == null" --format jsonl > posts_without_geotags.jsonl
- Manually add geotags to the posts in
posts_without_geotags.jsonl
using your preferred text editor or a script. - Validate and update posts with geopoint conversion enabled to ensure data integrity:
firebatch update --collection posts --geopoint-convert --validator my_validators:PostValidator --verbose updates_with_geotags.jsonl
Workflow 2: Archiving Old Orders
For orders older than a year, you might want to move them to an archive collection to keep your active orders collection lean and performant.
- Identify and export old orders using timestamp conversion to detect dates properly:
firebatch read --collection orders --where "date < 2023-01-01" --timestamp-convert --format jsonl --verbose > old_orders.jsonl
- Review the exported data to ensure accuracy.
- Import old orders into the archive with automatic timestamp updates:
firebatch write --collection archived_orders --timestamp-field archived_at --timestamp-convert --format jsonl --verbose < old_orders.jsonl
- Delete the original old orders after confirming the archive's integrity (use dry-run mode first for safety):
firebatch delete --collection orders --verbose --dry-run old_orders.jsonl
After verification, remove--dry-run
to proceed with deletion.
Workflow 3: Consolidating User Feedback
Imagine you have feedback stored in multiple collections (e.g., feedback_2023
, feedback_2024
) and you want to consolidate all feedback into a single collection for easier analysis.
- Perform collection group queries to fetch all feedback documents:
firebatch read --collection feedback --collection-group --format jsonl --verbose > all_feedback.jsonl
- Optionally process the feedback data to fit the new unified format.
- Batch upload the consolidated feedback to a new
unified_feedback
collection:firebatch write --collection unified_feedback --format jsonl --verbose all_feedback.jsonl
Contributing
:heart: Your contributions make Firebatch better.
Report bugs, suggest enhancements, or submit pull requests on our GitHub repository. Join our community to make Firestore more accessible and efficient for developers worldwide.
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
Built Distribution
File details
Details for the file firebatch-1.1.1.tar.gz
.
File metadata
- Download URL: firebatch-1.1.1.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d82d309d92d54b2d89e3273795c58d24beb99d699103e6ead091b50ce31fef7f |
|
MD5 | 074b5bc08a8077ea34a8d6d4c52d7f36 |
|
BLAKE2b-256 | d143d36d9409ad042e241f47c0772325c339650712de7e6f4ac2604e0190d9da |
File details
Details for the file firebatch-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: firebatch-1.1.1-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ae000747afdcfc1064205c6df1134e847e89c3f1c151b68f478e3218ba1b454 |
|
MD5 | ad24feec4d7d84af4f0aab007f21885b |
|
BLAKE2b-256 | d18f08cd33eafa4352f42ea42fb4f5b724e9733f1cdafce080fa35156e8882f7 |