Skip to main content

cloud object storage wrapper

Project description

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='obs'):
    """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.
    """
    with open(filepath, "rb") as f:
        config = tomllib.load(f)

        access_key_id = config["obs"]["access_key_id"]
        secret_access_key = config["obs"]["secret_access_key"]
        endpoint = config["obs"]["endpoint"]
        bucket = config["obs"]["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)

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

wareroom-0.0.4.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

wareroom-0.0.4-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file wareroom-0.0.4.tar.gz.

File metadata

  • Download URL: wareroom-0.0.4.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for wareroom-0.0.4.tar.gz
Algorithm Hash digest
SHA256 e0369a2ccbcbf501d114bd730f7d02ffa50aca48de7fbf7c4101640e02ef403b
MD5 038ba01f4b7169a3d81c922269293f02
BLAKE2b-256 9a7482a888a4f45d7505eb1ee53e3785d7b4e6cef42ddd998eb4bb6f97b6befd

See more details on using hashes here.

File details

Details for the file wareroom-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: wareroom-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for wareroom-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 863dded0ae54a2bd9a9932e414eea9dbe9f1efeb14e92903bb31691cd4ff2d14
MD5 07fae4249264cd6fc101fedc9f25c158
BLAKE2b-256 d8edda8bc7478c4da019dbaea95073b75cfe69ad911c1ae90d8c3ad4e4b2c2a8

See more details on using hashes here.

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