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.33-cp314-cp314-win_amd64.whl (157.1 kB view details)

Uploaded CPython 3.14Windows x86-64

bear_shelf-0.3.33-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.33-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.33-cp314-cp314-macosx_11_0_arm64.whl (385.0 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

bear_shelf-0.3.33-cp313-cp313-win_amd64.whl (157.4 kB view details)

Uploaded CPython 3.13Windows x86-64

bear_shelf-0.3.33-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.33-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.33-cp313-cp313-macosx_11_0_arm64.whl (384.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: bear_shelf-0.3.33-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 157.1 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.33-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 fcfb3ab97f0597b45d1e8f941c2badd3c51beeece6978f77b080be670960a4da
MD5 21ff628b636f9e3b1d19a3a640d9073f
BLAKE2b-256 6411f55a9169d65d9c09ec167f94874b54c717682cab0188324d911fda1e0c2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.33-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.33-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.33-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8e12cf2a2fc12262dfa3d0ec71d661a2a216a14f1bbd0d6b61180e83721ef669
MD5 2184fb8d0602ae3b591fab524b57994a
BLAKE2b-256 cdccd6b5510e87e1a600d2bd0ca93b6257ea9bc609353d4e6e0bbde5436c2356

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.33-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.33-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.33-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ef4ce5441a5fddaeaad4590d517750586435c480d070181c4e572a9de3637d49
MD5 0b7c829b95564123c9a292d71318709c
BLAKE2b-256 03dbc6cdefc4828d41f39970f4536b4bc2aba4c6031caee053e3e005b58446c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.33-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.33-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.33-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e47f46b3b92e40b79701fbf91c694f531875f0c4f6097bc913bfe3fa4494925a
MD5 f32142a068692e53982a6f08828df24c
BLAKE2b-256 acaaea831bbdcadca94678d6d79c86de5b35f17a37d743b34a34172b3ae18fd0

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.33-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.33-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: bear_shelf-0.3.33-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 157.4 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.33-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 76788e0c4c90946fa2d441e615f7bad2b070ed7e30e1913dafdc907e1e63072b
MD5 e040249101cb6e4b0eb501ad2d476eb8
BLAKE2b-256 c4994b39437e38c8973cc18dd625e7c7c75477772427929f68b5ebfe90074153

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.33-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.33-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.33-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6b889a5cc1589997adfb5117f061f13b32fecf3deda1d4c44e9163e64f9a0275
MD5 343b1ce9fc02f4c242b830dbd3565e6e
BLAKE2b-256 3a5dbbc007d7114569baca460ed0d7dedc576d46a08974ff3ec71d2e93fcaef4

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.33-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.33-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.33-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0a426a6788a767a5fdd0cb7bd0ed4630a2bdb0c82776c5f626c56b5ed76d8b82
MD5 f47244c65ff72ad0db6726c5ffd58a19
BLAKE2b-256 c25b809e9b983e2855c4987726d0c9d3f296d84960c0ca533d5c73a026df841f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.33-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.33-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.33-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cff3269e979aeee5f7c578bc5168ed00d973dc70d2b11c58dab20f32af8276ca
MD5 0ac5bebe6aa851da7f4026efefa0f79d
BLAKE2b-256 cf63a5c3872dfd015104953d57cbc5704de50802404396b5c8ba359402ec2917

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.33-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.

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