|
1 | 1 | # object-store-rs
|
2 |
| -A Python interface and pyo3 integration to the object-store crate |
| 2 | + |
| 3 | +A Python interface and pyo3 integration to the Rust [`object_store`](https://docs.rs/object_store/latest/object_store/) crate. This crate provides a uniform API for interacting with object storage services and local files. Using this library, the same code can run in multiple clouds and local test environments, via a simple runtime configuration change. |
| 4 | + |
| 5 | +<!-- For Rust developers looking to add object_store support to their Python packages, refer to pyo3-object_store. --> |
| 6 | + |
| 7 | +- Easy to install with no Python dependencies. |
| 8 | +- Full static type hinting |
| 9 | +- Full sync and async API |
| 10 | +- Helpers for constructing from environment variables and `boto3.Session` objects |
| 11 | + |
| 12 | +Among the included backend are: |
| 13 | + |
| 14 | +- Amazon S3 and S3-compliant APIs like Cloudflare R2 |
| 15 | +- Google Cloud Storage |
| 16 | +- Azure Blob Gen1 and Gen2 accounts (including ADLS Gen2) |
| 17 | +- Local filesystem |
| 18 | +- In-memory storage |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +```sh |
| 25 | +pip install object-store-rs |
| 26 | +``` |
| 27 | + |
| 28 | +## Comparison to object-store-python |
| 29 | + |
| 30 | +- More maintainable API than object-store-python. |
| 31 | +- Fewer classes. Use native Python (typed) dicts and objects where possible. |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +### Constructing a store |
| 36 | + |
| 37 | +For ease of use and accurate validation, there are separate classes for each backend. |
| 38 | + |
| 39 | +TODO: finish doc here |
| 40 | + |
| 41 | +#### Configuration |
| 42 | + |
| 43 | +- Each store concept has their own configuration. This is covered in the docs, and string literals are in the type hints. |
| 44 | + |
| 45 | +### Interacting with a store |
| 46 | + |
| 47 | +All methods for interacting with a store are exported as top-level functions, |
| 48 | +such as `get`, `put`, `list`, and `delete`. |
| 49 | + |
| 50 | +```py |
| 51 | +import object_store_rs as obs |
| 52 | + |
| 53 | +store = obs.store.MemoryStore() |
| 54 | + |
| 55 | +obs.put_file(store, "file.txt", b"hello world!") |
| 56 | +response = obs.get(store, "file.txt") |
| 57 | +response.meta |
| 58 | +# {'size': 12, |
| 59 | +# 'last_modified': datetime.datetime(2024, 10, 18, 4, 8, 12, 57046, tzinfo=datetime.timezone.utc), |
| 60 | +# 'version': None, |
| 61 | +# 'e_tag': '0', |
| 62 | +# 'location': 'file.txt'} |
| 63 | + |
| 64 | +assert response.bytes() == b"hello world!" |
| 65 | + |
| 66 | +byte_range = obs.get_range(store, "file.txt", offset=0, length=5) |
| 67 | +assert byte_range == b"hello" |
| 68 | + |
| 69 | +obs.copy(store, "file.txt", "other.txt") |
| 70 | +assert obs.get(store, "other.txt").bytes() == b"hello world!" |
| 71 | +``` |
| 72 | + |
| 73 | +All of these methods also have `async` counterparts, suffixed with `_async`. |
| 74 | + |
| 75 | +```py |
| 76 | +import object_store_rs as obs |
| 77 | + |
| 78 | +store = obs.store.MemoryStore() |
| 79 | + |
| 80 | +await obs.put_file_async(store, "file.txt", b"hello world!") |
| 81 | +response = await obs.get_async(store, "file.txt") |
| 82 | +response.meta |
| 83 | +# { |
| 84 | +# "last_modified": datetime.datetime( |
| 85 | +# 2024, 10, 18, 4, 14, 39, 630310, tzinfo=datetime.timezone.utc |
| 86 | +# ), |
| 87 | +# "size": 12, |
| 88 | +# "location": "file.txt", |
| 89 | +# "version": None, |
| 90 | +# "e_tag": "0", |
| 91 | +# } |
| 92 | +assert await response.bytes_async() == b"hello world!" |
| 93 | + |
| 94 | +byte_range = await obs.get_range_async(store, "file.txt", offset=0, length=5) |
| 95 | +assert byte_range == b"hello" |
| 96 | + |
| 97 | +await obs.copy_async(store, "file.txt", "other.txt") |
| 98 | +resp = await obs.get_async(store, "other.txt") |
| 99 | +assert await resp.bytes_async() == b"hello world!" |
| 100 | +``` |
0 commit comments