AccountInfo

AccountInfo stores basic information about the account, such as Application Key ID and Application Key, in order to let b2sdk.v2.B2Api perform authenticated requests.

There are two usable implementations provided by b2sdk:

  • b2sdk.v2.InMemoryAccountInfo - a basic implementation with no persistence

  • b2sdk.v2.SqliteAccountInfo - for console and GUI applications

They both provide the full AccountInfo interface.

Note

Backup applications and many server-side applications should implement their own AccountInfo, backed by the metadata/configuration database of the application.

AccountInfo implementations

InMemoryAccountInfo

AccountInfo with no persistence.

SqliteAccountInfo

Implementing your own

When building a server-side application or a web service, you might want to implement your own AccountInfo class backed by a database. In such case, you should inherit from b2sdk.v2.UrlPoolAccountInfo, which has groundwork for url pool functionality). If you cannot use it, inherit directly from b2sdk.v2.AbstractAccountInfo.

>>> from b2sdk.v2 import UrlPoolAccountInfo
>>> class MyAccountInfo(UrlPoolAccountInfo):
        ...

b2sdk.v2.AbstractAccountInfo describes the interface, while b2sdk.v2.UrlPoolAccountInfo and b2sdk.v2.UploadUrlPool implement a part of the interface for in-memory upload token management.

AccountInfo interface

AccountInfo helper classes

class b2sdk.account_info.upload_url_pool.UploadUrlPool[source]

For each key (either a bucket id or large file id), hold a pool of (url, auth_token) pairs.

Caution

This class is not part of the public interface. To find out how to safely use it, read this.

put(key, url, auth_token)[source]

Add the url and auth token to the pool for the given key.

Parameters
  • key (str) – bucket ID or large file ID

  • url (str) – bucket or file URL

  • auth_token (str) – authentication token

take(key)[source]

Return a (url, auth_token) if one is available, or (None, None) if not.

Parameters

key (str) – bucket ID or large file ID

Return type

tuple

clear_for_key(key)[source]

Remove an item from the pool by key.

Parameters

key (str) – bucket ID or large file ID