Giter VIP home page Giter VIP logo

firestore_size's Introduction

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

firestore_size's People

Contributors

waseemsabir avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

garawaa

firestore_size's Issues

Hello. It gives an exception when a document contains a document reference typed value

Traceback (most recent call last):
File "D:\Python39\lib\site-packages\firestore_size\calculate.py", line 75, in document_size
return additional_document_size + _calculate_size(document)
File "D:\Python39\lib\site-packages\firestore_size\calculate.py", line 68, in _calculate_size
return _object_size(obj)
File "D:\Python39\lib\site-packages\firestore_size\calculate.py", line 44, in _object_size
[
File "D:\Python39\lib\site-packages\firestore_size\calculate.py", line 45, in
_calculate_size(key) + _calculate_size(value)
File "D:\Python39\lib\site-packages\firestore_size\calculate.py", line 68, in _calculate_size
return _object_size(obj)
File "D:\Python39\lib\site-packages\firestore_size\calculate.py", line 31, in _object_size
return 16 + sum([len(segment) + 1 for segment in obj._key._path._segments])
AttributeError: 'DocumentReference' object has no attribute '_key'
This is exception message.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.