AccountInfo¶
AccountInfo stores basic information about the account, such as Application Key ID and Application Key,
in order to let b2sdk.v1.B2Api
perform authenticated requests.
There are two usable implementations provided by b2sdk:
b2sdk.v1.InMemoryAccountInfo
- a basic implementation with no persistence
b2sdk.v1.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.
-
class
b2sdk.v1.
InMemoryAccountInfo
[source]¶ Implements all methods of AccountInfo interface.
Hint
Usage of this class is appropriate for secure Web applications which do not wish to persist any user data.
Using this class for applications such as CLI, GUI or backup is discouraged, as
InMemoryAccountInfo
does not write down the authorization token persistently. That would be slow, as it would force the application to retrieve a new one on every command/click/backup start. Furthermore - an important property of AccountInfo is caching thebucket_name:bucket_id
mapping; in case ofInMemoryAccountInfo
the cache will be flushed between executions of the program.
SqliteAccountInfo¶
-
class
b2sdk.v1.
SqliteAccountInfo
[source]¶ Implements all methods of AccountInfo interface.
Uses a SQLite database for persistence and access synchronization between multiple processes. Not suitable for usage over NFS.
Underlying database has the following schema:
Hint
Usage of this class is appropriate for interactive applications installed on a user’s machine (i.e.: CLI and GUI applications).
Usage of this class might be appropriate for non-interactive applications installed on the user’s machine, such as backup applications. An alternative approach that should be considered is to store the AccountInfo data alongside the configuration of the rest of the application.
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.v1.UrlPoolAccountInfo
, which has groundwork for url pool functionality). If you cannot use it, inherit directly from b2sdk.v1.AbstractAccountInfo
.
>>> from b2sdk.v1 import UrlPoolAccountInfo
>>> class MyAccountInfo(UrlPoolAccountInfo):
...
b2sdk.v1.AbstractAccountInfo
describes the interface, while b2sdk.v1.UrlPoolAccountInfo
and b2sdk.v1.UploadUrlPool
implement a part of the interface for in-memory upload token management.
AccountInfo interface¶
AccountInfo helper classes¶
-
class
b2sdk.v1.
UrlPoolAccountInfo
[source]¶ Caution
This class is not part of the public interface. To find out how to safely use it, read this.
-
BUCKET_UPLOAD_POOL_CLASS
¶ A url pool class to use for small files.
-
LARGE_FILE_UPLOAD_POOL_CLASS
¶ A url pool class to use for large files.
-
-
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.