Useful tools that simplify OSS file operation.
Project description
Useful tools for OSS
Makes your experience with OSS easier.
Quick start
pip install ossTools
Caution: Currently, only the following functions are tested:
- ossInit
- ossOpen
- imRead
- imWrite
Please report any problems with other untested functions to me, thanks!
Email: Ziheng Zhang (Suyue)
from ossTools import *
ossInit(
bucket='bucket-name',
access_id='your-access-id',
access_key='your-access-key',
endpoint='oss-cn-hangzhou.aliyuncs.com',
)
# Read file, multiprocess safe!
with ossOpen("some/path/in/the/bucket", "r") as fp:
print(fp.read())
# Write file, multiprocess safe!
with ossOpen("some/path/in/the/bucket", "w") as fp:
# Python3
print("Hello, world!", file=fp)
# Python2
fp.write("Hello, world!\n")
# Open and show an image with OpenCV
import cv2
# Use wrapped imRead/imWrite function in ossTools instead of cv2.imread
img = imRead("some/image.jpg", flags=cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)
cv2.imshow("img", img)
cv2.waitKey()
# Integrate with tensorboardX
import tensorboardX as tb
writter = tb.SummaryWriter(log_dir="oss://bucket/path/to/oss/dir")
writter.add_scalar("train/loss", some_loss, global_step=iters)
# File Utils
# Check file existence
assert ossIsFile("path/to/file"), "File {} does not exist!".format("path/to/file")
# List files in a dir
print(ossListFile("path/to/dir"))
# Or list dirs in a dir
print(ossListDir("path/to/dir"))
# Download/Upload/Delete/Copy
ossDownloadFile("remote/path", "local/path", progress_callback=lambda per: print("{}% downloaded.".format(per)))
ossUploadFile("remote/path", "local/path", overwrite=True, progress_callback=lambda per: print("{}% uploaded.".format(per)))
ossDeleteFile("path/to/file")
ossDeleteDir("path/to/dir", iterative=True)
ossCopyFile("source/file", "target/file")
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
ossTools-0.1.12.tar.gz
(6.2 kB
view hashes)
Built Distribution
Close
Hashes for ossTools-0.1.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 320303e1f08755b9a6405b156d36b167815a5a0559b911f5cee18fa799fb6c6e |
|
MD5 | 2670a3d0561f1fd0f0e59beb087c1ca6 |
|
BLAKE2b-256 | 289bcd5a03a6f0afb98e3da0299a3a0ab8d769ae0e01d31b0ee5de7a3fae210d |