Backblaze B2 Command Line Tool (b2)
The `b2` package provides the official Command Line Tool for Backblaze B2 cloud storage. It allows users to manage files, buckets, and account settings directly from their terminal. The current version is 4.6.0, and it follows a frequent release cadence, often patching fixes and improving compatibility with newer Python versions or underlying SDK changes.
Common errors
-
ModuleNotFoundError: No module named 'b2'
cause The `b2` Python package is designed as a command-line tool, not a library for direct programmatic `import` in Python scripts.fixTo use the Backblaze B2 API programmatically in Python, install and use the `b2sdk` library (`pip install b2sdk`). To run the CLI, execute `b2` commands directly in your terminal. -
Error: This version of b2 requires Python >=3.9
cause You are attempting to run `b2` version 4.5.0 or newer on an unsupported Python version (e.g., Python 3.8).fixUpgrade your Python environment to version 3.9 or higher. Alternatively, if you cannot upgrade Python, install an older compatible version of `b2` using `pip install "b2<4.5.0"`. -
SystemError: <built-in function _io_q_write_impl> returned a result with an error set
cause A buffer overflow issue occurring with `rst2ansi` dependency's terminal size detection on Python 3.14+, fixed in `b2` v4.5.0.fixUpgrade your `b2` installation to version 4.5.0 or newer by running `pip install --upgrade b2`. -
Unauthorized: Credentials not valid
cause The `applicationKeyId` or `applicationKey` provided during `b2 authorize-account` is incorrect, or the key lacks the necessary permissions for the attempted operation.fixVerify your Backblaze B2 Application Key ID and Application Key in your B2 console. Ensure they are correctly entered and possess the required permissions. Re-run `b2 authorize-account <keyId> <applicationKey>` with the correct credentials.
Warnings
- breaking Support for Python 3.8 was officially dropped starting with `b2` version 4.5.0.
- gotcha On Python 3.14+, users might encounter `SystemError: <built-in function _io_q_write_impl> returned a result with an error set` due to a buffer overflow in a dependency's terminal size detection.
- gotcha Shell autocompletion features can be flaky or require re-installation after `b2` upgrades or Python version changes, especially on newer Python versions (3.12+, 3.14+).
- gotcha The `b2` CLI internally migrated to `b2sdk.v3` in v4.4.0. While this primarily impacts the underlying implementation, it signifies a major internal change. Users attempting to interact with B2 programmatically via Python should directly use `b2sdk` (specifically `b2sdk.v3`), not attempt to import internal components from the `b2` CLI package.
Install
-
pip install b2
Imports
- b2
import b2
This package is a CLI tool and not intended for direct programmatic import.
Quickstart
pip install b2 b2 authorize-account $B2_ACCOUNT_ID $B2_APPLICATION_KEY b2 bucket list b2 upload-file my-bucket-name local-file.txt remote-file-name.txt