8
8
9
9
--------------
10
10
11
- :mod: `dbm ` is a generic interface to variants of the DBM database ---
12
- :mod: `dbm.gnu ` or :mod: `dbm.ndbm `. If none of these modules is installed, the
11
+ :mod: `dbm ` is a generic interface to variants of the DBM database:
12
+
13
+ * :mod: `dbm.sqlite3 `
14
+ * :mod: `dbm.gnu `
15
+ * :mod: `dbm.ndbm `
16
+
17
+ If none of these modules are installed, the
13
18
slow-but-simple implementation in module :mod: `dbm.dumb ` will be used. There
14
19
is a `third party interface <https://www.jcea.es/programacion/pybsddb.htm >`_ to
15
20
the Oracle Berkeley DB.
@@ -25,8 +30,8 @@ the Oracle Berkeley DB.
25
30
.. function :: whichdb(filename)
26
31
27
32
This function attempts to guess which of the several simple database modules
28
- available --- :mod: `dbm.gnu `, :mod: `dbm.ndbm ` or :mod: `dbm.dumb ` --- should
29
- be used to open a given file.
33
+ available --- :mod: `dbm.sqlite3 `, :mod: `dbm.gnu `, :mod: `dbm.ndbm `,
34
+ or :mod: ` dbm.dumb ` --- should be used to open a given file.
30
35
31
36
Return one of the following values:
32
37
@@ -56,10 +61,6 @@ the Oracle Berkeley DB.
56
61
The Unix file access mode of the file (default: octal ``0o666``),
57
62
used only when the database has to be created.
58
63
59
- .. |incompat_note | replace ::
60
- The file formats created by :mod: `dbm.gnu` and :mod:`dbm.ndbm` are incompatible
61
- and can not be used interchangeably.
62
-
63
64
.. function :: open(file, flag='r', mode=0o666)
64
65
65
66
Open a database and return the corresponding database object.
@@ -144,6 +145,46 @@ then prints out the contents of the database::
144
145
145
146
The individual submodules are described in the following sections.
146
147
148
+ :mod: `dbm.sqlite3 ` --- SQLite backend for dbm
149
+ ---------------------------------------------
150
+
151
+ .. module :: dbm.sqlite3
152
+ :platform: All
153
+ :synopsis: SQLite backend for dbm
154
+
155
+ .. versionadded :: 3.13
156
+
157
+ **Source code: ** :source: `Lib/dbm/sqlite3.py `
158
+
159
+ --------------
160
+
161
+ This module uses the standard library :mod: `sqlite3 ` module to provide an
162
+ SQLite backend for the :mod: `dbm ` module.
163
+ The files created by :mod: `dbm.sqlite3 ` can thus be opened by :mod: `sqlite3 `,
164
+ or any other SQLite browser, including the SQLite CLI.
165
+
166
+ .. function :: open(filename, /, flag="r", mode=0o666)
167
+
168
+ Open an SQLite database.
169
+ The returned object behaves like a :term: `mapping `,
170
+ implements a :meth: `!close ` method,
171
+ and supports a "closing" context manager via the :keyword: `with ` keyword.
172
+
173
+ :param filename:
174
+ The path to the database to be opened.
175
+ :type filename: :term: `path-like object `
176
+
177
+ :param str flag:
178
+
179
+ * ``'r' `` (default): |flag_r |
180
+ * ``'w' ``: |flag_w |
181
+ * ``'c' ``: |flag_c |
182
+ * ``'n' ``: |flag_n |
183
+
184
+ :param mode:
185
+ The Unix file access mode of the file (default: octal ``0o666 ``),
186
+ used only when the database has to be created.
187
+
147
188
148
189
:mod: `dbm.gnu ` --- GNU database manager
149
190
---------------------------------------
@@ -160,11 +201,10 @@ The :mod:`dbm.gnu` module provides an interface to the :abbr:`GDBM (GNU dbm)`
160
201
library, similar to the :mod: `dbm.ndbm ` module, but with additional
161
202
functionality like crash tolerance.
162
203
163
- :class: `!gdbm ` objects behave similar to :term: `mappings <mapping> `,
164
- except that keys and values are always converted to :class: `bytes ` before storing,
165
- and the :meth: `!items ` and :meth: `!values ` methods are not supported.
204
+ .. note ::
166
205
167
- .. note :: |incompat_note|
206
+ The file formats created by :mod: `dbm.gnu ` and :mod: `dbm.ndbm ` are incompatible
207
+ and can not be used interchangeably.
168
208
169
209
.. exception :: error
170
210
@@ -211,8 +251,9 @@ and the :meth:`!items` and :meth:`!values` methods are not supported.
211
251
212
252
A string of characters the *flag * parameter of :meth: `~dbm.gnu.open ` supports.
213
253
214
- In addition to the dictionary-like methods, :class: `gdbm ` objects have the
215
- following methods and attributes:
254
+ :class: `!gdbm ` objects behave similar to :term: `mappings <mapping> `,
255
+ but :meth: `!items ` and :meth: `!values ` methods are not supported.
256
+ The following methods are also provided:
216
257
217
258
.. method :: gdbm.firstkey()
218
259
@@ -269,14 +310,13 @@ and the :meth:`!items` and :meth:`!values` methods are not supported.
269
310
270
311
The :mod: `dbm.ndbm ` module provides an interface to the
271
312
:abbr: `NDBM ( New Database Manager ) ` library.
272
- :class: `!ndbm ` objects behave similar to :term: `mappings <mapping> `,
273
- except that keys and values are always stored as :class: `bytes `,
274
- and the :meth: `!items ` and :meth: `!values ` methods are not supported.
275
-
276
313
This module can be used with the "classic" NDBM interface or the
277
314
:abbr: `GDBM ( GNU dbm ) ` compatibility interface.
278
315
279
- .. note :: |incompat_note|
316
+ .. note ::
317
+
318
+ The file formats created by :mod: `dbm.gnu ` and :mod: `dbm.ndbm ` are incompatible
319
+ and can not be used interchangeably.
280
320
281
321
.. warning ::
282
322
@@ -314,8 +354,9 @@ This module can be used with the "classic" NDBM interface or the
314
354
:param int mode:
315
355
|mode_param_doc |
316
356
317
- In addition to the dictionary-like methods, :class: `!ndbm ` objects
318
- provide the following method:
357
+ :class: `!ndbm ` objects behave similar to :term: `mappings <mapping> `,
358
+ but :meth: `!items ` and :meth: `!values ` methods are not supported.
359
+ The following methods are also provided:
319
360
320
361
.. versionchanged :: 3.11
321
362
Accepts :term: `path-like object ` for filename.
@@ -354,8 +395,6 @@ The :mod:`dbm.dumb` module provides a persistent :class:`dict`-like
354
395
interface which is written entirely in Python.
355
396
Unlike other :mod: `dbm ` backends, such as :mod: `dbm.gnu `, no
356
397
external library is required.
357
- As with other :mod: `dbm ` backends,
358
- the keys and values are always stored as :class: `bytes `.
359
398
360
399
The :mod: `!dbm.dumb ` module defines the following:
361
400
0 commit comments