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

Uploaded CPython 3.14Windows x86-64

bear_shelf-0.3.32-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.32-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.32-cp314-cp314-macosx_11_0_arm64.whl (382.6 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

bear_shelf-0.3.32-cp313-cp313-win_amd64.whl (155.0 kB view details)

Uploaded CPython 3.13Windows x86-64

bear_shelf-0.3.32-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.32-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.32-cp313-cp313-macosx_11_0_arm64.whl (382.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: bear_shelf-0.3.32-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 154.7 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.32-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 4e06074800fd14c00036712d70be98712458127f6ad72436e1d58ad027f450bb
MD5 27d037a0fa91e949c287952c2dc15178
BLAKE2b-256 7cee516460e299f3069a353aeb6cbdcb3037285364a94658ed58816482ca03e5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.32-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9212889be1558806285d20b1d59fab95a6ece4a91961c90e5bb0cdbfed836a23
MD5 21dd5814466dbdfb4c686c5e0a0ece58
BLAKE2b-256 99243a791edd4295f9f456bacd84613cc5454d01eec88478ec11f1e1c7e209f1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.32-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 93a2146f0ad6f9eff37d581dbd8fee5451d490257ab782ac8c28ddffdb43e35b
MD5 d3157d89ac98fd1ae87e15be5c457e51
BLAKE2b-256 236c261d072c6c2c93b329a4099b7635c874a689ea5a7d155d56af20da4d8d10

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.32-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c44737dfaaf7484fdf292322b00c5e94c55aa48fe4cf6ecf63e5fd5c2466b53
MD5 c8d3ee53e0967a6939b8a0f9460d0ebc
BLAKE2b-256 3ce74774e5b58abe4d4ef2c4dca61c8cbd7a69b351d05601daaacc67439d4694

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: bear_shelf-0.3.32-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 155.0 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.32-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8a1d7f5d709dff14ac8816d4b808619d390839feb46b2a055ca2de980d0fd909
MD5 858951b93bfe3db5a63a9cd9ae8bd3e0
BLAKE2b-256 025b036c9cf3bb688075f54e31fe89ed62ee9b06828a24ae5ada9d36dc3688c4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.32-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ad2a8131b1c976c988966bf56276695a200aacb0c57fd13f855a71d3dabdf01e
MD5 24a0050a35fe925a786ae3b70673cc3e
BLAKE2b-256 593c75320261b4b12e73c077ed68ab9062fa1dcdabaa7dd4d833f5eed487bb15

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.32-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6133b3591cccca2b8fe4717d2e70c46f3c5c501c93b68ac3b545738be77a7e01
MD5 7da194a5f0b1f39bbc34c7a15f5cf527
BLAKE2b-256 45cf3097ace51f1db7a078b32cddba061ab3f55acb69e856954c7d733a52c31a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.32-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d509170cf1a4fafae2eb9dc014bf64c0b018daae423f18b699c1048546c767c9
MD5 d5652942d27093cbf4b18262020c46df
BLAKE2b-256 da44a87b58ed0265bcc8490469341851a9aed70b6438bcee4bbcbca834893887

See more details on using hashes here.

Provenance

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