A robust Python wrapper around SQLite3 providing dict-like API, multi-threading support, and REST service endpoints
Project description
DB86 — the AE‑86 of databases
A robust SQLite3 wrapper with dict-like API, multi-threading support, and optional REST service endpoints.
Table of Contents
- Features
- Requirements
- Installation
- Quick Start
- Usage Guide
- CLI Tool
- REST Service
- Advanced Examples
- Testing
- Contributing
- License
Features
- Dict-like Interface: Intuitive Python dict API for database operations
- Multi-threaded: Thread-safe access with built-in synchronization
- Dual Storage Modes: JSON storage for documents, tables for structured data
- In-Memory & File-Based: Support for both
:memory:and persistent databases - REST API: Built-in FastAPI service for remote database access
- CLI Tools: Interactive shells for database & REST administration
- Context Managers: Automatic resource cleanup with
withstatements - Transaction Support: Thread-safe transaction context management
Requirements
- Python: 3.10 or higher
Installation
pip install db86
# or
poetry add db86
Quick Start
from db86 import Database
with Database('./my_db.sqlite', autocommit=True) as db:
storage = db['users']
storage['alice'] = {'name': 'Alice', 'email': 'alice@example.com'}
print(storage['alice'])
for key, val in storage.items():
print(key, val)
Usage Guide
Basic Database Operations
from db86 import Database
# File-based (flag: 'c'=read/write, 'r'=read-only, 'w'=overwrite)
db = Database('./data.sqlite', flag='c', autocommit=True)
# In-memory
db_mem = Database(':memory:')
# Inspect structure
print(db.storages) # List all tables
print(db.indices) # List indices
print(db.describe()) # Print schema
JSON Storage
Default mode for flexible, document-style data:
db = Database('./db.sqlite')
users = db['users'] # JSON storage
# Store, retrieve, update
users['alice'] = {'name': 'Alice', 'tags': ['admin', 'dev']}
print(users['alice']['name'])
# Iterate and delete
for uid, user in users.items():
print(f"{user['name']} ({uid})")
del users['alice']
db.close()
Tables (Structured Storage)
Relational storage with schema:
db = Database('./db.sqlite')
products = db['products', 'table']
# Store structured data
products['prod_001'] = {'name': 'Laptop', 'price': 999.99}
products['prod_002'] = {'name': 'Mouse', 'price': 29.99}
# Inspect schema
print(products.describe())
print(products.columns)
# Access like a dictionary
for pid, prod in products.items():
print(f"{prod['name']}: ${prod['price']}")
Database Configuration
# Autocommit: save after each operation (safer, slower)
db = Database('./db.sqlite', autocommit=True)
# Manual commit: batch saves (faster)
db = Database('./db.sqlite', autocommit=False)
db['data']['key'] = 'value'
db.commit()
# Journal modes: 'DELETE' (default), 'WAL' (concurrent), 'OFF' (fast, risky)
db = Database('./db.sqlite', journal_mode='WAL')
CLI Tool
db86-shell # Database management shell
db86-restx # REST service management
db86-server # Start REST API server
REST Service
RESTful API for remote database access:
db86-server # Start at http://localhost:8000
Core endpoints:
GET /— health checkPOST /databases— create databaseGET /databases/{db_name}/storages/{storage_name}/items/{key}— read itemPUT /databases/{db_name}/storages/{storage_name}/items/{key}— write itemDELETE /databases/{db_name}/storages/{storage_name}/items/{key}— delete item
Interactive API docs: http://localhost:8000/docs
Advanced Examples
# Transactions
from db86 import Transaction
with Transaction(db) as txn:
txn['data']['key'] = 'value'
# Auto-commits on success, rolls back on error
# Multiple storages
users = db['users', 'json']
orders = db['orders', 'table']
users['alice'] = {'name': 'Alice'}
orders['order_001'] = {'user': 'alice'}
# Batch inserts
db = Database('./large.sqlite', autocommit=False, journal_mode='WAL')
for i in range(100000):
db['data'][f'key_{i}'] = {'index': i}
if i % 1000 == 0:
db.commit()
db.commit()
Testing
pytest # Run all tests
pytest tests/ -v # Verbose output
Contributing
Contributions welcome! Submit PRs or open issues for bugs and features.
git clone https://github.com/anubhav-narayan/db86.git
cd db86
poetry install && pytest
License
DB86 is released under the MIT License. See LICENSE.md for full details.
# MIT License
Copyright (c) 2021-2026 Anubhav Mattoo.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Acknowledgments
- Inspired by and derived from sqlitedict
- Built with FastAPI, Click, and SQLite3
Questions? Open an issue on GitHub
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file db86-0.7.0.tar.gz.
File metadata
- Download URL: db86-0.7.0.tar.gz
- Upload date:
- Size: 38.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b27b40adddea22e44c5e88b23cc0cc9c4f87db7af498218f4392f95982712a7e
|
|
| MD5 |
ef4a8b5259c7759016c9c153d6ebaf88
|
|
| BLAKE2b-256 |
3e010bedab482c2b4552ab7096419ac831f888778cba0919c0412ebfdf9fcd45
|
Provenance
The following attestation bundles were made for db86-0.7.0.tar.gz:
Publisher:
publish-workflow.yml on anubhav-narayan/db86
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
db86-0.7.0.tar.gz -
Subject digest:
b27b40adddea22e44c5e88b23cc0cc9c4f87db7af498218f4392f95982712a7e - Sigstore transparency entry: 1352579585
- Sigstore integration time:
-
Permalink:
anubhav-narayan/db86@d6e85eb055a838872b946d4266f1a17a244a6615 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/anubhav-narayan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-workflow.yml@d6e85eb055a838872b946d4266f1a17a244a6615 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file db86-0.7.0-py3-none-any.whl.
File metadata
- Download URL: db86-0.7.0-py3-none-any.whl
- Upload date:
- Size: 40.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b2fe7b445cb8851a48e0d81e7fbedfdff477664d4726066242f95209201e085
|
|
| MD5 |
b9dbf8cc7ccd481cc74dc4c5f39e5602
|
|
| BLAKE2b-256 |
6f357a2fbb1dfe3bc131f3b2b0cca2dae75f8761077fcf8997cb22bf04c772ca
|
Provenance
The following attestation bundles were made for db86-0.7.0-py3-none-any.whl:
Publisher:
publish-workflow.yml on anubhav-narayan/db86
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
db86-0.7.0-py3-none-any.whl -
Subject digest:
8b2fe7b445cb8851a48e0d81e7fbedfdff477664d4726066242f95209201e085 - Sigstore transparency entry: 1352579703
- Sigstore integration time:
-
Permalink:
anubhav-narayan/db86@d6e85eb055a838872b946d4266f1a17a244a6615 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/anubhav-narayan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-workflow.yml@d6e85eb055a838872b946d4266f1a17a244a6615 -
Trigger Event:
workflow_dispatch
-
Statement type: