|
1 | 1 | # robinzhon |
2 | 2 |
|
3 | | -A high-performance Python library for fast, concurrent S3 object downloads. |
| 3 | +Minimal, high-performance Python helpers for concurrent S3 object transfers. |
4 | 4 |
|
5 | | -## Features |
| 5 | +A small extension that exposes fast, concurrent downloads (and uploads) to Python |
| 6 | +using a Rust implementation optimized for I/O-bound workloads. |
6 | 7 |
|
7 | | -- **Fast downloads**: Concurrent downloads using async I/O |
8 | | -- **Resilient**: Continues downloading even if some files fail |
9 | | -- **Simple API**: Easy-to-use methods for single and batch downloads |
10 | | -- **Detailed results**: Get success/failure information for batch operations |
| 8 | +## Install |
11 | 9 |
|
12 | | -## Requirements |
13 | | - |
14 | | -- Python >= 3.8 |
15 | | - |
16 | | -## Installation |
| 10 | +- From PyPI: `pip install robinzhon` or `uv add robinzhon` |
| 11 | +- From source (requires Rust + maturin): |
17 | 12 |
|
18 | 13 | ```bash |
19 | | -pip install robinzhon # if you use pip |
20 | | -uv add robinzhon # if you use uv |
| 14 | +# build and install into active venv |
| 15 | +maturin develop --release |
21 | 16 | ``` |
22 | 17 |
|
23 | | -## Example |
| 18 | +## Quick start |
| 19 | + |
| 20 | +Download a single object: |
24 | 21 |
|
25 | 22 | ```python |
26 | 23 | from robinzhon import S3Downloader |
27 | 24 |
|
28 | | -# Initialize downloader |
29 | | -client = S3Downloader("us-east-1") |
30 | | - |
31 | | -# Download a single file |
32 | | -download_path = client.download_file( |
33 | | - "test-bucket", "test-object-key", "./test-object-key" |
34 | | -) |
35 | | -# download_path will be the file path where the object was downloaded |
36 | | - |
37 | | -# Download multiple files to the same directory |
38 | | -files_to_download = [ |
39 | | - "data/file1.csv", |
40 | | - "data/file2.json", |
41 | | - "logs/app.log" |
42 | | -] |
43 | | -result = client.download_multiple_files( |
44 | | - "test-bucket", files_to_download, "./downloads" |
45 | | -) |
46 | | - |
47 | | -# Check results |
48 | | -print(f"Downloaded {len(result.successful)} files successfully") |
49 | | -print(f"Downloaded files: {result.successful}") |
50 | | -if result.has_failures(): |
51 | | - print(f"Failed to download: {result.failed}") |
52 | | - |
53 | | -# Download files with custom paths |
54 | | -downloads = [ |
55 | | - ("data/input.csv", "./processed/input_data.csv"), |
56 | | - ("config/settings.json", "./config/app_settings.json"), |
57 | | -] |
58 | | -result = client.download_multiple_files_with_paths("test-bucket", downloads) |
59 | | - |
60 | | -print(f"Success rate: {result.success_rate():.1%}") |
| 25 | +d = S3Downloader("us-east-1") |
| 26 | +path = d.download_file("my-bucket", "path/to/object.txt", "./object.txt") |
| 27 | +print(path) # ./object.txt |
| 28 | +``` |
| 29 | + |
| 30 | +Download many objects into a directory: |
| 31 | + |
| 32 | +```python |
| 33 | +files = ["data/a.csv", "data/b.csv"] |
| 34 | +res = d.download_multiple_files("my-bucket", files, "./downloads") |
| 35 | +print(res.successful) |
| 36 | +print(res.failed) |
| 37 | +``` |
| 38 | + |
| 39 | +Upload a single file or multiple files: |
| 40 | + |
| 41 | +```python |
| 42 | +from robinzhon import S3Uploader |
| 43 | + |
| 44 | +u = S3Uploader("us-east-1") |
| 45 | +u.upload_file("my-bucket", "dest/key.txt", "./local.txt") |
| 46 | +paths_and_keys = [("./local1.txt", "key1"), ("./local2.txt", "key2")] |
| 47 | +res = u.upload_multiple_files("my-bucket", paths_and_keys) |
| 48 | +print(res.successful, res.failed) |
61 | 49 | ``` |
62 | 50 |
|
63 | 51 | ## Configuration |
64 | 52 |
|
65 | | -You can configure the maximum number of concurrent downloads: |
| 53 | +- Both `S3Downloader` and `S3Uploader` accept an optional concurrency argument (default 5): |
66 | 54 |
|
67 | 55 | ```python |
68 | | -# Allow up to 10 concurrent downloads (default is 5) |
69 | | -client = S3Downloader("us-east-1", max_concurrent_downloads=10) |
| 56 | +S3Downloader("us-east-1", max_concurrent_downloads=10) |
| 57 | +S3Uploader("us-east-1", max_concurrent_uploads=10) |
70 | 58 | ``` |
71 | 59 |
|
72 | | -## Performance Test Results |
| 60 | +## API summary |
73 | 61 |
|
74 | | -```text |
75 | | -============================================================ |
76 | | -Performance Test: 1000 files |
77 | | -============================================================ |
| 62 | +- Results |
| 63 | + - Attributes: `successful: List[str]`, `failed: List[str]` |
| 64 | + - Methods: `is_complete_success()`, `has_success()`, `has_failures()`, `total_count()`, `success_rate()` |
78 | 65 |
|
79 | | -Testing threaded boto3 implementation... |
80 | | -Completed in 24.16s |
| 66 | +- S3Downloader(region_name, max_concurrent_downloads=5) |
| 67 | + - `download_file(bucket, key, local_path) -> str` |
| 68 | + - `download_multiple_files(bucket, keys, base_dir) -> Results` |
| 69 | + - `download_multiple_files_with_paths(bucket, [(key, local_path), ...]) -> Results` |
81 | 70 |
|
82 | | -Testing aioboto3 async implementation... |
83 | | -Completed in 27.70s |
| 71 | +- S3Uploader(region_name, max_concurrent_uploads=5) |
| 72 | + - `upload_file(bucket, key, local_path) -> str` |
| 73 | + - `upload_multiple_files(bucket, [(local_path, key), ...]) -> Results` |
84 | 74 |
|
85 | | -Testing robinzhon implementation... |
86 | | -Download completed in 10.30s |
87 | | -Verifying robinzhon downloads... |
| 75 | +## Building & testing |
88 | 76 |
|
89 | | -Performance Results (1000 files) |
90 | | -================================================================================ |
91 | | -Metric robinzhon threaded boto3 aioboto3 Winner |
92 | | -================================================================================ |
93 | | -Duration (seconds) 10.30 24.16 27.70 robinzhon |
94 | | -Throughput (files/sec) 97.1 41.4 36.1 robinzhon |
95 | | -Success Rate (%) 100.0 100.0 100.0 robinzhon |
96 | | -Files Downloaded 1000 1000 1000 |
97 | | -================================================================================ |
| 77 | +- Requires Rust toolchain and `maturin` to build the extension. |
| 78 | +- Tests are simple Python tests that assume the compiled extension is available. |
98 | 79 |
|
99 | | -Performance Summary: |
100 | | -robinzhon is 2.3x faster than threaded boto3 |
101 | | -robinzhon is 2.7x faster than aioboto3 |
102 | | -``` |
| 80 | +## License |
| 81 | + |
| 82 | +See the [LICENSE](LICENSE) file in the repository. |
0 commit comments