clibmdbx 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. clibmdbx-1.0.1/CHANGELOG.md +35 -0
  2. clibmdbx-1.0.1/CONTRIBUTING.md +20 -0
  3. clibmdbx-1.0.1/LICENSE +177 -0
  4. clibmdbx-1.0.1/MANIFEST.in +11 -0
  5. clibmdbx-1.0.1/NOTICE +9 -0
  6. clibmdbx-1.0.1/PKG-INFO +189 -0
  7. clibmdbx-1.0.1/README.md +155 -0
  8. clibmdbx-1.0.1/RELEASING.md +164 -0
  9. clibmdbx-1.0.1/SBOM.cdx.json +58 -0
  10. clibmdbx-1.0.1/SECURITY.md +23 -0
  11. clibmdbx-1.0.1/THIRD_PARTY_NOTICES.md +31 -0
  12. clibmdbx-1.0.1/VENDORING.md +33 -0
  13. clibmdbx-1.0.1/benchmarks/README.md +64 -0
  14. clibmdbx-1.0.1/benchmarks/benchmark.py +339 -0
  15. clibmdbx-1.0.1/benchmarks/check_performance.py +43 -0
  16. clibmdbx-1.0.1/benchmarks/results/review-20260829-run1.json +133 -0
  17. clibmdbx-1.0.1/benchmarks/results/review-20260829-run2.json +133 -0
  18. clibmdbx-1.0.1/benchmarks/results/review-20260829-run3.json +133 -0
  19. clibmdbx-1.0.1/benchmarks/results/review-20260829-summary.json +37 -0
  20. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-affinity-run1.json +133 -0
  21. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-affinity-run2.json +133 -0
  22. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-affinity-run3.json +133 -0
  23. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-affinity-summary.json +37 -0
  24. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-audit-run1.json +132 -0
  25. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-audit-run2.json +132 -0
  26. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-audit-run3.json +132 -0
  27. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-audit-run4.json +132 -0
  28. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-audit-run5.json +132 -0
  29. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-audit-run6.json +132 -0
  30. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-audit-summary.json +40 -0
  31. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-run1.json +132 -0
  32. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-run2.json +132 -0
  33. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-run3.json +132 -0
  34. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-summary.json +37 -0
  35. clibmdbx-1.0.1/benchmarks/results/wsl-x86_64-wtd-parity-run.json +133 -0
  36. clibmdbx-1.0.1/benchmarks/summarize.py +43 -0
  37. clibmdbx-1.0.1/docs/API.md +73 -0
  38. clibmdbx-1.0.1/docs/API_COVERAGE.md +44 -0
  39. clibmdbx-1.0.1/docs/BUILDING.md +65 -0
  40. clibmdbx-1.0.1/docs/LMDB_COMPATIBILITY.md +50 -0
  41. clibmdbx-1.0.1/docs/WTD_MDBX_PY_COMPATIBILITY.md +143 -0
  42. clibmdbx-1.0.1/pyproject.toml +82 -0
  43. clibmdbx-1.0.1/scripts/build_mdbx_chk.sh +12 -0
  44. clibmdbx-1.0.1/scripts/check_api_coverage.py +38 -0
  45. clibmdbx-1.0.1/scripts/check_release_artifacts.py +117 -0
  46. clibmdbx-1.0.1/scripts/check_release_configuration.py +47 -0
  47. clibmdbx-1.0.1/scripts/check_version.py +49 -0
  48. clibmdbx-1.0.1/scripts/check_wheel_native.py +170 -0
  49. clibmdbx-1.0.1/scripts/index_install_smoke.py +126 -0
  50. clibmdbx-1.0.1/scripts/inspect_artifacts.py +60 -0
  51. clibmdbx-1.0.1/scripts/testpypi_install.sh +11 -0
  52. clibmdbx-1.0.1/scripts/verify_index_release.py +78 -0
  53. clibmdbx-1.0.1/scripts/verify_vendor.py +61 -0
  54. clibmdbx-1.0.1/setup.cfg +4 -0
  55. clibmdbx-1.0.1/setup.py +148 -0
  56. clibmdbx-1.0.1/src/clibmdbx/__init__.py +26 -0
  57. clibmdbx-1.0.1/src/clibmdbx/__init__.pyi +275 -0
  58. clibmdbx-1.0.1/src/clibmdbx/_core.c +3782 -0
  59. clibmdbx-1.0.1/src/clibmdbx/_version.py +4 -0
  60. clibmdbx-1.0.1/src/clibmdbx/py.typed +1 -0
  61. clibmdbx-1.0.1/src/clibmdbx.egg-info/PKG-INFO +189 -0
  62. clibmdbx-1.0.1/src/clibmdbx.egg-info/SOURCES.txt +85 -0
  63. clibmdbx-1.0.1/src/clibmdbx.egg-info/dependency_links.txt +1 -0
  64. clibmdbx-1.0.1/src/clibmdbx.egg-info/requires.txt +3 -0
  65. clibmdbx-1.0.1/src/clibmdbx.egg-info/top_level.txt +1 -0
  66. clibmdbx-1.0.1/tests/conftest.py +29 -0
  67. clibmdbx-1.0.1/tests/stubtest_allowlist.txt +1 -0
  68. clibmdbx-1.0.1/tests/test_batch_random.py +56 -0
  69. clibmdbx-1.0.1/tests/test_concurrency_process.py +282 -0
  70. clibmdbx-1.0.1/tests/test_core.py +240 -0
  71. clibmdbx-1.0.1/tests/test_database_cursor.py +246 -0
  72. clibmdbx-1.0.1/tests/test_errors.py +164 -0
  73. clibmdbx-1.0.1/tests/test_recovery.py +92 -0
  74. clibmdbx-1.0.1/tests/test_release_scripts.py +158 -0
  75. clibmdbx-1.0.1/tests/test_wtdcode_interop.py +91 -0
  76. clibmdbx-1.0.1/tests/test_wtdcode_parity.py +364 -0
  77. clibmdbx-1.0.1/tests/valgrind-python.supp +8 -0
  78. clibmdbx-1.0.1/tests/valgrind_smoke.py +24 -0
  79. clibmdbx-1.0.1/vendor/libmdbx/COPYRIGHT +159 -0
  80. clibmdbx-1.0.1/vendor/libmdbx/LICENSE +177 -0
  81. clibmdbx-1.0.1/vendor/libmdbx/NOTICE +43 -0
  82. clibmdbx-1.0.1/vendor/libmdbx/VERSION.json +1 -0
  83. clibmdbx-1.0.1/vendor/libmdbx/mdbx-internals.h +3899 -0
  84. clibmdbx-1.0.1/vendor/libmdbx/mdbx-wingetopt.h +111 -0
  85. clibmdbx-1.0.1/vendor/libmdbx/mdbx.c +42791 -0
  86. clibmdbx-1.0.1/vendor/libmdbx/mdbx.h +7673 -0
  87. clibmdbx-1.0.1/vendor/libmdbx/mdbx_chk.c +679 -0
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ This project follows Semantic Versioning and PEP 440. Released versions are
4
+ immutable.
5
+
6
+ ## 1.0.1 - 2026-08-29
7
+
8
+ - Initial stable public release of the hand-written CPython C-API binding.
9
+ - Start the public version sequence at 1.0.1 by maintainer choice; 1.0.0 and
10
+ all earlier development versions were never published to a package index.
11
+ - Embed the official libmdbx 0.14.3 amalgamation.
12
+ - Add environment, transaction, DBI and cursor APIs, Python exception mapping,
13
+ C-loop batch primitives, thread affinity and post-fork rejection.
14
+ - Add randomized model testing, concurrency, crash recovery, sanitizers,
15
+ `mdbx_chk`, reproducible benchmarks and multi-platform wheel CI.
16
+ - Keep repeated database wrappers on one environment-owned native DBI; prevent
17
+ double-close, invalidate aliases after deleting drop, and invalidate handles
18
+ created by an aborted outer or nested transaction.
19
+ - Guard GIL-detached environment operations against concurrent close and defer
20
+ accidental cross-thread write finalization to the native owner thread.
21
+ - Expand native error subclasses and expose `code`, `what`, and `reason`.
22
+ - Add an independently written parity suite for all 23 collected
23
+ wtdcode/mdbx-py test scenarios and pinned two-way on-disk interoperability
24
+ tests against `libmdbx==0.3.2`.
25
+ - Expose official system RAM/page diagnostics and raise `OverflowError` for a
26
+ DB sequence increment that would exceed unsigned 64-bit storage.
27
+ - Reject unsafe scalar use of native `MDBX_RESERVE` and `MDBX_MULTIPLE`, whose
28
+ pointer/array contracts cannot be represented by the scalar Python methods.
29
+ - Harden cursor/transaction lifetime tracking around GIL-detached native calls,
30
+ including writer-owner configuration, nested transactions, cursor renewal,
31
+ cross-thread finalization and copied detached-batch results.
32
+ - Reject free-threaded CPython builds until the lifecycle model has been
33
+ redesigned and validated without the GIL.
34
+ - Add release-configuration gates for repository/security contacts and test the
35
+ exact sdist from the release workflow before any upload.
@@ -0,0 +1,20 @@
1
+ # Contributing
2
+
3
+ Changes must preserve the central property of this package: the hot path is
4
+ hand-written CPython C API code calling the vendored official libmdbx C API.
5
+ ctypes, CFFI, Cython, Rust/PyO3 and runtime loading of another libmdbx are not
6
+ accepted.
7
+
8
+ Before submitting a change:
9
+
10
+ 1. Add focused success, boundary, failure and lifetime tests.
11
+ 2. Run `python -m pytest -q` with strict compiler warnings.
12
+ 3. Run the ASan/UBSan command in `docs/BUILDING.md` for C changes.
13
+ 4. Run `mdbx_chk` against any database written by a new storage operation.
14
+ 5. Update `docs/API_COVERAGE.md` and the public type stub for API changes.
15
+ 6. Run the benchmark three times for hot-path changes and commit raw JSON only
16
+ when the workload and machine metadata are complete.
17
+
18
+ Do not commit databases, credentials, organization data, generated wheels, or
19
+ private benchmark inputs. All commits must preserve the Apache-2.0 headers and
20
+ third-party notices.
clibmdbx-1.0.1/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,11 @@
1
+ include LICENSE NOTICE README.md CHANGELOG.md SECURITY.md CONTRIBUTING.md
2
+ include THIRD_PARTY_NOTICES.md SBOM.cdx.json VENDORING.md RELEASING.md
3
+ recursive-include src *.c *.py *.pyi py.typed
4
+ recursive-include vendor/libmdbx mdbx.c mdbx.h mdbx-internals.h mdbx_chk.c mdbx-wingetopt.h LICENSE NOTICE COPYRIGHT VERSION.json
5
+ recursive-include docs *.md
6
+ recursive-include tests *.py *.supp *.txt
7
+ recursive-include benchmarks *.py *.md *.json
8
+ recursive-include scripts *.py *.sh
9
+ exclude .coverage
10
+ prune build
11
+ prune dist
clibmdbx-1.0.1/NOTICE ADDED
@@ -0,0 +1,9 @@
1
+ clibmdbx
2
+ Copyright 2026 clibmdbx contributors
3
+
4
+ This product includes libmdbx v0.14.3, Copyright 2015-2026 Leonid Yuriev
5
+ and contributors, and work derived from LMDB. See vendor/libmdbx/NOTICE and
6
+ vendor/libmdbx/COPYRIGHT for complete attribution.
7
+
8
+ clibmdbx is an independent community binding and is not an official libmdbx
9
+ project.
@@ -0,0 +1,189 @@
1
+ Metadata-Version: 2.4
2
+ Name: clibmdbx
3
+ Version: 1.0.1
4
+ Summary: High-performance CPython C-API bindings for an embedded libmdbx
5
+ Author: clibmdbx contributors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/jyj117/mdbx-py
8
+ Project-URL: Issues, https://github.com/jyj117/mdbx-py/issues
9
+ Project-URL: Changelog, https://github.com/jyj117/mdbx-py/blob/main/CHANGELOG.md
10
+ Project-URL: Upstream, https://github.com/Mithril-mine/libmdbx
11
+ Keywords: mdbx,libmdbx,database,key-value,cpython,extension
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: Microsoft :: Windows :: Windows 10
15
+ Classifier: Operating System :: MacOS :: MacOS X
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: C
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Topic :: Database :: Database Engines/Servers
25
+ Requires-Python: >=3.10
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ License-File: NOTICE
29
+ License-File: vendor/libmdbx/LICENSE
30
+ License-File: vendor/libmdbx/NOTICE
31
+ License-File: vendor/libmdbx/COPYRIGHT
32
+ Requires-Dist: typing_extensions>=4.15; python_version < "3.15"
33
+ Dynamic: license-file
34
+
35
+ # clibmdbx
36
+
37
+ `clibmdbx` is an independent, high-performance CPython binding for
38
+ [libmdbx](https://github.com/Mithril-mine/libmdbx). Both the distribution and
39
+ import name are `clibmdbx`. It is a community project and is not an official
40
+ Mithril-mine/libmdbx package.
41
+
42
+ The hot path is hand-written CPython C API code calling the libmdbx C API
43
+ directly. The extension embeds the official libmdbx 0.14.3 amalgamation, so a
44
+ wheel does not load a system `libmdbx` and has no runtime Python dependencies.
45
+ It does not use ctypes, CFFI, Cython, Rust, or a helper service.
46
+
47
+ > **Stable release:** 1.0.1 deliberately uses a CPython-version-specific ABI
48
+ > for maximum hot-path performance. Public API compatibility follows Semantic
49
+ > Versioning within the 1.x line.
50
+
51
+ ## Quick start
52
+
53
+ ```python
54
+ import clibmdbx
55
+
56
+ with clibmdbx.Environment("cache.mdbx", max_dbs=8) as env:
57
+ with env.write() as txn:
58
+ txn.put(b"answer", b"42")
59
+
60
+ with env.read() as txn:
61
+ assert txn.get(b"answer") == b"42"
62
+ assert txn[b"answer"] == b"42"
63
+ ```
64
+
65
+ Named databases, DUPSORT, cursors and batches use the same transaction model:
66
+
67
+ ```python
68
+ with env.write() as txn:
69
+ events = txn.open_db(b"events", flags=clibmdbx.MDBX_DUPSORT, create=True)
70
+ txn.put_many([(b"job", b"started"), (b"job", b"finished")], db=events)
71
+
72
+ with env.read() as txn, txn.cursor(events) as cursor:
73
+ print(cursor.set(b"job"))
74
+ print(cursor.count())
75
+ ```
76
+
77
+ All keys and values accept `bytes` or a contiguous bytes-like object. Returned
78
+ data is copied to safe `bytes`. `MDBX_RESERVE` and borrowed zero-copy views are
79
+ not exposed because their native pointers can outlive neither the write call nor
80
+ the mapped transaction safely.
81
+
82
+ ## Concurrency and lifetime rules
83
+
84
+ - An `Environment` may be shared by threads. libmdbx still permits only one
85
+ write transaction at a time per environment.
86
+ - A `Transaction` and every cursor belonging to it are bound to the thread that
87
+ created the transaction. Cross-thread use raises `ThreadError` before calling
88
+ libmdbx.
89
+ - Transactions keep their environment alive; cursors and DB handles keep their
90
+ owners alive. Closing an environment with active transactions is rejected.
91
+ A `Database.close()` closes only that Python view because repeated opens may
92
+ share one native DBI; ordinary native DBIs remain environment-owned, avoiding
93
+ upstream's double-close/concurrent-close corruption hazard. Repeated
94
+ `close()`/`abort()` is safe.
95
+ - A process created with `fork()` must open a fresh environment. Inherited
96
+ objects raise `ForkError`; their destructors intentionally do not call into
97
+ the parent's native handles.
98
+ - The current single-phase high-performance extension supports CPython's main
99
+ interpreter only. Import in a subinterpreter raises `ImportError` explicitly
100
+ rather than sharing interpreter-owned exception/type objects unsafely. Use a
101
+ separate process when interpreter isolation is required.
102
+ - `commit`, `sync`, `copy`, defragmentation and warm-up release the GIL once
103
+ around the native operation. A commit with an open cursor retains the GIL
104
+ because libmdbx updates the transaction's cursor list while committing; close
105
+ cursors first when concurrent Python progress during commit matters. Warm
106
+ point reads keep the GIL to avoid a costly
107
+ release/reacquire on every key. Batch methods cross Python/C once and loop in
108
+ C. Their default fast path retains the GIL; `detached=True` first copies every
109
+ input, then releases the GIL exactly once around the native loop. Use detached
110
+ mode for cold pages, large batches or latency-sensitive RPC thread pools.
111
+ Detached mode requires all cursors in the transaction and parent chain to be
112
+ closed, preventing cross-thread cursor finalization from racing native work.
113
+ - The wrapper always enables native `MDBX_NOSTICKYTHREADS`, then applies the
114
+ stricter Python owner-thread checks itself. Read transactions can therefore
115
+ be finalized safely by a different Python worker. libmdbx still requires a
116
+ write transaction to finish on its creator OS thread: an accidental
117
+ cross-thread final reference is marked broken and queued, never unlocked on
118
+ the wrong thread. Its owner reaps it automatically on the next environment
119
+ operation or explicitly with `env.reap_orphaned_transactions()`.
120
+ - `drop(delete=True)` is rejected while an unrelated transaction may still
121
+ reference the shared DBI. It invalidates all duplicate Python aliases after
122
+ the native delete-and-close succeeds. Creation rolled back at any nesting
123
+ level likewise invalidates its provisional aliases.
124
+
125
+ Durability defaults are upstream libmdbx defaults. Unsafe modes such as
126
+ `SAFE_NOSYNC`, `UTTERLY_NOSYNC`, `WRITEMAP`, and `NOMEMINIT` are opt-in constants;
127
+ the binding never enables them silently.
128
+
129
+ ## Major APIs
130
+
131
+ - `Environment`: geometry, options, flags, sync, consistent copy, online
132
+ defragmentation, warm-up, reader cleanup, statistics and information.
133
+ - `Transaction`: read/write/nested transactions, commit timing, abort,
134
+ reset/renew, refresh, park/unpark, canary, GC information, DB enumeration,
135
+ CRUD, replace and batch operations.
136
+ - `Database`: flags/statistics, sequence, clear/drop, close and rename.
137
+ - `Cursor`: exact/range positioning, forward/reverse and DUPSORT traversal,
138
+ count, write/delete/renew, iterator protocol and bounded range collection.
139
+ - Stable exception classes for common libmdbx failures, plus `ThreadError`,
140
+ `ForkError`, and `ClosedError` for wrapper safety checks. Native exceptions
141
+ include `code`, `what`, and `reason`, matching the diagnostic ergonomics
142
+ expected from mature LMDB bindings.
143
+
144
+ See [the complete C API coverage matrix](docs/API_COVERAGE.md),
145
+ [the API/lifecycle guide](docs/API.md),
146
+ [the wtdcode/mdbx-py ctypes compatibility audit](docs/WTD_MDBX_PY_COMPATIBILITY.md),
147
+ [the python-lmdb comparison](docs/LMDB_COMPATIBILITY.md), and
148
+ [the benchmark method](benchmarks/README.md).
149
+
150
+ ## Build and verify from source
151
+
152
+ A C11 compiler and CPython development headers are required. Builds use the
153
+ vendored source and perform no network access.
154
+
155
+ ```bash
156
+ python -m venv .venv
157
+ . .venv/bin/activate
158
+ python -m pip install -U pip build pytest twine
159
+ python -m pip install -e .
160
+ python -m pytest -q
161
+ python -m build
162
+ python -m twine check dist/*
163
+ ```
164
+
165
+ Strict warnings are enabled by default. Sanitizer builds are supported on
166
+ Clang/GCC:
167
+
168
+ ```bash
169
+ CLIBMDBX_SANITIZE=address,undefined python -m pip install -e . --no-build-isolation
170
+ ASAN_OPTIONS=detect_leaks=0:abort_on_error=1 \
171
+ UBSAN_OPTIONS=halt_on_error=1 PYTHONMALLOC=malloc python -m pytest -q
172
+ ```
173
+
174
+ For source provenance, wheel policy, release commands, and supported-platform
175
+ evidence, see [VENDORING.md](VENDORING.md), [docs/BUILDING.md](docs/BUILDING.md),
176
+ and [RELEASING.md](RELEASING.md).
177
+
178
+ ## Embedded source and license
179
+
180
+ This source tree pins official libmdbx **0.14.3**, upstream release tag
181
+ `v0.14.3`. The release tag resolves to commit
182
+ `f7a3a9323cacacfa9dc6137ae7a7252a67744ff0`; the official amalgamation records
183
+ source commit `251562b2dc55266d8e6d0e6627ec88ecb410702f`.
184
+ The official amalgamation archive SHA-256 is
185
+ `dbc4a791c44d3e51a8159eedfee0dedada7b21d46c22588f0fa99294983f33cd`.
186
+
187
+ The wrapper and libmdbx are Apache-2.0 licensed. The sdist and wheels retain the
188
+ wrapper and upstream `LICENSE`, `NOTICE`, and `COPYRIGHT`; see
189
+ [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) and [SBOM.cdx.json](SBOM.cdx.json).
@@ -0,0 +1,155 @@
1
+ # clibmdbx
2
+
3
+ `clibmdbx` is an independent, high-performance CPython binding for
4
+ [libmdbx](https://github.com/Mithril-mine/libmdbx). Both the distribution and
5
+ import name are `clibmdbx`. It is a community project and is not an official
6
+ Mithril-mine/libmdbx package.
7
+
8
+ The hot path is hand-written CPython C API code calling the libmdbx C API
9
+ directly. The extension embeds the official libmdbx 0.14.3 amalgamation, so a
10
+ wheel does not load a system `libmdbx` and has no runtime Python dependencies.
11
+ It does not use ctypes, CFFI, Cython, Rust, or a helper service.
12
+
13
+ > **Stable release:** 1.0.1 deliberately uses a CPython-version-specific ABI
14
+ > for maximum hot-path performance. Public API compatibility follows Semantic
15
+ > Versioning within the 1.x line.
16
+
17
+ ## Quick start
18
+
19
+ ```python
20
+ import clibmdbx
21
+
22
+ with clibmdbx.Environment("cache.mdbx", max_dbs=8) as env:
23
+ with env.write() as txn:
24
+ txn.put(b"answer", b"42")
25
+
26
+ with env.read() as txn:
27
+ assert txn.get(b"answer") == b"42"
28
+ assert txn[b"answer"] == b"42"
29
+ ```
30
+
31
+ Named databases, DUPSORT, cursors and batches use the same transaction model:
32
+
33
+ ```python
34
+ with env.write() as txn:
35
+ events = txn.open_db(b"events", flags=clibmdbx.MDBX_DUPSORT, create=True)
36
+ txn.put_many([(b"job", b"started"), (b"job", b"finished")], db=events)
37
+
38
+ with env.read() as txn, txn.cursor(events) as cursor:
39
+ print(cursor.set(b"job"))
40
+ print(cursor.count())
41
+ ```
42
+
43
+ All keys and values accept `bytes` or a contiguous bytes-like object. Returned
44
+ data is copied to safe `bytes`. `MDBX_RESERVE` and borrowed zero-copy views are
45
+ not exposed because their native pointers can outlive neither the write call nor
46
+ the mapped transaction safely.
47
+
48
+ ## Concurrency and lifetime rules
49
+
50
+ - An `Environment` may be shared by threads. libmdbx still permits only one
51
+ write transaction at a time per environment.
52
+ - A `Transaction` and every cursor belonging to it are bound to the thread that
53
+ created the transaction. Cross-thread use raises `ThreadError` before calling
54
+ libmdbx.
55
+ - Transactions keep their environment alive; cursors and DB handles keep their
56
+ owners alive. Closing an environment with active transactions is rejected.
57
+ A `Database.close()` closes only that Python view because repeated opens may
58
+ share one native DBI; ordinary native DBIs remain environment-owned, avoiding
59
+ upstream's double-close/concurrent-close corruption hazard. Repeated
60
+ `close()`/`abort()` is safe.
61
+ - A process created with `fork()` must open a fresh environment. Inherited
62
+ objects raise `ForkError`; their destructors intentionally do not call into
63
+ the parent's native handles.
64
+ - The current single-phase high-performance extension supports CPython's main
65
+ interpreter only. Import in a subinterpreter raises `ImportError` explicitly
66
+ rather than sharing interpreter-owned exception/type objects unsafely. Use a
67
+ separate process when interpreter isolation is required.
68
+ - `commit`, `sync`, `copy`, defragmentation and warm-up release the GIL once
69
+ around the native operation. A commit with an open cursor retains the GIL
70
+ because libmdbx updates the transaction's cursor list while committing; close
71
+ cursors first when concurrent Python progress during commit matters. Warm
72
+ point reads keep the GIL to avoid a costly
73
+ release/reacquire on every key. Batch methods cross Python/C once and loop in
74
+ C. Their default fast path retains the GIL; `detached=True` first copies every
75
+ input, then releases the GIL exactly once around the native loop. Use detached
76
+ mode for cold pages, large batches or latency-sensitive RPC thread pools.
77
+ Detached mode requires all cursors in the transaction and parent chain to be
78
+ closed, preventing cross-thread cursor finalization from racing native work.
79
+ - The wrapper always enables native `MDBX_NOSTICKYTHREADS`, then applies the
80
+ stricter Python owner-thread checks itself. Read transactions can therefore
81
+ be finalized safely by a different Python worker. libmdbx still requires a
82
+ write transaction to finish on its creator OS thread: an accidental
83
+ cross-thread final reference is marked broken and queued, never unlocked on
84
+ the wrong thread. Its owner reaps it automatically on the next environment
85
+ operation or explicitly with `env.reap_orphaned_transactions()`.
86
+ - `drop(delete=True)` is rejected while an unrelated transaction may still
87
+ reference the shared DBI. It invalidates all duplicate Python aliases after
88
+ the native delete-and-close succeeds. Creation rolled back at any nesting
89
+ level likewise invalidates its provisional aliases.
90
+
91
+ Durability defaults are upstream libmdbx defaults. Unsafe modes such as
92
+ `SAFE_NOSYNC`, `UTTERLY_NOSYNC`, `WRITEMAP`, and `NOMEMINIT` are opt-in constants;
93
+ the binding never enables them silently.
94
+
95
+ ## Major APIs
96
+
97
+ - `Environment`: geometry, options, flags, sync, consistent copy, online
98
+ defragmentation, warm-up, reader cleanup, statistics and information.
99
+ - `Transaction`: read/write/nested transactions, commit timing, abort,
100
+ reset/renew, refresh, park/unpark, canary, GC information, DB enumeration,
101
+ CRUD, replace and batch operations.
102
+ - `Database`: flags/statistics, sequence, clear/drop, close and rename.
103
+ - `Cursor`: exact/range positioning, forward/reverse and DUPSORT traversal,
104
+ count, write/delete/renew, iterator protocol and bounded range collection.
105
+ - Stable exception classes for common libmdbx failures, plus `ThreadError`,
106
+ `ForkError`, and `ClosedError` for wrapper safety checks. Native exceptions
107
+ include `code`, `what`, and `reason`, matching the diagnostic ergonomics
108
+ expected from mature LMDB bindings.
109
+
110
+ See [the complete C API coverage matrix](docs/API_COVERAGE.md),
111
+ [the API/lifecycle guide](docs/API.md),
112
+ [the wtdcode/mdbx-py ctypes compatibility audit](docs/WTD_MDBX_PY_COMPATIBILITY.md),
113
+ [the python-lmdb comparison](docs/LMDB_COMPATIBILITY.md), and
114
+ [the benchmark method](benchmarks/README.md).
115
+
116
+ ## Build and verify from source
117
+
118
+ A C11 compiler and CPython development headers are required. Builds use the
119
+ vendored source and perform no network access.
120
+
121
+ ```bash
122
+ python -m venv .venv
123
+ . .venv/bin/activate
124
+ python -m pip install -U pip build pytest twine
125
+ python -m pip install -e .
126
+ python -m pytest -q
127
+ python -m build
128
+ python -m twine check dist/*
129
+ ```
130
+
131
+ Strict warnings are enabled by default. Sanitizer builds are supported on
132
+ Clang/GCC:
133
+
134
+ ```bash
135
+ CLIBMDBX_SANITIZE=address,undefined python -m pip install -e . --no-build-isolation
136
+ ASAN_OPTIONS=detect_leaks=0:abort_on_error=1 \
137
+ UBSAN_OPTIONS=halt_on_error=1 PYTHONMALLOC=malloc python -m pytest -q
138
+ ```
139
+
140
+ For source provenance, wheel policy, release commands, and supported-platform
141
+ evidence, see [VENDORING.md](VENDORING.md), [docs/BUILDING.md](docs/BUILDING.md),
142
+ and [RELEASING.md](RELEASING.md).
143
+
144
+ ## Embedded source and license
145
+
146
+ This source tree pins official libmdbx **0.14.3**, upstream release tag
147
+ `v0.14.3`. The release tag resolves to commit
148
+ `f7a3a9323cacacfa9dc6137ae7a7252a67744ff0`; the official amalgamation records
149
+ source commit `251562b2dc55266d8e6d0e6627ec88ecb410702f`.
150
+ The official amalgamation archive SHA-256 is
151
+ `dbc4a791c44d3e51a8159eedfee0dedada7b21d46c22588f0fa99294983f33cd`.
152
+
153
+ The wrapper and libmdbx are Apache-2.0 licensed. The sdist and wheels retain the
154
+ wrapper and upstream `LICENSE`, `NOTICE`, and `COPYRIGHT`; see
155
+ [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) and [SBOM.cdx.json](SBOM.cdx.json).