{"id":6319,"library":"b2sdk","title":"Backblaze B2 SDK","description":"The `b2sdk` library provides a comprehensive Python SDK for interacting with Backblaze B2 Cloud Storage. It allows developers to manage buckets, upload and download files, handle file versions, and more. The current version is 2.10.4, with releases occurring regularly to add features, fix bugs, and maintain compatibility.","status":"active","version":"2.10.4","language":"en","source_language":"en","source_url":"https://github.com/Backblaze/b2-sdk-python","tags":["backblaze","b2","cloud storage","object storage","sdk"],"install":[{"cmd":"pip install b2sdk","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Since v2.9.1, the B2 SDK officially recommends importing from `b2sdk.v3` for the latest API interface and features. Importing from `b2sdk` directly (which maps to `v2`) is still supported but may not receive new features or might be deprecated in the future.","wrong":"from b2sdk import B2Api","symbol":"B2Api","correct":"from b2sdk.v3 import B2Api"},{"note":"Used for persisting B2 account authorization information locally.","symbol":"SqliteAccountInfo","correct":"from b2sdk.v3.account_info.sqlite_account_info import SqliteAccountInfo"}],"quickstart":{"code":"import os\nfrom b2sdk.v3 import B2Api\nfrom b2sdk.v3.account_info.sqlite_account_info import SqliteAccountInfo\n\n# It's recommended to store credentials in environment variables\nAPPLICATION_KEY_ID = os.environ.get('B2_APPLICATION_KEY_ID', 'YOUR_KEY_ID')\nAPPLICATION_KEY = os.environ.get('B2_APPLICATION_KEY', 'YOUR_KEY')\n\nif APPLICATION_KEY_ID == 'YOUR_KEY_ID' or APPLICATION_KEY == 'YOUR_KEY':\n    print(\"Please set B2_APPLICATION_KEY_ID and B2_APPLICATION_KEY environment variables.\")\nelse:\n    try:\n        # Initialize account info storage (can be SqliteAccountInfo, InMemoryAccountInfo, etc.)\n        info = SqliteAccountInfo()\n        b2_api = B2Api(info)\n\n        # Authorize with Backblaze B2\n        b2_api.authorize_account(\n            realm='production',  # Or 'test' for integration testing\n            application_key_id=APPLICATION_KEY_ID,\n            application_key=APPLICATION_KEY\n        )\n        print(\"Successfully authorized with Backblaze B2.\")\n\n        # Example: List your buckets\n        print(\"\\nListing buckets:\")\n        buckets = b2_api.list_buckets()\n        if buckets:\n            for bucket in buckets:\n                print(f\"  - {bucket.name} (ID: {bucket.id_}, Type: {bucket.bucket_type})\")\n        else:\n            print(\"  No buckets found.\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize the `B2Api` client, authorize with your Backblaze B2 credentials (retrieved from environment variables for security), and then list your B2 buckets. This is a common first step for any interaction with B2 Cloud Storage."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or later.","message":"Python 3.8 support was dropped in `b2sdk` v2.10.0. Projects using `b2sdk` must now run on Python 3.9 or newer.","severity":"breaking","affected_versions":"<2.10.0"},{"fix":"Update imports to `from b2sdk.v3 import B2Api` for new projects or when updating existing code.","message":"The recommended API version for `b2sdk` is `v3` since `v2.9.1`. Importing `B2Api` from `b2sdk` directly (i.e., `from b2sdk import B2Api`) will use the older `v2` API, which may lack new features or lead to future compatibility issues.","severity":"gotcha","affected_versions":">=2.9.1"},{"fix":"If encountering issues after upgrading, try deleting the local account info file (typically `~/.b2_account_info`) and re-authorizing, or consult the `b2sdk` migration guide if available.","message":"If using `SqliteAccountInfo` for local credential caching, upgrading to `b2sdk` v2.10.3 from an older version might encounter backwards compatibility issues due to changes in the sqlite schema related to multi-bucket key support.","severity":"gotcha","affected_versions":"<2.10.3"},{"fix":"Upgrade to `b2sdk` v2.10.4 or later to fix this retry behavior.","message":"A retry bug in `upload_unbound_stream()` for small-file uploads could cause a `ValueError: I/O operation on closed file` if a retryable upload error occurred.","severity":"gotcha","affected_versions":">=2.9.1, <2.10.4"},{"fix":"Review key management logic and ensure it aligns with the multi-bucket key capabilities introduced in `v2.9.1`.","message":"The `b2sdk` library adapted `authorize_account` and key management flows for multi-bucket keys in `v2.9.1`. If you manage application keys that are scoped to multiple buckets, older integrations might need review.","severity":"gotcha","affected_versions":"<2.9.1"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}