CLI tool to clean up unfinished Backblaze B2 large uploads
Project description
B2 Cleanup
A CLI tool and Python library to clean up unfinished Backblaze B2 large file uploads.
📋 Overview
When uploading large files to Backblaze B2, interrupted uploads can leave behind unfinished file parts that consume storage and incur costs. This tool helps you identify and clean up these unfinished uploads.
🔧 Features
- Lists all unfinished large file uploads in a given B2 bucket
- Optionally cancels them (dry-run support included)
- Uses the official
b2sdkfor native Backblaze API access - Supports authentication via env vars, CLI override, or the
b2CLI - Clean CLI with logging support
- Class-based and easily extensible
🚀 Installation
pip install b2-cleanup
🧪 Usage
# Basic usage (requires B2 CLI to be installed and authorized)
b2-cleanup your-bucket-name
# Use with explicit credentials
b2-cleanup your-bucket-name --key-id YOUR_KEY_ID --key YOUR_APPLICATION_KEY
# Dry run to preview what would be deleted
b2-cleanup your-bucket-name --dry-run
Example (dry run):
b2-cleanup my-bucket --dry-run
Example (delete for real, with logging):
b2-cleanup my-bucket --log-file cleanup_$(date +%F).log
Example (override credentials):
b2-cleanup my-bucket --key-id my-key-id --key my-app-key
Example (Python usage):
from b2_cleanup import B2CleanupTool
# Using environment variables or B2 CLI for auth
tool = B2CleanupTool(dry_run=True)
# Using explicit credentials
tool = B2CleanupTool(
dry_run=False,
override_key_id="your-key-id",
override_key="your-application-key"
)
# Clean up unfinished uploads
tool.cleanup_unfinished_uploads("your-bucket-name")
🔐 Authentication
This tool supports three ways to authenticate with B2, in priority order:
-
Explicit CLI arguments:
b2-cleanup bucket-name --key-id YOUR_KEY_ID --key YOUR_APPLICATION_KEY
-
Environment variables:
export B2_APPLICATION_KEY_ID=abc123 export B2_APPLICATION_KEY=supersecretkey b2-cleanup bucket-name
-
The
b2CLI (must be previously authorized):b2 account authorize # Then the tool will read credentials via: b2 account get
📁 Project Structure
b2-cleanup/
├── b2_cleanup/
│ ├── __init__.py # Package exports
│ ├── core.py # Core functionality
│ └── cli.py # CLI implementation
├── tests/
│ ├── __init__.py
│ ├── test_core.py
│ └── test_cli.py
├── pyproject.toml # Project metadata + dependencies
├── CHANGELOG.md # Version history
├── .gitignore
└── README.md
📦 Packaging Notes
- The CLI entry point is
b2-cleanupviapyproject.toml - Install in editable mode (
uv pip install -e .) for fast development - Dependencies are managed via
uv - Testing dependencies:
uv pip install -e ".[dev]"
🧪 Testing
# Install dev dependencies
pip install b2-cleanup[dev]
# Run tests
pytest
# With coverage
pytest --cov=b2_cleanup
🛠️ Roadmap
- Filter uploads by file age
- Support multiple buckets
- Output metrics (count, size, cost saved)
- Optional integration with S3-compatible B2 APIs
📝 License
MIT License © 2025 Jeroen Verhoeven
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file b2_cleanup-0.1.4.tar.gz.
File metadata
- Download URL: b2_cleanup-0.1.4.tar.gz
- Upload date:
- Size: 37.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b86af0e5917b15c2a631f7e5726afc3bc2b20e5fea196a123480b784d3412fe1
|
|
| MD5 |
191e80564475b4fc1fc41e557662c073
|
|
| BLAKE2b-256 |
bead1dfb65da1d8b5015258d0730fd0d5f4b1c8830c117f08be539d681bd9bf1
|
File details
Details for the file b2_cleanup-0.1.4-py3-none-any.whl.
File metadata
- Download URL: b2_cleanup-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a67cb6573ff2390d030bb056d37974008745f24ddd5250aad64e9cfc6fe158b
|
|
| MD5 |
0c973a150b0216328be3e59dbaf8cd93
|
|
| BLAKE2b-256 |
2104efe2cbd041079c34689a2e50f2efd1d011daa89d899591a15d383c0c9127
|