Giter Site home page Giter Site logo

s3lite's Introduction

S3Lite

Minimal async s3 client implementation in python.

Installation

Requirements:

  • Python 3.9+
pip install s3lite

Examples

List buckets

from s3lite import Client

client = Client("key-id", "secret-key", "https://s3-endpoint")
for bucket in await client.ls_buckets():
    print(bucket.name)

Create new bucket

from s3lite import Client

client = Client("key-id", "secret-key", "https://s3-endpoint")
bucket = await client.create_bucket("new-bucket")

Upload object

from io import BytesIO
from s3lite import Client

client = Client("key-id", "secret-key", "https://s3-endpoint")
object_from_path = await client.upload_object("new-bucket", "test-image.jpg", "./local-image.png")

with open("document.txt", "rb") as f:  # Make sure to open file in read-binary mode
    object_from_file = await client.upload_object("new-bucket", "document.txt", f)

bytes_io = BytesIO(b"test file content")
object_from_bytesio = await client.upload_object("new-bucket", "test.txt", bytes_io)

Download object

from s3lite import Client

client = Client("key-id", "secret-key", "https://s3-endpoint")
saved_path = await client.download_object("new-bucket", "test-image.jpg", "./local-image.png")

bytes_io = await client.download_object("new-bucket", "document.txt", in_memory=True)

partial_bytes = await client.download_object("new-bucket", "test.txt", in_memory=True, offset=4, limit=6)

Generate presigned url

from s3lite import Client

client = Client("key-id", "secret-key", "https://s3-endpoint")

obj = await client.upload_object("new-bucket", "test-image.jpg", "./local-image.png")
presigned_url = obj.share()  # Url will be valid for 1 day

presigned_url_1h = client.share("new-bucket", "test.txt", 3600)  # Url will be valid for 1 hour

Delete object

from s3lite import Client

client = Client("key-id", "secret-key", "https://s3-endpoint")
saved_path = await client.delete_object("new-bucket", "test-image.jpg")

s3lite's People

Contributors

ruslanuc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.