易于使用谷歌云平台存储桶包装器
storage-bucket的Python项目详细描述
谷歌云平台存储桶
这个软件包只是为了让那些不得不使用google云存储桶的人的生活更轻松一些。在
快速启动:
- 拿到包裹
pip install storage-bucket
- 下载密钥文件并另存为key.json键然后用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'
- 运行一些代码:
fromstorage_bucket.download_fileimportDownloadFile,download_filedefuse_data_for_something(data):print(data)# Normal way, this might throw exception... handle them yourself.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.# so its completely safe.DownloadFile()('my_bucket','my_file.txt',).map(use_data_for_something,# send data to this function,)
文件/blob操作
下载
^{pr2}$上传
fromstorage_bucket.upload_fileimportUploadFile,upload_fileUploadFile()(b'data','bucket_name','filename')upload_file(b'data','bucket_name','filename')
列表
fromstorage_bucket.list_filesimportListFiles,list_filesListFiles()('bucket')list_files('bucket')ListFiles()('bucket','foldername/')list_files('bucket','foldername/')
删除
fromstorage_bucket.delete_fileimportDeleteFile,delete_fileDeleteFile()('bucketname','filename')delete_file('bucketname','filename')
铲斗操作
创建Bucket
fromstorage_bucket.createimportCreateBucket,create_bucketCreateBucket()('bucket-name','EU','STANDARD')create_bucket('bucket-name','EU','STANDARD')
删除Bucket
fromstorage_bucket.deleteimportDeleteBucket,delete_bucketDeleteBucket()('bucket-name')delete_bucket('bucket-name')
列出存储桶
fromstorage_bucket.listimportListBuckets,list_buckets,list_bucket_namesbuckets=ListBuckets()()bucket_names=list_bucket_names(buckets.unwrap())buckets2=list_buckets()bucket_names2=list_bucket_names(buckets2)
使用Returns库。
- 让我们排除所有的例外。在
- 让我们把东西串起来,这样一切看起来都很好。在
- 允许您使用
DownloadFile()(args...).map(dostuff).alt(dostuffonfailure)
- 不喜欢吗?使用为您的方便而提供的匹配正常函数。在
贡献
喜欢图书馆,想要帮助我们,请查看:CONTRIBUTING.md
- 项目
标签: