BTrees
Scalable persistent object containers
What it is and what it does
BTrees is a library of persistent container objects built around a modified B-tree data structure, designed to work inside ZODB's optimistic concurrency paradigm. It provides scalable alternatives to standard Python dictionaries and sets that can be stored in a ZODB database, with explicit conflict resolution when concurrent transactions detect conflicts.
The package includes multiple tree variants (OOBTree for object-to-object mappings, IOBTree for integer keys, etc.) and corresponding set types, all optimized for the transactional semantics of ZODB. It depends on persistent (for the base persistent object protocol) and zope.interface (for interface definitions), and is maintained as part of the Zope Foundation ecosystem.
Use it for:
- Store large, mutable mappings in ZODB that scale better than in-memory dicts for concurrent multi-user applications.
- Build conflict-aware data structures in ZODB that automatically resolve concurrent modifications without manual locking.
- Implement persistent sets and ordered collections in a ZODB database with efficient range queries and iteration.
- Replace standard Python containers in long-lived ZODB transactions where memory efficiency and conflict handling matter.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
BTrees provides persistent, scalable B-tree data structures optimized for ZODB's optimistic concurrency model, with built-in conflict resolution for concurrent access.
Yes, if you are using ZODB and need scalable persistent containers with built-in conflict resolution. The package is mature, actively maintained, and has no known vulnerabilities. Install friction is moderate due to C extension compilation, but wheels are provided for current Python versions. Verify ZPL-2.1 license compatibility before adoption.
Install
btrees on PyPI
pip
pip install btreesuv
uv add btreespoetry
poetry add btreesInstalling BTrees
Before you install
Medium install friction due to compiled C extensions across multiple platforms (wheels provided for Python 3.10–3.14 on macOS, Linux, and Windows). Active maintenance with recent release (107 days ago) and ongoing platform support additions.
License in practice
Licensed under ZPL-2.1 (Zope Public License 2.1); license treatment marked unclear in metadata, so verify compatibility with your project's licensing requirements before use.
Quickstart
pip install btrees
from BTrees.OOBTree import OOBTree
from persistent import Persistent
tree = OOBTree()
tree['key'] = 'value'
Requires Python 3.10 or later; C extensions will compile on install if wheels are unavailable for your platform.
Verify before relying
- Actual performance characteristics and scalability limits compared to standard Python dicts or other persistent stores.
- Whether the C extension is required or if pure Python fallback is acceptable for your use case.
- Specific ZODB version compatibility and integration patterns beyond basic container usage.
Package facts
| License | ZPL-2.1 (unclear) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 2 — persistent, zope.interface |
| Maintenance | actively maintained — 107 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 348,006/month — #7,345 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: btrees-6.4-cp310-cp310-macosx_10_9_x86_64.whl; btrees-6.4-cp310-cp310-macosx_11_0_arm64.whl; btrees-6.4-cp310-cp310-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl; btrees-6.4-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; btrees-6.4-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; btrees-6.4-cp310-cp310-win_amd64.whl; btrees-6.4-cp311-cp311-macosx_10_9_x86_64.whl; btrees-6.4-cp311-cp311-macosx_11_0_arm64.whl; btrees-6.4-cp311-cp311-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl; btrees-6.4-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; btrees-6.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; btrees-6.4-cp311-cp311-win_amd64.whl; btrees-6.4-cp311-cp311-win_arm64.whl; btrees-6.4-cp312-cp312-macosx_10_9_x86_64.whl; btrees-6.4-cp312-cp312-macosx_11_0_arm64.whl; btrees-6.4-cp312-cp312-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl; btrees-6.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; btrees-6.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; btrees-6.4-cp312-cp312-win_amd64.whl; btrees-6.4-cp312-cp312-win_arm64.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
zope.containerProvides container interfaces and…
unclear · top 15,000 on PyPI
persistentProvides transparent persistence for Python…
unclear · top 15,000 on PyPI
ZODBZODB is an object-oriented database for Python…
unclear · top 15,000 on PyPI
zope.annotationStores additional metadata on objects without…
unclear · top 15,000 on PyPI
transactionProvides a generic transaction management…
unclear · top 5,000 on PyPI
PersistenceProvides a persistent base class built on…
unclear · top 15,000 on PyPI
zc.lockfileProvides portable inter-process locks…
unclear · top 5,000 on PyPI
rtreeRtree wraps libspatialindex to provide spatial…
permissive · top 5,000 on PyPI
nutreeNutree provides a Python library for creating,…
permissive · top 5,000 on PyPI
zodbpickleProvides a ZODB-compatible pickle interface…
unclear · top 15,000 on PyPI