Skip to main content

Python utility for Cloud Storage for Firebase.

Project description


PyPI version Python Versions lint & test codecov

Python utility for Cloud Storage for Firebase.

What is This?

In order to use Google Cloud Storage with the Firebase framework, you have to:

  • Give an access token to uploaded files,
  • Publish a URL with an access token for the domain
  • As a further application, you may want to grant a new access token, remove an existing access token, or in a real use case, get a instance from a URL.

Unfortunately google-cloud-storage package does not provide the functions for them.

But by using cloud-storage-for-firebase-utils you can easily achieve them👍.


Quick Start

First, install by pip intall csfutils . Second, prepare a target file stars⭐.jpg . Finally, run below code❗

from import Blob, Bucket, Client

# Import package
# ==============
import csfutils

# Initialize, Bucket and Blob instances
# =================================================================
storage: Client = Client()
bucket: Bucket = storage.bucket("")  # PUT YOUR BUCKET NAME
blob: Blob = bucket.blob("images/stars⭐.jpg")  # PUT PATH ON CLOUD STORAGE YOU WANT

# 🔥Upload "./stars⭐.jpg" to Cloud Storage for Firebase
# ======================================================
uploaded_url: str = csfutils.upload_from_filename_for_firebase(blob, "./stars⭐.jpg")
# --> uploaded_url=

# csfutils.upload_from_file_for_firebase() and csfutils.upload_from_string_for_firebase() also exist.

# 🔥Add, get and delete an access token
# =====================================
current_access_token = csfutils.get_access_token(blob)
assert type(current_access_token) is str
# --> current_access_token=f7d0815d-96f8-4907-b22c-70ad9e38d7ff

new_access_token: str = csfutils.add_access_token(blob)
# --> new_access_token=e0d97b72-44c3-415d-8d88-1e3aeae2fc28

access_tokens = csfutils.get_access_token(blob)
assert isinstance(access_tokens, list)
# --> current_access_token=['f7d0815d-96f8-4907-b22c-70ad9e38d7ff','e0d97b72-44c3-415d-8d88-1e3aeae2fc28']

csfutils.delete_access_token(blob, new_access_token)
# --> latest_access_token=f7d0815d-96f8-4907-b22c-70ad9e38d7ff

# 🔥Get instance from URL
# =================================================
blob_ref_from_url: Blob = csfutils.ref_from_url(
# --> blob_ref_from_url == storage.bucket("").get_blob("images/stars✧.jpg")

Bonus Track

from csfutils

# BONUS 1: Get instance
# =================================================
storage: Client = csfutils.init_storage("./your_service_account.json")

# BONUS 2: Parse URL to bucket name & path
# ========================================
bucket_name, path = csfutils.parse_url("")
# -->,path=images/stars⭐.jpg

# BONUS 3: Get 3 URLs:, and
# ========================================================================================================
blob: Blob = storage.bucket(bucket_name).blob(path)

firestorage_url = csfutils.get_download_url(blob)
# --> firestorage_url=

public_url = csfutils.get_download_url(blob, csfutils.UrlType.PUBLIC_URL)
# --> firestorage_url=

authenticated_url = csfutils.get_download_url(blob, csfutils.UrlType.AUTHENTICATED_URL)
# --> authenticated_url=

# BONUS 4: Get GS path
# ====================
gs_path = csfutils.get_gs_path(blob)
# --> gs_path=gs://⭐.jpg


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

csfutils-0.2.0.tar.gz (9.6 kB view hashes)

Uploaded Source

Built Distribution

csfutils-0.2.0-py3-none-any.whl (10.1 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