Skip to main content

Python library to calculate the approximate size of a firestore document

Project description

firestore_size

Tests License: MIT

Python library to calculate the approximate size of a firestore document. This can be used for firebase storage cost analysis, among other things.

Installation

pip install firestore_size

Usage

from firestore_size.calculate import document_size

# initialize firebase and firestore client

collection = db.collection("data")
doc = collection.doc(id).get()
data = doc.to_dict()

doc_size = document_size(data)
print("Doc Size is ", doc_size)

How it calculates?

Checkout how the size of firestore docs is calculated in documentation.

Brief description is

  • Array - The sum of the sizes of its values
  • Boolean - 1 byte
  • Bytes - Byte length
  • Date and time - 8 bytes
  • Floating-point number - 8 bytes
  • Geographical point - 16 bytes
  • Integer - 8 bytes
  • Map - The size of the map, calculated the same way as document size
  • Null - 1 byte
  • Reference - The document name size
  • Text string - Number of UTF-8 encoded bytes + 1

What is not included?

Does not take into account the name of a document, check docs on how it's calculated.

Does not take into account indexing. Indexes can be disabled - docs - to free up more space.

How to contribute?

Create issues for any bugs caught. Fork the repo to your account and send pull request with your changes.

Run tests using

python3 setup.py pytest

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_size-1.0.1.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

firestore_size-1.0.1-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

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