beaver-db 0.1.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of beaver-db might be problematic. Click here for more details.
- beaver_db-0.3.0/PKG-INFO +129 -0
- beaver_db-0.3.0/README.md +121 -0
- beaver_db-0.3.0/beaver/__init__.py +1 -0
- beaver_db-0.3.0/beaver/core.py +492 -0
- beaver_db-0.3.0/beaver_db.egg-info/PKG-INFO +129 -0
- {beaver_db-0.1.0 → beaver_db-0.3.0}/beaver_db.egg-info/SOURCES.txt +1 -0
- beaver_db-0.3.0/beaver_db.egg-info/requires.txt +1 -0
- {beaver_db-0.1.0 → beaver_db-0.3.0}/pyproject.toml +4 -2
- beaver_db-0.1.0/PKG-INFO +0 -117
- beaver_db-0.1.0/README.md +0 -110
- beaver_db-0.1.0/beaver/__init__.py +0 -1
- beaver_db-0.1.0/beaver/core.py +0 -163
- beaver_db-0.1.0/beaver_db.egg-info/PKG-INFO +0 -117
- {beaver_db-0.1.0 → beaver_db-0.3.0}/beaver_db.egg-info/dependency_links.txt +0 -0
- {beaver_db-0.1.0 → beaver_db-0.3.0}/beaver_db.egg-info/top_level.txt +0 -0
- {beaver_db-0.1.0 → beaver_db-0.3.0}/setup.cfg +0 -0
beaver_db-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: beaver-db
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Asynchronous, embedded, modern DB based on SQLite.
|
|
5
|
+
Requires-Python: >=3.13
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: numpy>=2.3.3
|
|
8
|
+
|
|
9
|
+
# beaver 🦫
|
|
10
|
+
|
|
11
|
+
A fast, single-file, multi-modal database for Python, built with the standard sqlite3 library.
|
|
12
|
+
|
|
13
|
+
`beaver` is the **B**ackend for **E**mbedded **A**synchronous **V**ector & **E**vent Retrieval. It's an industrious, all-in-one database designed to manage complex, modern data types without requiring a database server.
|
|
14
|
+
|
|
15
|
+
## Design Philosophy
|
|
16
|
+
|
|
17
|
+
`beaver` is built with a minimalistic philosophy for small, local use cases where a full-blown database server would be overkill.
|
|
18
|
+
|
|
19
|
+
- **Minimalistic & Zero-Dependency**: Uses only Python's standard libraries (`sqlite3`, `asyncio`) and `numpy`.
|
|
20
|
+
- **Async-First (When It Matters)**: The pub/sub system is fully asynchronous for high-performance, real-time messaging. Other features like key-value, list, and vector operations are synchronous for ease of use.
|
|
21
|
+
- **Built for Local Applications**: Perfect for local AI tools, RAG prototypes, chatbots, and desktop utilities that need persistent, structured data without network overhead.
|
|
22
|
+
- **Fast by Default**: It's built on SQLite, which is famously fast and reliable for local applications.
|
|
23
|
+
|
|
24
|
+
## Core Features
|
|
25
|
+
|
|
26
|
+
- **Asynchronous Pub/Sub**: A fully asynchronous, Redis-like publish-subscribe system for real-time messaging.
|
|
27
|
+
- **Persistent Key-Value Store**: A simple `set`/`get` interface for storing any JSON-serializable object.
|
|
28
|
+
- **Pythonic List Management**: A fluent, Redis-like interface for managing persistent, ordered lists.
|
|
29
|
+
- **Vector Storage & Search**: Store vector embeddings and perform simple, brute-force k-nearest neighbor searches, ideal for small-scale RAG.
|
|
30
|
+
- **Single-File & Portable**: All data is stored in a single SQLite file, making it incredibly easy to move, back up, or embed in your application.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install beaver-db
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quickstart & API Guide
|
|
39
|
+
|
|
40
|
+
### Initialization
|
|
41
|
+
|
|
42
|
+
All you need to do is import and instantiate the `BeaverDB` class with a file path.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from beaver import BeaverDB, Document
|
|
46
|
+
|
|
47
|
+
db = BeaverDB("my_application.db")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Key-Value Store
|
|
51
|
+
|
|
52
|
+
Use `set()` and `get()` for simple data storage. The value can be any JSON-encodable object.
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
# Set a value
|
|
56
|
+
db.set("app_config", {"theme": "dark", "user_id": 123})
|
|
57
|
+
|
|
58
|
+
# Get a value
|
|
59
|
+
config = db.get("app_config")
|
|
60
|
+
print(f"Theme: {config['theme']}") # Output: Theme: dark
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### List Management
|
|
64
|
+
|
|
65
|
+
Get a list wrapper with `db.list()` and use Pythonic methods to manage it.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
tasks = db.list("daily_tasks")
|
|
69
|
+
tasks.push("Write the project report")
|
|
70
|
+
tasks.prepend("Plan the day's agenda")
|
|
71
|
+
print(f"The first task is: {tasks[0]}")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Vector Storage & Search
|
|
75
|
+
|
|
76
|
+
Store `Document` objects containing vector embeddings and metadata. The search is a linear scan, which is sufficient for small-to-medium collections.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
# Get a handle to a collection
|
|
80
|
+
docs = db.collection("my_documents")
|
|
81
|
+
|
|
82
|
+
# Create and index a document (ID will be a UUID)
|
|
83
|
+
doc1 = Document(embedding=[0.1, 0.2, 0.7], text="A cat sat on the mat.")
|
|
84
|
+
docs.index(doc1)
|
|
85
|
+
|
|
86
|
+
# Create and index a document with a specific ID (for upserting)
|
|
87
|
+
doc2 = Document(id="article-42", embedding=[0.9, 0.1, 0.1], text="A dog chased a ball.")
|
|
88
|
+
docs.index(doc2)
|
|
89
|
+
|
|
90
|
+
# Search for the 2 most similar documents
|
|
91
|
+
query_vector = [0.15, 0.25, 0.65]
|
|
92
|
+
results = docs.search(vector=query_vector, top_k=2)
|
|
93
|
+
|
|
94
|
+
# Results are a list of (Document, distance) tuples
|
|
95
|
+
top_document, distance = results[0]
|
|
96
|
+
print(f"Closest document: {top_document.text} (distance: {distance:.4f})")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Asynchronous Pub/Sub
|
|
100
|
+
|
|
101
|
+
Publish events from one part of your app and listen in another using `asyncio`.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
import asyncio
|
|
105
|
+
|
|
106
|
+
async def listener():
|
|
107
|
+
async with db.subscribe("system_events") as sub:
|
|
108
|
+
async for message in sub:
|
|
109
|
+
print(f"LISTENER: Received event -> {message['event']}")
|
|
110
|
+
|
|
111
|
+
async def publisher():
|
|
112
|
+
await asyncio.sleep(1)
|
|
113
|
+
await db.publish("system_events", {"event": "user_login", "user": "alice"})
|
|
114
|
+
|
|
115
|
+
# To run them concurrently:
|
|
116
|
+
# asyncio.run(asyncio.gather(listener(), publisher()))
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Roadmap
|
|
120
|
+
|
|
121
|
+
`beaver` aims to be a complete, self-contained data toolkit. The following features are planned:
|
|
122
|
+
|
|
123
|
+
- **More Efficient Vector Search**: Integrate an approximate nearest neighbor (ANN) index like `scipy.spatial.cKDTree` to improve search speed on larger datasets.
|
|
124
|
+
- **JSON Document Store with Full-Text Search**: Store flexible JSON documents and get powerful full-text search across all text fields, powered by SQLite's FTS5 extension.
|
|
125
|
+
- **Standard Relational Interface**: While `beaver` provides high-level features, you can always use the same SQLite file for normal relational tasks with standard SQL.
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# beaver 🦫
|
|
2
|
+
|
|
3
|
+
A fast, single-file, multi-modal database for Python, built with the standard sqlite3 library.
|
|
4
|
+
|
|
5
|
+
`beaver` is the **B**ackend for **E**mbedded **A**synchronous **V**ector & **E**vent Retrieval. It's an industrious, all-in-one database designed to manage complex, modern data types without requiring a database server.
|
|
6
|
+
|
|
7
|
+
## Design Philosophy
|
|
8
|
+
|
|
9
|
+
`beaver` is built with a minimalistic philosophy for small, local use cases where a full-blown database server would be overkill.
|
|
10
|
+
|
|
11
|
+
- **Minimalistic & Zero-Dependency**: Uses only Python's standard libraries (`sqlite3`, `asyncio`) and `numpy`.
|
|
12
|
+
- **Async-First (When It Matters)**: The pub/sub system is fully asynchronous for high-performance, real-time messaging. Other features like key-value, list, and vector operations are synchronous for ease of use.
|
|
13
|
+
- **Built for Local Applications**: Perfect for local AI tools, RAG prototypes, chatbots, and desktop utilities that need persistent, structured data without network overhead.
|
|
14
|
+
- **Fast by Default**: It's built on SQLite, which is famously fast and reliable for local applications.
|
|
15
|
+
|
|
16
|
+
## Core Features
|
|
17
|
+
|
|
18
|
+
- **Asynchronous Pub/Sub**: A fully asynchronous, Redis-like publish-subscribe system for real-time messaging.
|
|
19
|
+
- **Persistent Key-Value Store**: A simple `set`/`get` interface for storing any JSON-serializable object.
|
|
20
|
+
- **Pythonic List Management**: A fluent, Redis-like interface for managing persistent, ordered lists.
|
|
21
|
+
- **Vector Storage & Search**: Store vector embeddings and perform simple, brute-force k-nearest neighbor searches, ideal for small-scale RAG.
|
|
22
|
+
- **Single-File & Portable**: All data is stored in a single SQLite file, making it incredibly easy to move, back up, or embed in your application.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install beaver-db
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quickstart & API Guide
|
|
31
|
+
|
|
32
|
+
### Initialization
|
|
33
|
+
|
|
34
|
+
All you need to do is import and instantiate the `BeaverDB` class with a file path.
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from beaver import BeaverDB, Document
|
|
38
|
+
|
|
39
|
+
db = BeaverDB("my_application.db")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Key-Value Store
|
|
43
|
+
|
|
44
|
+
Use `set()` and `get()` for simple data storage. The value can be any JSON-encodable object.
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
# Set a value
|
|
48
|
+
db.set("app_config", {"theme": "dark", "user_id": 123})
|
|
49
|
+
|
|
50
|
+
# Get a value
|
|
51
|
+
config = db.get("app_config")
|
|
52
|
+
print(f"Theme: {config['theme']}") # Output: Theme: dark
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### List Management
|
|
56
|
+
|
|
57
|
+
Get a list wrapper with `db.list()` and use Pythonic methods to manage it.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
tasks = db.list("daily_tasks")
|
|
61
|
+
tasks.push("Write the project report")
|
|
62
|
+
tasks.prepend("Plan the day's agenda")
|
|
63
|
+
print(f"The first task is: {tasks[0]}")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Vector Storage & Search
|
|
67
|
+
|
|
68
|
+
Store `Document` objects containing vector embeddings and metadata. The search is a linear scan, which is sufficient for small-to-medium collections.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
# Get a handle to a collection
|
|
72
|
+
docs = db.collection("my_documents")
|
|
73
|
+
|
|
74
|
+
# Create and index a document (ID will be a UUID)
|
|
75
|
+
doc1 = Document(embedding=[0.1, 0.2, 0.7], text="A cat sat on the mat.")
|
|
76
|
+
docs.index(doc1)
|
|
77
|
+
|
|
78
|
+
# Create and index a document with a specific ID (for upserting)
|
|
79
|
+
doc2 = Document(id="article-42", embedding=[0.9, 0.1, 0.1], text="A dog chased a ball.")
|
|
80
|
+
docs.index(doc2)
|
|
81
|
+
|
|
82
|
+
# Search for the 2 most similar documents
|
|
83
|
+
query_vector = [0.15, 0.25, 0.65]
|
|
84
|
+
results = docs.search(vector=query_vector, top_k=2)
|
|
85
|
+
|
|
86
|
+
# Results are a list of (Document, distance) tuples
|
|
87
|
+
top_document, distance = results[0]
|
|
88
|
+
print(f"Closest document: {top_document.text} (distance: {distance:.4f})")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Asynchronous Pub/Sub
|
|
92
|
+
|
|
93
|
+
Publish events from one part of your app and listen in another using `asyncio`.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
import asyncio
|
|
97
|
+
|
|
98
|
+
async def listener():
|
|
99
|
+
async with db.subscribe("system_events") as sub:
|
|
100
|
+
async for message in sub:
|
|
101
|
+
print(f"LISTENER: Received event -> {message['event']}")
|
|
102
|
+
|
|
103
|
+
async def publisher():
|
|
104
|
+
await asyncio.sleep(1)
|
|
105
|
+
await db.publish("system_events", {"event": "user_login", "user": "alice"})
|
|
106
|
+
|
|
107
|
+
# To run them concurrently:
|
|
108
|
+
# asyncio.run(asyncio.gather(listener(), publisher()))
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Roadmap
|
|
112
|
+
|
|
113
|
+
`beaver` aims to be a complete, self-contained data toolkit. The following features are planned:
|
|
114
|
+
|
|
115
|
+
- **More Efficient Vector Search**: Integrate an approximate nearest neighbor (ANN) index like `scipy.spatial.cKDTree` to improve search speed on larger datasets.
|
|
116
|
+
- **JSON Document Store with Full-Text Search**: Store flexible JSON documents and get powerful full-text search across all text fields, powered by SQLite's FTS5 extension.
|
|
117
|
+
- **Standard Relational Interface**: While `beaver` provides high-level features, you can always use the same SQLite file for normal relational tasks with standard SQL.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .core import BeaverDB, Document
|