bucket-locker
Concurrency-safe local copies of Google Cloud Storage (GCS) blobs in Python.
Why?
You need this library if:
- You are using a GCS bucket.
- Your system, app, or service downloads files from that bucket, works on local copies, and then uploads them back.
What it does
bucket-locker helps you:
- Avoid data races
- between accesses to the same local copy (e.g. multiple threads/tasks), and
- between different local copies of the same blob (e.g. multiple processes/instances).
- Avoid redundant I/O
- skip downloads if your local copy is already in sync,
- skip uploads if the blob hasn’t changed.
Installation
pip install bucket-locker
Usage
import asyncio
from pathlib import Path
from bucket_locker import Locker, BlobNotFound
async def main():
locker = Locker(bucket_name="my-bucket", local_dir=Path("/tmp/bucket"))
# Safe read–write access
try:
async with locker.owned_local_copy("data.json") as handle:
# work on the local file
data = handle.path.read_text()
handle.path.write_text(data + "\nextra line")
# changes will be uploaded automatically on exit
except BlobNotFound:
print("Blob not found in GCS")
# Safe read-only access: does not lock the blob
async with locker.readonly_local_copy("config.yaml") as handle:
config = handle.path.read_text()
print(config)
asyncio.run(main())
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for bucket-locker 1.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bucket_locker-1.0.8.tar.gz | 11.9 kB | Without provenance | Details for bucket_locker-1.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bucket_locker-1.0.8-py3-none-any.whl | Python 3 | none | any | Details for bucket_locker-1.0.8-py3-none-any.whl |
Total release size: 19.6 kB
Release files / bucket_locker-1.0.8.tar.gz
| Download URL | bucket_locker-1.0.8.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb05144c7bcb9f623c544fba1b67b7f1e3dfac7e3585e7a2c2a40572618f3eb4
|
|
BLAKE2b-256 checksum How to use checksums |
d1c7877692ecf2adc5e8545a860bb6759059bffba544cb1d243b9944fcea09c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / bucket_locker-1.0.8-py3-none-any.whl
| Download URL | bucket_locker-1.0.8-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d383dc837ee0140f6533330655b48904560bb19edea95dbef01f27f5eace9657
|
|
BLAKE2b-256 checksum How to use checksums |
05748fa390ad6a08c78b49da6dc9c76f59aca0d06e2cce9b1b7aed4a8170d8d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Security for bucket-locker 1.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.