Skip to main content
Alt Text

tinybridge

TinyDB bridge implementation for asyncio-based applications.

AIOBridge is an async-safe adapter for TinyDB, inspired by its design and intended for use within asyncio-based concurrent tasks. It enables safe and structured interaction with TinyDB from asynchronous Python code.

Key capabilities

  • Implements an async context manager for automatic resource handling
  • Ensures concurrency safety via a shared asyncio.Lock per DB file path
  • Executes all TinyDB operations using asyncio.to_thread() for non-blocking behavior
  • Provides functional-style error handling via Result objects
  • Supports configurable per-operation timeouts for robustness under load

Installation

Install via pip:

pip install tinybridge

Or using uv:

uv add tinybridge

tinybridge depends on tinydb and result, both installed automatically as dependencies.

Configuration

AIOBridge accepts the following options during initialization:

Parameter Type Default Description
path str — Path to the TinyDB JSON file
timeout int 10 Timeout (in seconds) applied to each operation
tinydb_class type TinyDB Optional class to override the default TinyDB implementation
**kwargs dict — Additional keyword arguments passed to the TinyDB constructor

Customizing tinydb_class

You can override the default TinyDB class either by passing a custom class directly or by subclassing AIOBridge.

Via tinydb_class argument

from tinybridge import AIOBridge
from tinydb import TinyDB
from tinydb.storages import MemoryStorage

class InMemoryTinyDB(TinyDB):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, storage=MemoryStorage, **kwargs)

async with AIOBridge("db.json", tinydb_class=InMemoryTinyDB) as db:
    ...

By subclassing AIOBridge

from tinybridge import AIOBridge
from tinydb import TinyDB
from tinydb.storages import JSONStorage
from tinydb.middlewares import CachingMiddleware

class CustomTinyDB(TinyDB):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, storage=CachingMiddleware(JSONStorage), **kwargs)

class CustomAIOBridge(AIOBridge):
    tinydb_class = CustomTinyDB

Usage Example

Minimal example demonstrating asynchronous insert:

import asyncio
from tinybridge import AIOBridge

async def main():
    async with AIOBridge("db.json") as db:
        result = await db.insert({"name": "Alice"})
        if result.is_ok():
            print("Inserted:", result.unwrap())
        else:
            print("Insert failed:", result.unwrap_err())

asyncio.run(main())

All standard TinyDB operations—such as get, search, update, and remove—are supported. Each method is wrapped for async compatibility and returns a Result object for safe error handling.

Similar Projects

Alternative community-driven efforts to add async capabilities to TinyDB:

Metadata

Release files for tinybridge 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tinybridge 0.1.4
File Size Uploaded
tinybridge-0.1.4.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tinybridge 0.1.4
File Interpreter ABI Platform
tinybridge-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 kB

Release files / tinybridge-0.1.4.tar.gz

Download URL tinybridge-0.1.4.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5dca2760b12e06225b51863aa7d17e3c52d309963df7bb9001a21e1538b82f33
BLAKE2b-256 checksum
How to use checksums
be21049ee8a8da8a0ec8803bf0c68c52a8f7152321e6770edda489c30365c799
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.4.18

Release files / tinybridge-0.1.4-py3-none-any.whl

Download URL tinybridge-0.1.4-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ada191ceda51e38305526ecc815674d129171d417c8e5a0f05a9dc67a0ed8b96
BLAKE2b-256 checksum
How to use checksums
3c04c277c503ba69ff7d1ba1a1b513a78e7f2aedee4fe743733f0f110b06f775
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.4.18

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page