File: account_info.rst

package info (click to toggle)
python-b2sdk 2.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,020 kB
  • sloc: python: 30,902; sh: 13; makefile: 8
file content (115 lines) | stat: -rw-r--r-- 4,411 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
.. _AccountInfo:

########################
AccountInfo
########################

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

There are two usable implementations provided by **b2sdk**:

 * :py:class:`b2sdk.v2.InMemoryAccountInfo` - a basic implementation with no persistence
 * :py:class:`b2sdk.v2.SqliteAccountInfo` - for console and GUI applications

They both provide the full :ref:`AccountInfo interface <account_info_interface>`.

.. note::
   Backup applications and many server-side applications should :ref:`implement their own <my_account_info>` *AccountInfo*, backed by the metadata/configuration database of the application.


***************************
AccountInfo implementations
***************************

InMemoryAccountInfo
===================

*AccountInfo* with no persistence.

.. autoclass:: b2sdk.v2.InMemoryAccountInfo()
   :no-members:

   Implements all methods of :ref:`AccountInfo interface <account_info_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 the ``bucket_name:bucket_id`` mapping; in case of ``InMemoryAccountInfo`` the cache will be flushed between executions of the program.

   .. method:: __init__()

      The constructor takes no parameters.


SqliteAccountInfo
=================

.. autoclass:: b2sdk.v2.SqliteAccountInfo()
   :inherited-members:
   :no-members:
   :special-members: __init__

   Implements all methods of :ref:`AccountInfo interface <account_info_interface>`.

   Uses a `SQLite database <https://www.sqlite.org/index.html>`_ for persistence
   and access synchronization between multiple processes. Not suitable for usage over NFS.

   Underlying database has the following schema:

   .. graphviz:: /dot/sqlite_account_info_schema.dot

   .. 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.


.. _my_account_info:

*********************
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 :py:class:`b2sdk.v2.UrlPoolAccountInfo`, which has groundwork for url pool functionality). If you cannot use it, inherit directly from :py:class:`b2sdk.v2.AbstractAccountInfo`.

.. code-block:: python

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


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


.. _account_info_interface:

AccountInfo interface
=====================

.. autoclass:: b2sdk.v2.AbstractAccountInfo()
   :inherited-members:
   :private-members:
   :exclude-members: _abc_cache, _abc_negative_cache, _abc_negative_cache_version, _abc_registry


AccountInfo helper classes
==========================

.. autoclass:: b2sdk.v2.UrlPoolAccountInfo()
   :inherited-members:
   :no-members:
   :members: BUCKET_UPLOAD_POOL_CLASS, LARGE_FILE_UPLOAD_POOL_CLASS

   .. caution::
      This class is not part of the public interface. To find out how to safely use it, read :ref:`this <semantic_versioning>`.

.. autoclass:: b2sdk._internal.account_info.upload_url_pool.UploadUrlPool()
   :inherited-members:
   :private-members:

   .. caution::
      This class is not part of the public interface. To find out how to safely use it, read :ref:`this <semantic_versioning>`.