Skip to main content

Command-line tool for querying/updating firestore

Project description

Firestore CLI

This CLI tool allows you to interact with Google Firestore using command-line commands. It includes two main scripts: fsquery and fsupdate.

Installation

  1. Install from PyPI:

    pip install firestore-cli
    

Usage

Credentials

To specify the credentials necessary to access Firestore, you can use either of the following methods:

  1. Using the --credentials option:

    Provide the path to the Firebase credentials JSON file directly via the --credentials command-line option. Example usage:

    fsquery --credentials /path/to/your/credentials.json --path your/firestore/collection
    
  2. Using the GOOGLE_APPLICATION_CREDENTIALS environment variable: Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your Firebase credentials JSON file. Example usage:

    export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/credentials.json
    fsquery --path your/firestore/collection
    

If neither method is provided, the script will attempt to use the default application credentials (which probably won't go well)

Emulators

If you're using the local firestore emulators you'll want to set an environment variable to influence the Firestore SDK. Use whatever port you're running your firestore emulators on. In this example, that port is 8080.

export FIRESTORE_EMULATOR_HOST="127.0.0.1:8080"

fsquery

The fsquery script allows you to query documents from a Firestore collection.

Command Line Options

  • --path collection: Path to the Firestore collection (required).
  • --credentials: Path to Firebase credentials JSON file (optional).
  • --database: Firestore database name (optional, defaults to '(default)').
  • --group: Specify if this is a collection group query (optional).
  • --where: Apply multiple filters to the query in the format field:operation:value e.g. --where "some_field == some_value" (optional). It is recommended to place quotes around the expression.
  • --id: Query for a specific document ID (optional).
  • --orderby: Order the results by specified fields, followed by ASCENDING or DESCENDING (optional).
  • --limit n: Return n or fewer results (optional).
  • --recursion n: Follow references and fetch the referenced documents up to level n, incorporating them into the document that is returned. (optional, default: 0, which does not follow any references.)
  • --out filename: Write the json output to a file named filename

Examples

  1. Query all documents in a collection:

    fsquery --path your-collection
    
  2. Query documents with a filter:

    fsquery --path your-collection --where "field_name == value"
    
  3. Write output to a file

    fsquery --path your-collection --out query.json
    
  4. Query documents from a named database:

    fsquery --path your-collection --database my-database-name
    

fsupdate

The fsupdate script allows you to set, add, update, or delete documents in a Firestore collection.

Command Line Options

  • --path: Path to the Firestore collection (required).
  • --credentials: Path to Firebase credentials JSON file (optional).
  • --database: Firestore database name (optional, defaults to '(default)').
  • --set: Set a document with the specified ID.
  • --add: Add a new document.
  • --update: Update a document with the specified ID.
  • --delete: Delete a document with the specified ID.
  • --doc: Path to the JSON file containing the document data.

Examples

  1. Set a document:

    fsupdate --path your-collection --set your-document-id --doc path/to/your/document.json
    
  2. Add a document:

    fsupdate --path your-collection --add --doc path/to/your/document.json
    
  3. Update a document:

    fsupdate --path your-collection --update your-document-id --doc path/to/your/document.json
    
  4. Delete a document:

    fsupdate --path your-collection --delete your-document-id
    
  5. Set a document in a named database:

    fsupdate --path your-collection --database my-database-name --set your-document-id --doc path/to/your/document.json
    

License

This project is licensed under the MIT License.

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

firestore_cli-0.2.4.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

firestore_cli-0.2.4-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file firestore_cli-0.2.4.tar.gz.

File metadata

  • Download URL: firestore_cli-0.2.4.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for firestore_cli-0.2.4.tar.gz
Algorithm Hash digest
SHA256 c093e2cdca5cfc3a473e97225080a996c2d968cc11c24fbe776e603168e42510
MD5 fc66d7d9112d6102d268708f044c710e
BLAKE2b-256 b67949bc8a335bc2409f2abad676b3fd48dba06dd4e5687b0f306e4a74bdfe47

See more details on using hashes here.

File details

Details for the file firestore_cli-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: firestore_cli-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for firestore_cli-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4aa97d078238fef868b7fca19dcf9883aa70eaeda38c96e19b30cc8fbda89cf7
MD5 92e31b66d2e248657a3594209190b80a
BLAKE2b-256 6e044ba9c323beedf26a6a59fd0536f45b7f29d3bf0c47cbc979fbb694d22e1f

See more details on using hashes here.

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