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 8958379
Show file tree
Hide file tree
Showing 20 changed files with 1,194 additions and 51 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Docker images
uses: ScribeMD/[email protected]
with:
key: ${{ runner.os }}-docker-${{ hashFiles('**/docker-compose.yaml') }}
- name: Cache mypy
uses: actions/cache@v4
with:
path: "**/.mypy_cache"
key: ${{ runner.os }}-${{ matrix.python-version }}-mypy-${{ hashFiles('**/poetry.lock') }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
Expand Down
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 boto3 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=pathlib.Path(__file__).name,
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
```
2 changes: 1 addition & 1 deletion invocations/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def build(
context: invoke.Context,
) -> None:
"""Build python environ."""
"""Build python environment."""
saritasa_invocations.poetry.install(context)


Expand Down
Loading

0 comments on commit 8958379

Please sign in to comment.