Easy to work with Google Cloud Platform Storage Bucket wrapper
Project description
Google Cloud Platform Storage Bucket
This package just aims to make life a little bit easier for people who have to work with google cloud storage bucket.
Quickstart:
- get the package
pip install storage-bucket
- Download your keyfile and save it as key.json and point to it with env var:
gcloud iam service-accounts keys create key.json --iam-account your_service_account@your_project.iam.gserviceaccount.com
export GOOGLE_APPLICATION_CREDENTIALS='key.json'
- Run some code:
from storage_bucket.download_file import DownloadFile, download_file
def use_data_for_something(data):
print(data)
# Normal way, this might throw exception...
my_data = download_file(
'my_bucket',
'my_file.txt',
)
use_data_for_something(my_data)
# Returns Modal way
# this will _only_ call use_data_for_something when data is successfully downloaded.
DownloadFile()(
'my_bucket',
'my_file.txt',
).map(
use_data_for_something, # send data to this function,
).alt(
print, # print error or send a mail or w/e
)
Supported functions
Downloading
from storage_bucket.download_file import DownloadFile, download_file
DownloadFile()('bucket', 'filename')
download_file('bucket', 'filename')
Uploading
from storage_bucket.upload_file import UploadFile, upload_file
UploadFile()(b'data', 'bucket_name', 'filename')
upload_file(b'data', 'bucket_name', 'filename')
Listing
from storage_bucket.list_files import ListFiles, list_files
ListFiles()('bucket')
list_files('bucket')
ListFiles()('bucket', 'foldername/')
list_files('bucket', 'foldername/')
Deleting
from storage_bucket.delete_file import DeleteFile, delete_file
DeleteFile()('bucketname', 'filename')
delete_file('bucketname', 'filename')
List Buckets
from storage_bucket.list import ListBuckets, list_buckets, list_bucket_names
buckets = ListBuckets()()
bucket_names = list_bucket_names(buckets.unwrap())
buckets2 = list_buckets()
bucket_names2 = list_bucket_names(buckets2)
The use of Returns library.
- Just lets us get rid of all exceptions.
- Lets us chain stuff so everything looks good.
- Lets you use
DownloadFile()(args...).map(dostuff).alt(dostuffonfailure)
- Don't like it? use the matching normal function provided for your convenience.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
storage-bucket-0.4.0.tar.gz
(6.7 kB
view hashes)
Built Distribution
Close
Hashes for storage_bucket-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3639e8def469d08d3a1297c585171efe728ee51da38fbd629dec4227c3dadb6 |
|
MD5 | d6bba5137862ea8db487862fd21f9b55 |
|
BLAKE2b-256 | c961bf1fb7e1e3cfece20a6118906dbbc1a1be93b58d9366da73589efa5e777a |