没有项目描述
emporium的Python项目详细描述
简介
商场提供了文件存储的抽象。目前支持存储 本地磁盘、内存或S3上的文件。大多数商店实现为 围绕smart-open的简单包装 包裹。
示例
下面的代码片段创建一个存储,将一些文本写入 存储,然后读取并打印文件两次。文件hello.txt将具有 在文件夹data/job下创建,相对于当前工作目录。
fromemporiumimportcreate_storeconfig={"type":"local","base_path":"data"}store=create_store(config)withstore.write("job/hello.txt")ashandle:handle.write("world!")withstore.read("job/hello.txt")ashandle:print(handle.read())substore=store.substore("job/")withsubstore.open("hello.txt")ashandle:print(handle.read())
要将文件写入s3中的密钥,请将配置定义更改为以下内容:
config={"type":"s3","bucket":"my-data-bucket","prefix":"data"}