semvec/pypi-packages huggingface dataset:
masterai-oss 2023.8.1
masterai oss
License: MIT
Requires Python: >=3.6.0


# masterai-oss
> 基于[boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html)封装, 返回值更加清晰


## 支持

### 原生函数
1. copy_object
1. delete_object
1. get_object
1. head_object
1. put_object
1. list_objects
1. list_objects_v2
1. filter
1. all
1. download_file
1. download_fileobj
1. upload_file
1. upload_fileobj

### 扩展函数
1. check_object_exist
1. upload_if_not_exist


#### 使用方式
```python
from masterai_oss import S3Client, PutObjectResponse, HeadObjectResponse

client = S3Client(
    access_key="your access_key",
    secret_key="your secret_key",
    bucket_name="your bucket_name",
    endpoint="your endpoint",
)

key = "path/of/obj.suffix"
put_response: PutObjectResponse = client.put_object(
    key=key,
    body=b"file content",
)

head_response: HeadObjectResponse = client.head_object(
    key=key
)
print(head_response.ContentLength)
```
uploadthing.py 0.3.3
Python SDK for UploadThing
License: MIT
Requires Python: <4.0,>=3.12

# Installation

```sh
pip install uploadthing.py
```

# Quickstart

## Using UTApi

This is basically a 1:1 clone of the official [TypeScript SDK](https://docs.uploadthing.com/api-reference/ut-api)

```py
import asyncio, os

from uploadthing_py import UTApi


async def main():
    utapi = UTApi(os.getenv("UPLOADTHING_SECRET"))

    # List the files in your app
    res = await utapi.list_files()
    print("List files:", res)

    # Delete the first file from the list
    key = res[0].key
    res = await utapi.delete_file(key)
    print("Delete file:", res)

    # (TODO) Create a new file
    # res = await utapi.upload_files()


if __name__ == "__main__":
    asyncio.run(main())
```

## Using FastAPI

You can use FastAPI like any of the JavaScript backend adapters.

> [!TIP]
>
> You can use this example along with one of the [client examples](https://github.com/pingdotgg/uploadthing/tree/main/examples/backend-adapters)
>
> ```sh
> UPLOADTHING_SECRET=sk_foo poetry run uvicorn examples.fastapi:app --reload --port 3000
> ```

> [!WARNING]
>
> This is a work in progress and not yet ready for production use.

```py
from fastapi import FastAPI, Request, Response
from uploadthing_py import (
    UploadThingRequestBody,
    create_uploadthing,
    create_route_handler,
)
from fastapi.middleware.cors import CORSMiddleware
import os

app = FastAPI()
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

f = create_uploadthing()


upload_router = {
    "videoAndImage": f(
        {
            "image/png": {"max_file_size": "4MB"},
            "image/heic": {"max_file_size": "16MB"},
        }
    )
    .middleware(lambda req: {"user_id": req.headers["x-user-id"]})
    .on_upload_complete(lambda file, metadata: print(f"Upload complete for {metadata['user_id']}"))
}
handlers = create_route_handler(
    router=upload_router,
    api_key=os.getenv("UPLOADTHING_SECRET"),
    is_dev=os.getenv("ENVIRONMENT", "development") == "development",
)


@app.get("/api")
async def greeting():
    return "Hello from FastAPI"


@app.get("/api/uploadthing")
async def ut_get():
    return handlers["GET"]()


@app.post("/api/uploadthing")
async def ut_post(
    request: Request,
    response: Response,
    body: UploadThingRequestBody,
):
    return await handlers["POST"](
        request=request,
        response=response,
        body=body,
    )
```