Persist pydantic models and query NoSQL-like.
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
🛠️ DuctTapeDB
DuctTapeDB is a lightweight, SQLite-powered solution designed for quickly persisting and searching Pydantic models. Whether you're working on non-technical projects or building fast prototypes with FastAPI, DuctTapeDB provides a simple and intuitive way to store and manage your data.
Originally created for a hobby project, DuctTapeDB has evolved into a powerful tool for rapid development, with a focus on ease of use and integration. 🚀
Why Use DuctTapeDB?
- Pydantic-Centric: Effortlessly store and search Pydantic models without additional setup.
- FastAPI-Ready: Perfect for creating CRUD APIs in minutes.
- Lightweight: Powered by SQLite—works out-of-the-box, no server required.
- Async and Sync Support:
- HookLoopDB (Async): Feature-rich and optimized for modern async workflows.
- DuctTapeDB (Sync): A straightforward synchronous option, with plans to align features across both modes.
Features
- Simple Persistence: Automatically save and retrieve Pydantic models with minimal code.
- Advanced Querying: Query data using JSON fields and SQL expressions.
- Async and Sync Options: Use what fits your project best.
- FastAPI Integration: Quickly build APIs with CRUD functionality.
- SQLite-Powered: Works anywhere—no need for additional infrastructure.
Installation
Install DuctTapeDB using pip:
pip install ducttapedb
For examples using FastAPI and FastUI, ensure you also install the required dependencies:
pip install fastapi fastui pydantic
Quickstart
1. Define Your Pydantic Model
from ducttapedb.hookloopdb.model import HookLoopModel
class Item(HookLoopModel):
name: str
description: str
price: float
in_stock: bool
2. Create a Database
from ducttapedb.hookloopdb.table import HookLoopTable
# Create an async SQLite database
async def setup_database():
table = await HookLoopTable.create_file("items", "items.db")
await table.initialize()
Item.set_table(table)
3. Perform CRUD Operations
Create
item = Item(name="Widget", description="A useful widget", price=19.99, in_stock=True)
await item.save()
Read
retrieved_item = await Item.from_id(item.id)
print(retrieved_item)
Query
items_in_stock = await Item.models_from_db(order_by="json_extract(data, '$.price') ASC")
print(items_in_stock)
Delete
await item.delete()
Using with FastAPI
You can quickly spin up a CRUD API using DuctTapeDB with FastAPI. Here's how:
-
Run the Example API:
- Install dependencies:
pip install fastapi fastui pydantic
- Start the development server:
fastapi dev examples\api\main.py
- Install dependencies:
-
Navigate to: http://127.0.0.1:8000/docs for the interactive API documentation, or to http://127.0.0.1:8000 for a very simple FastUI table and a form to insert items.
More Examples
Other examples included in this repo:
-
Inserts with a timer going:
- Install dependencies:
python examples\async_inserts\example.py
- You should see stats printed as it inserts and retrieves rows with the async HookLoopModel
- Install dependencies:
-
More examples planned
Roadmap
- Align features across HookLoopDB (Async) and DuctTapeDB (Sync).
- Add more advanced querying capabilities.
- Simplify relationships and data normalization.
- Add more convenience features.
Contributing
Contributions are welcome! If you encounter bugs or have feature requests, feel free to open an issue on GitHub.
License
DuctTapeDB is licensed under the MIT License. See the LICENSE file for more details.
Let me know if you'd like any additional tweaks! 🚀
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 ducttapedb-2025.1.12.1.tar.gz.
File metadata
- Download URL: ducttapedb-2025.1.12.1.tar.gz
- Upload date:
- Size: 23.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0191ef722e9a9a4a5cebbffcbc89c9a085c2d89bfde22e28bf26148b8ebd383
|
|
| MD5 |
34420474455e458c94a920c195d2c55e
|
|
| BLAKE2b-256 |
7b098b31e3b2e09b520989d36d260552da67a3da46aa3c04ccee9a40d9f71e5e
|
File details
Details for the file ducttapedb-2025.1.12.1-py3-none-any.whl.
File metadata
- Download URL: ducttapedb-2025.1.12.1-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc7b85ca5a2d798c62c0b333216dffb1a0ffe9b7d15738c298669b5ad0c199a8
|
|
| MD5 |
48cffcb16587971760c3c75dda31e084
|
|
| BLAKE2b-256 |
e663d3b920e2c8a3fd0d65ff9e6b56254e78da014aea844013eacea9bfa91a1a
|