Skip to content

Commit

Permalink
Set up package
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Gorbil <[email protected]>
Co-authored-by: Kseniya Shaydurova <[email protected]>
Co-authored-by: Andrey Otto <[email protected]>
Co-authored-by: Nikita Azanov <[email protected]>
Co-authored-by: Shirokov Sergey <[email protected]>
Co-authored-by: Leonid Malin <[email protected]>
  • Loading branch information
7 people committed Apr 17, 2024
1 parent e28b691 commit 61fd4dd
Show file tree
Hide file tree
Showing 18 changed files with 1,183 additions and 50 deletions.
3 changes: 0 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false,
"env": {
"PYTEST_ADDOPTS": "--no-cov"
},
}
]
}
1 change: 1 addition & 0 deletions .vscode/recommended_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"**/.pytest_cache": true,
"**/.mypy_cache": true,
"**/.ruff_cache": true,
"**/localstack_volume": true,
"**/htmlcov": true,
},

Expand Down
71 changes: 70 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,71 @@
# saritasa-s3-tools
Tools For S3 Used By Saritasa

![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/saritasa-nest/saritasa-s3-tools/checks.yml)
![PyPI](https://img.shields.io/pypi/v/saritasa-s3-tools)
![PyPI - Status](https://img.shields.io/pypi/status/saritasa-s3-tools)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/saritasa-s3-tools)
![PyPI - License](https://img.shields.io/pypi/l/saritasa-s3-tools)
![PyPI - Downloads](https://img.shields.io/pypi/dm/saritasa-s3-tools)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

Extension for django and drf to ease work with S3

## Installation

```bash
pip install saritasa-s3-tools
```

or if you are using [poetry](https://python-poetry.org/)

```bash
poetry add saritasa-s3-tools
```

To install all optional dependencies add `[all]`

## Features

* `S3Client` and `AsyncS3Client` for integrations with s3 buckets
* `S3FileTypeConfig` for defining configuration parameters for direct upload to s3
* `S3Key` for generating unique keys for s3 upload
* `pytest` plugin with fixtures for `boto3`, `S3Client` and `AsyncS3Client`

## Direct upload example

```python
import saritasa_s3_tools
import pathlib
import xml.etree.ElementTree

s3_client = saritasa_s3_tools.S3Client(
boto3_client=boto3_client,
default_bucket=s3_bucket,
)
s3_params = s3_client.generate_params(
filename=__file__.split("/")[-1],
config=saritasa_s3_tools.S3FileTypeConfig.configs["files"],
content_type="application/x-python-code",
extra_metadata={
"test": "123",
},
)
with (
httpx.Client() as client,
pathlib.Path(__file__).open("rb") as upload_file,
):
upload_response = client.post(
url=s3_params.url,
data={
key: value
for key, value in s3_params.params.items()
if value is not None
},
files={"file": upload_file.read()},
)
parsed_response = xml.etree.ElementTree.fromstring( # noqa: S314
upload_response.content.decode(),
)
file_key = parsed_response[2].text
file_url = parsed_response[0].text
```
173 changes: 134 additions & 39 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 61fd4dd

Please sign in to comment.