Skip to main content

A lightweight document storage system with SQLAlchemy dialect support. Where your data or honey, hibernates.

Project description

🐻📚 Bear-Shelf

pypi version

The shelf where your data hibernates. 🐻💤

A lightweight document storage system with SQLAlchemy dialect support. Store your data in JSONL, JSON, TOML, YAML, XML, MessagePack, or in-memory formats with a clean, type-safe interface — no SQLite required.

Features

  • 🔌 SQLAlchemy Integration: A real SQLAlchemy dialect — use familiar ORM syntax over plain files
  • 📦 Multiple Backends: JSONL (default), JSON, TOML, YAML, XML, MessagePack, or in-memory
  • 🧰 Two Front Doors: Use the raw bearshelf:// dialect, or the batteries-included DatabaseManager API
  • 🔒 Type-Safe: Full type hints, Pydantic models, and custom column types (Mapped[Path], Mapped[EpochTimestamp])
  • 📝 Write-Ahead Logging: Optional WAL with buffered/immediate flush modes for durability and bulk-write speed
  • Compiled Core: Hot paths implemented in C++23 (pybind11) and Cython (Goal is to only have it in C++)

Installation

With uv:

uv add bear-shelf
# or
uv pip install bear-shelf

Minimum Python: 3.12.

Quick Start

Bear-Shelf gives you two equally first-class ways to work with your data. Pick whichever fits how you think.

Option A — Raw SQLAlchemy dialect

If you already know SQLAlchemy, just point an engine at a file. The backend is chosen by the file extension.

from sqlalchemy import create_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, Session

engine = create_engine("bearshelf:///path/to/users.jsonl")

class Base(DeclarativeBase): ...

class User(Base):
    __tablename__ = "users"
    id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
    name: Mapped[str]
    email: Mapped[str] = mapped_column(unique=True)

Base.metadata.create_all(engine)

with Session(engine) as session:
    session.add(User(name="Bear", email="bear@shelf.com"))
    session.commit()

Option B — DatabaseManager API

A higher-level wrapper that handles the engine, sessions, and table registration for you, and returns convenient per-table handles.

from pathlib import Path
from sqlalchemy.orm import Mapped, mapped_column
from bear_shelf.database import BearShelfDB

# get_base() returns a declarative base wired with Bear-Shelf's custom types
Base = BearShelfDB.get_base()

class User(Base):
    __tablename__ = "users"
    id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
    name: Mapped[str]
    config_path: Mapped[Path]            # stored as text, returned as a Path

db = BearShelfDB(path="users.jsonl")

# Build only the tables you want; bare create_tables() builds them all.
db.include(User).create_tables()

with db.open_session() as session:
    session.add(User(name="Bear", config_path=Path("~/cfg.toml")))

users = db.get_all(User)                 # [User(name='Bear', ...)]
count = db.count(User)                   # 1
db.close()

include(*models) is handy when one declarative base defines many tables but a given database should only create a subset (e.g. test isolation). Creating a subset whose foreign keys reference tables you left out fails loudly with a message telling you what to add.

🎨 Custom Column Types

Annotate columns with rich Python types and Bear-Shelf converts them at the storage boundary — no manual (de)serialization:

Annotation Stored as Returned as
Mapped[Path] text pathlib.Path
Mapped[EpochTimestamp] integer bear_epoch_time.EpochTimestamp

These are registered on the base returned by BearShelfDB.get_base().

🎯 Storage Backends

The backend is auto-detected from the file extension (or pass storage=/schema=):

Backend URL / extension
JSONL (default) bearshelf:///data.jsonl
JSON bearshelf:///data.json
TOML bearshelf:///data.toml
YAML bearshelf:///data.yaml
XML bearshelf:///data.xml
MessagePack bearshelf:///data.msgpack
Memory bearshelf:///:memory:

📝 Write-Ahead Logging

For bulk writes and crash safety, enable WAL. In BUFFERED mode, inserts append to a log and a background thread checkpoints to the main file — turning thousands of slow full-file rewrites into fast appends.

from bear_shelf.datastore import BearBase, Columns
from bear_shelf.datastore.wal.config import WALConfig

db = BearBase(
    "events.json",
    storage="json",
    enable_wal=True,
    wal_config=WALConfig.high_throughput(),   # or .immediate() for fsync-per-op
)

db.create_table("events", columns=[
    Columns(name="id", type="int", primary_key=True),
    Columns(name="event_type", type="str"),
])

table = db.table("events")
table.insert_all([{"id": i, "event_type": "click"} for i in range(5000)])
db.close()

See examples/wal_example.py for buffered/immediate modes, custom tuning, manual checkpointing, and crash recovery, and examples/foreign_key_example.py for relationships.

🐻 About

Built with ❤️ by Bear. Part of the Bear-verse ecosystem:

  • funcy_bear: functional programming & type introspection utilities
  • bear-epoch-time: precision-aware timestamp handling
  • codec_cub: Codec utilties for the various storages used in Bear Shelf

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bear_shelf-0.3.29-cp314-cp314-win_amd64.whl (152.8 kB view details)

Uploaded CPython 3.14Windows x86-64

bear_shelf-0.3.29-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

bear_shelf-0.3.29-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (2.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

bear_shelf-0.3.29-cp314-cp314-macosx_11_0_arm64.whl (380.0 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

bear_shelf-0.3.29-cp313-cp313-win_amd64.whl (153.1 kB view details)

Uploaded CPython 3.13Windows x86-64

bear_shelf-0.3.29-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

bear_shelf-0.3.29-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (2.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

bear_shelf-0.3.29-cp313-cp313-macosx_11_0_arm64.whl (379.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

bear_shelf-0.3.29-cp312-cp312-win_amd64.whl (153.1 kB view details)

Uploaded CPython 3.12Windows x86-64

bear_shelf-0.3.29-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

bear_shelf-0.3.29-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (2.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

bear_shelf-0.3.29-cp312-cp312-macosx_11_0_arm64.whl (380.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file bear_shelf-0.3.29-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: bear_shelf-0.3.29-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 152.8 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bear_shelf-0.3.29-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 79b1bb79a16af7e8b5ff2c9016a0b2d8bea1ebf9ae3939926812b1603a3494ba
MD5 169eda443418d47cea3683a37d4e418b
BLAKE2b-256 e515d5acc93f636d42e628e4186fa3391a332757779d674108f4a3265245410b

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp314-cp314-win_amd64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bear_shelf-0.3.29-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.29-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 909c9671e55bed5aa4f3de7f400da7f2f0298b28f77209c88646f3f5a5a05849
MD5 7d8a9f00b6b609e490c1589c2f1f63f4
BLAKE2b-256 4039234e0c95f6b0d01d750f527927447862dd0a3e8e9db3aa465c241bd3bf03

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bear_shelf-0.3.29-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.29-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 48ba21b20f1241a839ceba77c251697415218eea70935f9244fdd9787035f3d8
MD5 ace2ebd750710e37a7c1c9b139c78fd4
BLAKE2b-256 edd03d4a45b6b04e58e5cdf3503c4763d03406faeaa78f199d29aeb4d5c99253

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bear_shelf-0.3.29-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.29-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 482f1a182c3fc21ca699b1ed5187681f40a8aed0ac226594b163ce43d05700ad
MD5 05cd47eec34988409f5ded59037cc93f
BLAKE2b-256 99ecd76dfb3651ca2f27146c48698eacacffda092086f0638771a70c3b997c86

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bear_shelf-0.3.29-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: bear_shelf-0.3.29-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 153.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bear_shelf-0.3.29-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2ea75210571638d6005265db941c0f59aa31f11152da7c160cb628762fa42a9d
MD5 5580cc7f4fe940cf0119c101e3bb58e3
BLAKE2b-256 ee24aaff41aaad4cafea4fbab40657c65a0a759ae7e06d2f4eb96776e1d295a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp313-cp313-win_amd64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bear_shelf-0.3.29-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.29-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c7ec188c5bfafdd90bfd4d6ced8b30a4b016ad5906f557ba73f1eca661cc9b9d
MD5 e4efcdcd5276825bdd67fff3ffa756c5
BLAKE2b-256 c1481e193d76a3fedb3a48371ed08c2416511c6a0fbfbe63c143c6688a704bf6

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bear_shelf-0.3.29-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.29-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 651a9e56ec434707061ce99d3062b44b1933c840c4b72791c833be99a4a3b778
MD5 0cbb3d1cd84e3cff9fa8a331e647481f
BLAKE2b-256 ef340adf6d105b52c1eb8127046a6b4bffacbb49d9d00ac16447468bf2e516a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bear_shelf-0.3.29-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.29-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 212a356de255ce95f24fc6b3e4e893194a7dc1499b1681bf6668ad2b8d2c198d
MD5 555d02c4f34835e67a13e24f46ce0ec1
BLAKE2b-256 011acf9cb11f95ac188ecf92a35e8e0978c1ebe098a7ec7c82ed8d77edfab78c

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bear_shelf-0.3.29-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: bear_shelf-0.3.29-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 153.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bear_shelf-0.3.29-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e59571ee12c728934d83140f64bee334e3b7a8f265aeedb30edcedf3140e5138
MD5 a833d573e5a5ea0b0ebf1d253f042603
BLAKE2b-256 d32d921e2f6f7b694f80df14570663fe7d6ac43010ad67ac956f220fe0e626d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp312-cp312-win_amd64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bear_shelf-0.3.29-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.29-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 36b3a6164523990dcf2a6a0788aed7b2f12a7d171d3f2682d9187fc11e88bcb9
MD5 888473f8a108220bbffba1bb93021eac
BLAKE2b-256 950b22b3e29c886c7a01ce82a5892970f307b5d1501def8ec1fbc2fb4bd2652d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bear_shelf-0.3.29-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.29-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 875eaabffad9494582fa6a47652f3aa1042003ff5ab2eee7de57a464db9757ce
MD5 40cc5d0afa3bd5455b3ce6f780b6e4c0
BLAKE2b-256 7d15c1257129c55b545008c5d5534010f4ea5faf595a5401153471928eed815d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bear_shelf-0.3.29-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.29-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7684da259b415cd5d57b8813d473d889e3a1fe39acc8a028a464e1e782f392b7
MD5 7f40223eef474a59428cc322e104622e
BLAKE2b-256 904cd1edb0e292b87cc11777accffcbb08077940a81f4f7a856edb8c54b483f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.29-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-shelf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page