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

Uploaded CPython 3.14Windows x86-64

bear_shelf-0.3.31-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.31-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.31-cp314-cp314-macosx_11_0_arm64.whl (380.1 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

bear_shelf-0.3.31-cp313-cp313-win_amd64.whl (153.2 kB view details)

Uploaded CPython 3.13Windows x86-64

bear_shelf-0.3.31-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.31-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.31-cp313-cp313-macosx_11_0_arm64.whl (379.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: bear_shelf-0.3.31-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 152.9 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.31-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 d68c0f1b091d7692c8339a462a4764c6ee871acfd873f1643fcb2bcbb8863099
MD5 d2d6a4a0347e8fc8df4443f08227c8ed
BLAKE2b-256 49c2754a7a63226fd0a0d706cc0dc0d47fd00165f8226d0a2f3e16fe3cc6369a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.31-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ba4a980760ec63f664b879076deac30b953c5a3067433de857470b980993cdec
MD5 92ae81b700d3a1158c69bf13d17ac2ae
BLAKE2b-256 94aa9f376b59024dd43e23a4eafaf3217bca3f1ad16da8570f48324502a65ea1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.31-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f7fcb775c06f1dd5e80975c80ef8cb880626c85241064e948d63a4e6a9d10fa5
MD5 8f736ee24a192b54bbcd80957722f049
BLAKE2b-256 4681fef28c0c26b5b9897c274ee8c2c502dffa5f6af6d752db67f29b1bb562b0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.31-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 64fa95f6b56cabacd2171da1cc85c657571173493a42e3d3df36ff588c5323d9
MD5 74ea1307de3f98c0caa3f88991cf9aac
BLAKE2b-256 ed835f7d368418255557cbc0b39d3b75ddc443d47e0c06784e3d17022aa0ccd4

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: bear_shelf-0.3.31-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 153.2 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.31-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 99b9dcc352b4eca7a7a3d6a2855539f62a2f06949c9f62c754d918444f3e0f15
MD5 b3e1606f5918e8b82f333dabf8ca919e
BLAKE2b-256 ecccb16e0663f9d7fb7507e50212bac143dc1f799695d8e78cccbe88f8bfc008

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.31-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d2ac2db8ffb3fdb82b8f6cc4bd3038fe2696708cf38ecc209d6670d95105cc5d
MD5 28afb4d6ce08763e4aa8286fd920d1ed
BLAKE2b-256 c6bdcd2ce044e60be63991e70cb0d8d12a32b1c42dffe9cf36d0ee66199c3363

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.31-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0fe416d3ec29611e39fff45b95bb67fd3b1ae8f8978612814bddf026cb89bad7
MD5 da49c1e6ae0e2dad9e3c4490e72cd189
BLAKE2b-256 2d814001afbe0fe49acbb9c2c397e5a802e800255a12139c8d7868e6f280d3a8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.31-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e6da1b56f7f353682712b1c221fa36a32dad77d571fa04cf1c644be2c374ba1
MD5 f406e42573c5f4d7fb1899386aa2cc25
BLAKE2b-256 940b7e117369f8d3d83abe95c39d89616fce07353c3c3d9fa86c1c95794d98ba

See more details on using hashes here.

Provenance

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