wareroom
cloud object storage wrapper
Usage
pip install wareroom
set cloud storage credentials in config file
[obs]
access_key_id = "xxxx"
secret_access_key = "xxxx"
endpoint="https://obs.cn-north-4.myhuaweicloud.com"
bucket="image"
replace access_key_id and secret_access_key with your own credentials
from wareroom import Client
import tomllib
def read_config(filepath, kind='storage'):
"""Read storage config from toml file.
:param filepath: path to config file
:type filepath: str
:param kind: kind of config, default is storage
:type kind: str
:return: return config keys
:rtype: tuple, (str, str, str, str): access_id, secret_key, endpoint, bucket.
"""
with open(filepath, "rb") as f:
config = tomllib.load(f)
access_key_id = config["storage"]["access_key_id"]
secret_access_key = config["storage"]["secret_access_key"]
endpoint = config["storage"]["endpoint"]
bucket = config["storage"]["bucket"]
return access_key_id, secret_access_key, endpoint, bucket
config_file = "config.toml"
# read access key from config file
access_key_id, secret_access_key, endpoint, bucket = read_config(config_file)
# create client
client = Client(access_key_id, secret_access_key, endpoint, bucket)
# upload file
filename = "test.jpg"
bucket = "image"
with open(filename, "rb") as file:
result, content = client.add(bucket, filename, "image/jpeg", file)
# download file
result, content, buffer = client.get(bucket, filename)
# delete file
result, content = client.delete(bucket, filename)
api
read_config
read cloud storage credentials from config file
Read obs config from toml file.
Args:
filepath (str): toml config file path.
kind (str): config kind, only obs now.
Returns:
(str, str, str, str): access_id, secret_key, endpoint, bucket.
Client.add
upload file to cloud storage
if upload success, return True and url, else return False and reason
Args:
bucket (str): OBS bucket name.
filename (str): filename.
content_type (str): image MIME type / media type e.g. image/png or text/markdown.
file (File) : A SpooledTemporaryFile (a file-like object).
This is the actual Python file that you can pass directly to other functions
or libraries that expect a "file-like" object.
Returns:
(bool, str): (True/False, url/reason)
Client.get
download file from cloud storage
if download success, return True, content type, file buffer, else return False ,reason and ""
Args:
bucket (str): OBS bucket name.
filename (str): filename.
Returns:
(bool, str, File): (True/False, reason, file buffer)
Args:
bucket (str): OBS bucket name.
filename (str): filename
Returns:
(bool, str, str): (True/False, content_type/reason, buffer/"")
Client.delete
delete file from cloud storage
if delete success, return True and success message, else return False and reason
Args:
bucket (str): OBS bucket name.
filename (str): filename
Returns:
(bool, str): (True/False, message/reason)
Metadata
Release files for wareroom 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wareroom-0.0.9.tar.gz | 28.5 kB | Without provenance | Details for wareroom-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wareroom-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for wareroom-0.0.9-py3-none-any.whl |
Total release size: 38.7 kB
Release files / wareroom-0.0.9.tar.gz
| Download URL | wareroom-0.0.9.tar.gz |
|---|---|
| Size | 28.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9ec99d0a89e3952cc40b3976d04274d67280c29dcad73d2f0f56837468ee95a
|
|
BLAKE2b-256 checksum How to use checksums |
3cf5446235a4bea79226bc986327cea556609f5880b2ee27254a1aa5b771b5b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.1
|
Release files / wareroom-0.0.9-py3-none-any.whl
| Download URL | wareroom-0.0.9-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
868661b27241e9343aab5919d5dfe1910c2726a8f8dc461ce86484ff2dd6c52d
|
|
BLAKE2b-256 checksum How to use checksums |
d9fcc5ba9ddce6c6336a0340b94bd9e2ec5137f720e88ab59fc709f3fe3131f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.1
|
Security for wareroom 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.