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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

bear_shelf-0.3.30-cp312-cp312-win_amd64.whl (153.2 kB view details)

Uploaded CPython 3.12Windows x86-64

bear_shelf-0.3.30-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.30-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.30-cp312-cp312-macosx_11_0_arm64.whl (380.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: bear_shelf-0.3.30-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.30-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 67af058c4f2e565e9ee73d514759b57409051d0c7f5952485c54ccffade3d2b6
MD5 02b32783451aa2d56b544b58e29985cf
BLAKE2b-256 2527787bd9bb0016b3cce71e69678bcbadcf8c473f718f5afdc330ea78d7137e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.30-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dcf1c5fccd9588d2b8d64789c349b0d224db2aceaa1bb703da466302b5a9d791
MD5 07572ef27e739866a53fe06c40aa738e
BLAKE2b-256 af94bbafbc6cf516e1ea767659974975b75a174aed0a3a928e7369e11bce7cca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.30-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0b6bffcc3d5938a878b76e4ff6d5c30b784d3ed9c345c625249dc4617473656b
MD5 df2b41ab498a47be18118f231e7635f7
BLAKE2b-256 813a3e6002cc905b02fd5336abcc5652d47722a0f06a0c9d25ba98e2fb2c7959

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.30-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 694a7a9a78078753deee99c303093d1ef2d7f0beaec8f435dba8cc0b5db0650f
MD5 289c732afddf8067325f62b99e5abe4c
BLAKE2b-256 e0a3eb45111c58acac9dbf5cfab3516575358da280b2e307781731f8c9803771

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: bear_shelf-0.3.30-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.30-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1a0ed3d09338ad41f027c950c26764b775e361f8b86a3ea538fa89ba042d4a5a
MD5 2b2ee71204a4fa6981cca9ce15c0e986
BLAKE2b-256 5a905b0c8384831ff6f180cb6da21f2ca2a28d9ef3ff4df9bd60e14098e107ae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.30-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a1585d298fb6c0453cb0d5f7c12b8133418c7fa2e1ee336a1ff181bc3f85f5fb
MD5 1300cd2affe76aaeb410e26d3d5421ef
BLAKE2b-256 9ea620b96b9f89dd358ad9421af3a673a5a4c7d13ee2f77bd4b24c8f588854b5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.30-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b56b9b731a0884d0bc003379a0dc92e526f82181ab5e257b6db3feaf1336f669
MD5 1cc4d2c95cac9f04dff9a3cd8f5dae60
BLAKE2b-256 afdf3ddd24a123177912a69c3a0c139f608d4e4ee77a9acf5a19c12f87c8d6eb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bear_shelf-0.3.30-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d49b41952b06aeaf72071053fd676b6e9ab8285d137786e76d63ce7b1da5d436
MD5 297d94f564e99fe2780f6e42b96d0e37
BLAKE2b-256 21eca2e6268f9c1841c17668fcfcbd882a2bf0328cf7b7aa7884f5afc48cc74a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.30-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.30-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: bear_shelf-0.3.30-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 153.2 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.30-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1e7f1b33d89671876ffc7b67d7c053a5a46080c9ed74ce185a69252df55299f5
MD5 30b844ff06facc63bfea863f6ea8ea8b
BLAKE2b-256 2b0af163ec78ad4ad6aaef8db568268728a3d4f3baaf7071e5076ba3c5926112

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.30-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.30-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.30-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7991b235bdda65c6e8e61f43ee7d9d9dab053c7a1eaea0145973221c682715d4
MD5 3d5ffb58872b8f5dec2ba099846458a1
BLAKE2b-256 f9d3afb4db02d4f42411122b5307a06f4c93fecd68dcf9c9878ac844e647c854

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.30-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.30-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.30-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 55d354cf0c8c4097df6d7f5fffc195323750ea9ed63cc02ecb62d41a1ae2e2cb
MD5 ac1fa2a13d92f2a544e3f7642786c243
BLAKE2b-256 428a2d469202f700e7304488016b0288b155df371826c12894dfa2ae24942476

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_shelf-0.3.30-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.30-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bear_shelf-0.3.30-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eb510ea5fc89411a2ac47456e8a9d132a4956f6edd02e42658748c13af7cfad8
MD5 b600bc38dcc379b6f7194152a2809cf6
BLAKE2b-256 8bce0bc3ac001bf1e846f6e2d6545ccb8856c744aa629d9e5a1ecaafc671d7d5

See more details on using hashes here.

Provenance

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