beaver-db 0.2.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.2.0 → beaver_db-0.3.0}/beaver/core.py +105 -0
- beaver_db-0.3.0/beaver_db.egg-info/PKG-INFO +129 -0
- {beaver_db-0.2.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.2.0 → beaver_db-0.3.0}/pyproject.toml +4 -2
- beaver_db-0.2.0/PKG-INFO +0 -109
- beaver_db-0.2.0/README.md +0 -102
- beaver_db-0.2.0/beaver/__init__.py +0 -1
- beaver_db-0.2.0/beaver_db.egg-info/PKG-INFO +0 -109
- {beaver_db-0.2.0 → beaver_db-0.3.0}/beaver_db.egg-info/dependency_links.txt +0 -0
- {beaver_db-0.2.0 → beaver_db-0.3.0}/beaver_db.egg-info/top_level.txt +0 -0
- {beaver_db-0.2.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
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
+
import uuid
|
|
3
|
+
import numpy as np
|
|
2
4
|
import json
|
|
3
5
|
import sqlite3
|
|
4
6
|
import time
|
|
@@ -26,6 +28,7 @@ class BeaverDB:
|
|
|
26
28
|
self._create_pubsub_table()
|
|
27
29
|
self._create_kv_table()
|
|
28
30
|
self._create_list_table()
|
|
31
|
+
self._create_collections_table()
|
|
29
32
|
|
|
30
33
|
def _create_pubsub_table(self):
|
|
31
34
|
"""Creates the pub/sub log table if it doesn't exist."""
|
|
@@ -64,6 +67,19 @@ class BeaverDB:
|
|
|
64
67
|
)
|
|
65
68
|
""")
|
|
66
69
|
|
|
70
|
+
def _create_collections_table(self):
|
|
71
|
+
"""Creates the collections table if it doesn't exist."""
|
|
72
|
+
with self._conn:
|
|
73
|
+
self._conn.execute("""
|
|
74
|
+
CREATE TABLE IF NOT EXISTS beaver_collections (
|
|
75
|
+
collection TEXT NOT NULL,
|
|
76
|
+
item_id TEXT NOT NULL,
|
|
77
|
+
item_vector BLOB NOT NULL,
|
|
78
|
+
metadata TEXT,
|
|
79
|
+
PRIMARY KEY (collection, item_id)
|
|
80
|
+
)
|
|
81
|
+
""")
|
|
82
|
+
|
|
67
83
|
def close(self):
|
|
68
84
|
"""Closes the database connection."""
|
|
69
85
|
if self._conn:
|
|
@@ -139,6 +155,10 @@ class BeaverDB:
|
|
|
139
155
|
raise TypeError("List name must be a non-empty string.")
|
|
140
156
|
return ListWrapper(name, self._conn)
|
|
141
157
|
|
|
158
|
+
def collection(self, name: str) -> "CollectionWrapper":
|
|
159
|
+
"""Returns a wrapper for interacting with a vector collection."""
|
|
160
|
+
return CollectionWrapper(name, self._conn)
|
|
161
|
+
|
|
142
162
|
# --- Asynchronous Pub/Sub Methods ---
|
|
143
163
|
|
|
144
164
|
async def publish(self, channel_name: str, payload: Any):
|
|
@@ -385,3 +405,88 @@ class Subscriber(AsyncIterator):
|
|
|
385
405
|
async def __anext__(self) -> Any:
|
|
386
406
|
"""Allows 'async for' to pull messages from the internal queue."""
|
|
387
407
|
return await self._queue.get()
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
class Document:
|
|
411
|
+
"""A data class for a vector and its metadata, with a unique ID."""
|
|
412
|
+
def __init__(self, embedding: list[float], id: str|None = None, **metadata):
|
|
413
|
+
if not isinstance(embedding, list) or not all(isinstance(x, (int, float)) for x in embedding):
|
|
414
|
+
raise TypeError("Embedding must be a list of numbers.")
|
|
415
|
+
|
|
416
|
+
self.id = id or str(uuid.uuid4())
|
|
417
|
+
self.embedding = np.array(embedding, dtype=np.float32)
|
|
418
|
+
|
|
419
|
+
for key, value in metadata.items():
|
|
420
|
+
setattr(self, key, value)
|
|
421
|
+
|
|
422
|
+
def to_dict(self) -> dict[str, Any]:
|
|
423
|
+
"""Serializes metadata to a dictionary."""
|
|
424
|
+
metadata = self.__dict__.copy()
|
|
425
|
+
# Exclude internal attributes from the metadata payload
|
|
426
|
+
metadata.pop('embedding', None)
|
|
427
|
+
metadata.pop('id', None)
|
|
428
|
+
return metadata
|
|
429
|
+
|
|
430
|
+
def __repr__(self):
|
|
431
|
+
metadata_str = ', '.join(f"{k}={v!r}" for k, v in self.to_dict().items())
|
|
432
|
+
return f"Document(id='{self.id}', {metadata_str})"
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
class CollectionWrapper:
|
|
436
|
+
"""A wrapper for vector collection operations with upsert logic."""
|
|
437
|
+
def __init__(self, name: str, conn: sqlite3.Connection):
|
|
438
|
+
self._name = name
|
|
439
|
+
self._conn = conn
|
|
440
|
+
|
|
441
|
+
def index(self, document: Document):
|
|
442
|
+
"""
|
|
443
|
+
Indexes a Document, performing an upsert based on the document's ID.
|
|
444
|
+
If the ID exists, the record is replaced.
|
|
445
|
+
If the ID is new (or auto-generated), a new record is inserted.
|
|
446
|
+
|
|
447
|
+
Args:
|
|
448
|
+
document: The Document object to index.
|
|
449
|
+
"""
|
|
450
|
+
with self._conn:
|
|
451
|
+
self._conn.execute(
|
|
452
|
+
"INSERT OR REPLACE INTO beaver_collections (collection, item_id, item_vector, metadata) VALUES (?, ?, ?, ?)",
|
|
453
|
+
(
|
|
454
|
+
self._name,
|
|
455
|
+
document.id,
|
|
456
|
+
document.embedding.tobytes(),
|
|
457
|
+
json.dumps(document.to_dict())
|
|
458
|
+
)
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
def search(self, vector: list[float], top_k: int = 10) -> list[tuple[Document, float]]:
|
|
462
|
+
"""
|
|
463
|
+
Performs a vector search and returns Document objects.
|
|
464
|
+
"""
|
|
465
|
+
query_vector = np.array(vector, dtype=np.float32)
|
|
466
|
+
|
|
467
|
+
cursor = self._conn.cursor()
|
|
468
|
+
cursor.execute(
|
|
469
|
+
"SELECT item_id, item_vector, metadata FROM beaver_collections WHERE collection = ?",
|
|
470
|
+
(self._name,)
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
all_docs_data = cursor.fetchall()
|
|
474
|
+
cursor.close()
|
|
475
|
+
|
|
476
|
+
if not all_docs_data:
|
|
477
|
+
return []
|
|
478
|
+
|
|
479
|
+
results = []
|
|
480
|
+
for row in all_docs_data:
|
|
481
|
+
doc_id = row['item_id']
|
|
482
|
+
embedding = np.frombuffer(row['item_vector'], dtype=np.float32).tolist()
|
|
483
|
+
metadata = json.loads(row['metadata'])
|
|
484
|
+
|
|
485
|
+
distance = np.linalg.norm(embedding - query_vector)
|
|
486
|
+
|
|
487
|
+
# Reconstruct the Document object with its original ID
|
|
488
|
+
doc = Document(id=doc_id, embedding=list(embedding), **metadata)
|
|
489
|
+
results.append((doc, float(distance)))
|
|
490
|
+
|
|
491
|
+
results.sort(key=lambda x: x[1])
|
|
492
|
+
return results[:top_k]
|
|
@@ -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 @@
|
|
|
1
|
+
numpy>=2.3.3
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "beaver-db"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "Asynchronous, embedded, modern DB based on SQLite."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.13"
|
|
7
|
-
dependencies = [
|
|
7
|
+
dependencies = [
|
|
8
|
+
"numpy>=2.3.3",
|
|
9
|
+
]
|
|
8
10
|
|
|
9
11
|
[tool.hatch.build.targets.wheel]
|
|
10
12
|
packages = ["beaver"]
|
beaver_db-0.2.0/PKG-INFO
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: beaver-db
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: Asynchronous, embedded, modern DB based on SQLite.
|
|
5
|
-
Requires-Python: >=3.13
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
|
|
8
|
-
# beaver 🦫
|
|
9
|
-
|
|
10
|
-
A fast, single-file, multi-modal database for Python, built with the standard sqlite3 library.
|
|
11
|
-
|
|
12
|
-
`beaver` is the Backend for Embedded Asynchronous Vector & Event Retrieval. It's an industrious, all-in-one database designed to manage complex, modern data types without requiring a database server.
|
|
13
|
-
|
|
14
|
-
Design Philosophy
|
|
15
|
-
`beaver` is built with a minimalistic philosophy for small, local use cases where a full-blown database server would be overkill.
|
|
16
|
-
|
|
17
|
-
- **Minimalistic & Zero-Dependency**: Uses only Python's standard libraries (sqlite3, asyncio). No external packages are required, making it incredibly lightweight and portable.
|
|
18
|
-
- **Async-First (When It Matters)**: The pub/sub system is fully asynchronous for high-performance, real-time messaging. Simpler features like key-value and list operations remain synchronous for ease of use.
|
|
19
|
-
- **Built for Local Applications**: Perfect for local AI tools, chatbots (streaming tokens), task management apps, desktop utilities, and prototypes that need persistent, structured data without network overhead.
|
|
20
|
-
- **Fast by Default**: It's built on SQLite, which is famously fast, reliable, and will likely serve your needs for a long way before you need a "professional" database.
|
|
21
|
-
|
|
22
|
-
## Core Features
|
|
23
|
-
|
|
24
|
-
- **Asynchronous Pub/Sub**: A fully asynchronous, Redis-like publish-subscribe system for real-time messaging.
|
|
25
|
-
- **Persistent Key-Value Store**: A simple set/get interface for storing configuration, session data, or any other JSON-serializable object.
|
|
26
|
-
- **Pythonic List Management**: A fluent, Redis-like interface (db.list("name").push()) for managing persistent, ordered lists with support for indexing and slicing.
|
|
27
|
-
- **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.
|
|
28
|
-
|
|
29
|
-
## Installation
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
pip install beaver-db
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Quickstart & API Guide
|
|
36
|
-
|
|
37
|
-
### 1. Initialization
|
|
38
|
-
|
|
39
|
-
All you need to do is import and instantiate the BeaverDB class with a file path.
|
|
40
|
-
|
|
41
|
-
```python
|
|
42
|
-
from beaver import BeaverDB
|
|
43
|
-
|
|
44
|
-
db = BeaverDB("my_application.db")
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### 2. Key-Value Store
|
|
48
|
-
|
|
49
|
-
Use `set()` and `get()` for simple data storage. The value can be any JSON-encodable object.
|
|
50
|
-
|
|
51
|
-
```python
|
|
52
|
-
# Set a value
|
|
53
|
-
db.set("app_config", {"theme": "dark", "user_id": 123})
|
|
54
|
-
|
|
55
|
-
# Get a value
|
|
56
|
-
config = db.get("app_config")
|
|
57
|
-
print(f"Theme: {config['theme']}") # Output: Theme: dark
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### 3. List Management
|
|
61
|
-
|
|
62
|
-
Get a list wrapper with `db.list()` and use Pythonic methods to manage it.
|
|
63
|
-
|
|
64
|
-
```python
|
|
65
|
-
# Get a wrapper for the 'tasks' list
|
|
66
|
-
tasks = db.list("daily_tasks")
|
|
67
|
-
|
|
68
|
-
# Push items to the list
|
|
69
|
-
tasks.push("Write the project report")
|
|
70
|
-
tasks.push("Send follow-up emails")
|
|
71
|
-
tasks.prepend("Plan the day's agenda") # Push to the front
|
|
72
|
-
|
|
73
|
-
# Use len() and indexing (including slices!)
|
|
74
|
-
print(f"There are {len(tasks)} tasks.")
|
|
75
|
-
print(f"The first task is: {tasks[0]}")
|
|
76
|
-
print(f"The rest is: {tasks[1:]}")
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### 4. Asynchronous Pub/Sub
|
|
80
|
-
|
|
81
|
-
Publish events from one part of your app and listen in another using asyncio.
|
|
82
|
-
|
|
83
|
-
```python
|
|
84
|
-
import asyncio
|
|
85
|
-
|
|
86
|
-
async def listener():
|
|
87
|
-
async with db.subscribe("system_events") as sub:
|
|
88
|
-
async for message in sub:
|
|
89
|
-
print(f"LISTENER: Received event -> {message['event']}")
|
|
90
|
-
|
|
91
|
-
async def publisher():
|
|
92
|
-
await asyncio.sleep(1)
|
|
93
|
-
await db.publish("system_events", {"event": "user_login", "user": "alice"})
|
|
94
|
-
|
|
95
|
-
# To run them concurrently:
|
|
96
|
-
# asyncio.run(asyncio.gather(listener(), publisher()))
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Roadmap
|
|
100
|
-
|
|
101
|
-
`beaver` aims to be a complete, self-contained data toolkit. The following features are planned:
|
|
102
|
-
|
|
103
|
-
- **Vector Storage & Search**: Store NumPy vector embeddings and perform efficient k-nearest neighbor (k-NN) searches using `scipy.spatial.cKDTree`.
|
|
104
|
-
- **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.
|
|
105
|
-
- **Standard Relational Interface**: While `beaver` provides high-level features, you can always use the same SQLite file for normal relational tasks (e.g., managing users, products) with standard SQL.
|
|
106
|
-
|
|
107
|
-
## License
|
|
108
|
-
|
|
109
|
-
This project is licensed under the MIT License.
|
beaver_db-0.2.0/README.md
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# beaver 🦫
|
|
2
|
-
|
|
3
|
-
A fast, single-file, multi-modal database for Python, built with the standard sqlite3 library.
|
|
4
|
-
|
|
5
|
-
`beaver` is the Backend for Embedded Asynchronous Vector & Event 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
|
-
`beaver` is built with a minimalistic philosophy for small, local use cases where a full-blown database server would be overkill.
|
|
9
|
-
|
|
10
|
-
- **Minimalistic & Zero-Dependency**: Uses only Python's standard libraries (sqlite3, asyncio). No external packages are required, making it incredibly lightweight and portable.
|
|
11
|
-
- **Async-First (When It Matters)**: The pub/sub system is fully asynchronous for high-performance, real-time messaging. Simpler features like key-value and list operations remain synchronous for ease of use.
|
|
12
|
-
- **Built for Local Applications**: Perfect for local AI tools, chatbots (streaming tokens), task management apps, desktop utilities, and prototypes that need persistent, structured data without network overhead.
|
|
13
|
-
- **Fast by Default**: It's built on SQLite, which is famously fast, reliable, and will likely serve your needs for a long way before you need a "professional" database.
|
|
14
|
-
|
|
15
|
-
## Core Features
|
|
16
|
-
|
|
17
|
-
- **Asynchronous Pub/Sub**: A fully asynchronous, Redis-like publish-subscribe system for real-time messaging.
|
|
18
|
-
- **Persistent Key-Value Store**: A simple set/get interface for storing configuration, session data, or any other JSON-serializable object.
|
|
19
|
-
- **Pythonic List Management**: A fluent, Redis-like interface (db.list("name").push()) for managing persistent, ordered lists with support for indexing and slicing.
|
|
20
|
-
- **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.
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
pip install beaver-db
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Quickstart & API Guide
|
|
29
|
-
|
|
30
|
-
### 1. Initialization
|
|
31
|
-
|
|
32
|
-
All you need to do is import and instantiate the BeaverDB class with a file path.
|
|
33
|
-
|
|
34
|
-
```python
|
|
35
|
-
from beaver import BeaverDB
|
|
36
|
-
|
|
37
|
-
db = BeaverDB("my_application.db")
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### 2. Key-Value Store
|
|
41
|
-
|
|
42
|
-
Use `set()` and `get()` for simple data storage. The value can be any JSON-encodable object.
|
|
43
|
-
|
|
44
|
-
```python
|
|
45
|
-
# Set a value
|
|
46
|
-
db.set("app_config", {"theme": "dark", "user_id": 123})
|
|
47
|
-
|
|
48
|
-
# Get a value
|
|
49
|
-
config = db.get("app_config")
|
|
50
|
-
print(f"Theme: {config['theme']}") # Output: Theme: dark
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### 3. List Management
|
|
54
|
-
|
|
55
|
-
Get a list wrapper with `db.list()` and use Pythonic methods to manage it.
|
|
56
|
-
|
|
57
|
-
```python
|
|
58
|
-
# Get a wrapper for the 'tasks' list
|
|
59
|
-
tasks = db.list("daily_tasks")
|
|
60
|
-
|
|
61
|
-
# Push items to the list
|
|
62
|
-
tasks.push("Write the project report")
|
|
63
|
-
tasks.push("Send follow-up emails")
|
|
64
|
-
tasks.prepend("Plan the day's agenda") # Push to the front
|
|
65
|
-
|
|
66
|
-
# Use len() and indexing (including slices!)
|
|
67
|
-
print(f"There are {len(tasks)} tasks.")
|
|
68
|
-
print(f"The first task is: {tasks[0]}")
|
|
69
|
-
print(f"The rest is: {tasks[1:]}")
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### 4. Asynchronous Pub/Sub
|
|
73
|
-
|
|
74
|
-
Publish events from one part of your app and listen in another using asyncio.
|
|
75
|
-
|
|
76
|
-
```python
|
|
77
|
-
import asyncio
|
|
78
|
-
|
|
79
|
-
async def listener():
|
|
80
|
-
async with db.subscribe("system_events") as sub:
|
|
81
|
-
async for message in sub:
|
|
82
|
-
print(f"LISTENER: Received event -> {message['event']}")
|
|
83
|
-
|
|
84
|
-
async def publisher():
|
|
85
|
-
await asyncio.sleep(1)
|
|
86
|
-
await db.publish("system_events", {"event": "user_login", "user": "alice"})
|
|
87
|
-
|
|
88
|
-
# To run them concurrently:
|
|
89
|
-
# asyncio.run(asyncio.gather(listener(), publisher()))
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## Roadmap
|
|
93
|
-
|
|
94
|
-
`beaver` aims to be a complete, self-contained data toolkit. The following features are planned:
|
|
95
|
-
|
|
96
|
-
- **Vector Storage & Search**: Store NumPy vector embeddings and perform efficient k-nearest neighbor (k-NN) searches using `scipy.spatial.cKDTree`.
|
|
97
|
-
- **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.
|
|
98
|
-
- **Standard Relational Interface**: While `beaver` provides high-level features, you can always use the same SQLite file for normal relational tasks (e.g., managing users, products) with standard SQL.
|
|
99
|
-
|
|
100
|
-
## License
|
|
101
|
-
|
|
102
|
-
This project is licensed under the MIT License.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .core import BeaverDB, Subscriber
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: beaver-db
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: Asynchronous, embedded, modern DB based on SQLite.
|
|
5
|
-
Requires-Python: >=3.13
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
|
|
8
|
-
# beaver 🦫
|
|
9
|
-
|
|
10
|
-
A fast, single-file, multi-modal database for Python, built with the standard sqlite3 library.
|
|
11
|
-
|
|
12
|
-
`beaver` is the Backend for Embedded Asynchronous Vector & Event Retrieval. It's an industrious, all-in-one database designed to manage complex, modern data types without requiring a database server.
|
|
13
|
-
|
|
14
|
-
Design Philosophy
|
|
15
|
-
`beaver` is built with a minimalistic philosophy for small, local use cases where a full-blown database server would be overkill.
|
|
16
|
-
|
|
17
|
-
- **Minimalistic & Zero-Dependency**: Uses only Python's standard libraries (sqlite3, asyncio). No external packages are required, making it incredibly lightweight and portable.
|
|
18
|
-
- **Async-First (When It Matters)**: The pub/sub system is fully asynchronous for high-performance, real-time messaging. Simpler features like key-value and list operations remain synchronous for ease of use.
|
|
19
|
-
- **Built for Local Applications**: Perfect for local AI tools, chatbots (streaming tokens), task management apps, desktop utilities, and prototypes that need persistent, structured data without network overhead.
|
|
20
|
-
- **Fast by Default**: It's built on SQLite, which is famously fast, reliable, and will likely serve your needs for a long way before you need a "professional" database.
|
|
21
|
-
|
|
22
|
-
## Core Features
|
|
23
|
-
|
|
24
|
-
- **Asynchronous Pub/Sub**: A fully asynchronous, Redis-like publish-subscribe system for real-time messaging.
|
|
25
|
-
- **Persistent Key-Value Store**: A simple set/get interface for storing configuration, session data, or any other JSON-serializable object.
|
|
26
|
-
- **Pythonic List Management**: A fluent, Redis-like interface (db.list("name").push()) for managing persistent, ordered lists with support for indexing and slicing.
|
|
27
|
-
- **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.
|
|
28
|
-
|
|
29
|
-
## Installation
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
pip install beaver-db
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Quickstart & API Guide
|
|
36
|
-
|
|
37
|
-
### 1. Initialization
|
|
38
|
-
|
|
39
|
-
All you need to do is import and instantiate the BeaverDB class with a file path.
|
|
40
|
-
|
|
41
|
-
```python
|
|
42
|
-
from beaver import BeaverDB
|
|
43
|
-
|
|
44
|
-
db = BeaverDB("my_application.db")
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### 2. Key-Value Store
|
|
48
|
-
|
|
49
|
-
Use `set()` and `get()` for simple data storage. The value can be any JSON-encodable object.
|
|
50
|
-
|
|
51
|
-
```python
|
|
52
|
-
# Set a value
|
|
53
|
-
db.set("app_config", {"theme": "dark", "user_id": 123})
|
|
54
|
-
|
|
55
|
-
# Get a value
|
|
56
|
-
config = db.get("app_config")
|
|
57
|
-
print(f"Theme: {config['theme']}") # Output: Theme: dark
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### 3. List Management
|
|
61
|
-
|
|
62
|
-
Get a list wrapper with `db.list()` and use Pythonic methods to manage it.
|
|
63
|
-
|
|
64
|
-
```python
|
|
65
|
-
# Get a wrapper for the 'tasks' list
|
|
66
|
-
tasks = db.list("daily_tasks")
|
|
67
|
-
|
|
68
|
-
# Push items to the list
|
|
69
|
-
tasks.push("Write the project report")
|
|
70
|
-
tasks.push("Send follow-up emails")
|
|
71
|
-
tasks.prepend("Plan the day's agenda") # Push to the front
|
|
72
|
-
|
|
73
|
-
# Use len() and indexing (including slices!)
|
|
74
|
-
print(f"There are {len(tasks)} tasks.")
|
|
75
|
-
print(f"The first task is: {tasks[0]}")
|
|
76
|
-
print(f"The rest is: {tasks[1:]}")
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### 4. Asynchronous Pub/Sub
|
|
80
|
-
|
|
81
|
-
Publish events from one part of your app and listen in another using asyncio.
|
|
82
|
-
|
|
83
|
-
```python
|
|
84
|
-
import asyncio
|
|
85
|
-
|
|
86
|
-
async def listener():
|
|
87
|
-
async with db.subscribe("system_events") as sub:
|
|
88
|
-
async for message in sub:
|
|
89
|
-
print(f"LISTENER: Received event -> {message['event']}")
|
|
90
|
-
|
|
91
|
-
async def publisher():
|
|
92
|
-
await asyncio.sleep(1)
|
|
93
|
-
await db.publish("system_events", {"event": "user_login", "user": "alice"})
|
|
94
|
-
|
|
95
|
-
# To run them concurrently:
|
|
96
|
-
# asyncio.run(asyncio.gather(listener(), publisher()))
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Roadmap
|
|
100
|
-
|
|
101
|
-
`beaver` aims to be a complete, self-contained data toolkit. The following features are planned:
|
|
102
|
-
|
|
103
|
-
- **Vector Storage & Search**: Store NumPy vector embeddings and perform efficient k-nearest neighbor (k-NN) searches using `scipy.spatial.cKDTree`.
|
|
104
|
-
- **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.
|
|
105
|
-
- **Standard Relational Interface**: While `beaver` provides high-level features, you can always use the same SQLite file for normal relational tasks (e.g., managing users, products) with standard SQL.
|
|
106
|
-
|
|
107
|
-
## License
|
|
108
|
-
|
|
109
|
-
This project is licensed under the MIT License.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|