beaver-db 0.17.5__py3-none-any.whl → 0.18.0__py3-none-any.whl

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/__init__.py CHANGED
@@ -1,3 +1,5 @@
1
1
  from .core import BeaverDB
2
2
  from .types import Model
3
3
  from .collections import Document, WalkDirection
4
+
5
+ __version__ = "0.17.6"
beaver/cli.py CHANGED
@@ -1,10 +1,35 @@
1
1
  import typer
2
2
  import rich
3
3
  from typing_extensions import Annotated
4
+ import beaver
4
5
 
5
6
  app = typer.Typer()
6
7
 
7
8
 
9
+ def version_callback(value: bool):
10
+ if value:
11
+ print(beaver.__version__)
12
+ raise typer.Exit()
13
+
14
+
15
+ @app.callback()
16
+ def main(
17
+ version: Annotated[
18
+ bool,
19
+ typer.Option(
20
+ "--version",
21
+ callback=version_callback,
22
+ is_eager=True,
23
+ help="Show the version and exit.",
24
+ ),
25
+ ] = False,
26
+ ):
27
+ """
28
+ BeaverDB command-line interface.
29
+ """
30
+ pass
31
+
32
+
8
33
  @app.command()
9
34
  def serve(
10
35
  database: Annotated[
beaver/collections.py CHANGED
@@ -96,13 +96,20 @@ class Document(Model):
96
96
  def to_dict(self) -> dict[str, Any]:
97
97
  """Serializes the document's metadata to a dictionary."""
98
98
  metadata = self.__dict__.copy()
99
- metadata.pop("embedding", None)
100
- metadata.pop("id", None)
99
+ metadata["embedding"] = self.embedding.tolist() if self.embedding is not None else None
101
100
  return metadata
102
101
 
103
102
  def __repr__(self):
103
+ d = self.to_dict()
104
+ d.pop("embedding")
104
105
  metadata_str = ", ".join(f"{k}={v!r}" for k, v in self.to_dict().items())
105
- return f"Document(id='{self.id}', {metadata_str})"
106
+ return f"Document({metadata_str})"
107
+
108
+ def model_dump_json(self) -> str:
109
+ d = self.to_dict()
110
+ d.pop("embedding")
111
+ d.pop("id")
112
+ return json.dumps(d)
106
113
 
107
114
 
108
115
  class CollectionManager[D: Document]:
beaver/server.py CHANGED
@@ -270,7 +270,7 @@ def build(db: BeaverDB) -> FastAPI:
270
270
  def get_all_documents(name: str) -> List[dict]:
271
271
  """Retrieves all documents in the collection."""
272
272
  collection = db.collection(name)
273
- return [doc.model_dump() for doc in collection]
273
+ return [doc.to_dict() for doc in collection]
274
274
 
275
275
  @app.post("/collections/{name}/index", tags=["Collections"])
276
276
  def index_document(name: str, req: IndexRequest):
@@ -291,7 +291,7 @@ def build(db: BeaverDB) -> FastAPI:
291
291
  collection = db.collection(name)
292
292
  try:
293
293
  results = collection.search(vector=req.vector, top_k=req.top_k)
294
- return [{"document": doc.model_dump(), "distance": dist} for doc, dist in results]
294
+ return [{"document": doc.to_dict(), "distance": dist} for doc, dist in results]
295
295
  except TypeError as e:
296
296
  if "faiss" in str(e):
297
297
  raise HTTPException(status_code=501, detail="Vector search requires the '[faiss]' extra. Install with: pip install \"beaver-db[faiss]\"")
@@ -302,7 +302,7 @@ def build(db: BeaverDB) -> FastAPI:
302
302
  """Performs a full-text or fuzzy search on the collection."""
303
303
  collection = db.collection(name)
304
304
  results = collection.match(query=req.query, on=req.on, top_k=req.top_k, fuzziness=req.fuzziness)
305
- return [{"document": doc.model_dump(), "score": score} for doc, score in results]
305
+ return [{"document": doc.to_dict(), "score": score} for doc, score in results]
306
306
 
307
307
  @app.post("/collections/{name}/connect", tags=["Collections"])
308
308
  def connect_documents(name: str, req: ConnectRequest):
@@ -319,7 +319,7 @@ def build(db: BeaverDB) -> FastAPI:
319
319
  collection = db.collection(name)
320
320
  doc = Document(id=doc_id)
321
321
  neighbors = collection.neighbors(doc, label=label)
322
- return [n.model_dump() for n in neighbors]
322
+ return [n.to_dict() for n in neighbors]
323
323
 
324
324
  @app.post("/collections/{name}/{doc_id}/walk", tags=["Collections"])
325
325
  def walk_graph(name: str, doc_id: str, req: WalkRequest) -> List[dict]:
@@ -327,7 +327,7 @@ def build(db: BeaverDB) -> FastAPI:
327
327
  collection = db.collection(name)
328
328
  source_doc = Document(id=doc_id)
329
329
  results = collection.walk(source=source_doc, labels=req.labels, depth=req.depth, direction=req.direction)
330
- return [doc.model_dump() for doc in results]
330
+ return [doc.to_dict() for doc in results]
331
331
 
332
332
  return app
333
333
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beaver-db
3
- Version: 0.17.5
3
+ Version: 0.18.0
4
4
  Summary: Fast, embedded, and multi-modal DB based on SQLite for AI-powered applications.
5
5
  License-File: LICENSE
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -42,7 +42,7 @@ A fast, single-file, multi-modal database for Python, built with the standard `s
42
42
 
43
43
  `beaver` is built with a minimalistic philosophy for small, local use cases where a full-blown database server would be overkill.
44
44
 
45
- - **Minimalistic**: The core library has zero external dependencies. Vector search capabilities, which require `numpy` and `faiss-cpu`, are available as an optional feature.
45
+ - **Minimalistic**: The core library has zero external dependencies. Vector search, the REST server, and the CLI, which require external libraries, are available as optional features.
46
46
  - **Schemaless**: Flexible data storage without rigid schemas across all modalities.
47
47
  - **Synchronous, Multi-Process, and Thread-Safe**: Designed for simplicity and safety in multi-threaded and multi-process environments.
48
48
  - **Built for Local Applications**: Perfect for local AI tools, RAG prototypes, chatbots, and desktop utilities that need persistent, structured data without network overhead.
@@ -61,6 +61,8 @@ A fast, single-file, multi-modal database for Python, built with the standard `s
61
61
  - **Full-Text and Fuzzy Search**: Automatically index and search through document metadata using SQLite's powerful FTS5 engine, enhanced with optional fuzzy search for typo-tolerant matching.
62
62
  - **Knowledge Graph**: Create relationships between documents and traverse the graph to find neighbors or perform multi-hop walks.
63
63
  - **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.
64
+ - **Built-in REST API Server (Optional)**: Instantly serve your database over a RESTful API with automatic OpenAPI documentation using FastAPI.
65
+ - **Full-Featured CLI Client (Optional)**: Interact with your database directly from the command line for administrative tasks and data exploration.
64
66
  - **Optional Type-Safety:** Although the database is schemaless, you can use a minimalistic typing system for automatic serialization and deserialization that is Pydantic-compatible out of the box.
65
67
 
66
68
  ## How Beaver is Implemented
@@ -79,7 +81,6 @@ The vector store in BeaverDB is designed for high performance and reliability, u
79
81
 
80
82
  This hybrid approach allows BeaverDB to provide a vector search experience that is both fast and durable, without sacrificing the single-file, embedded philosophy of the library.
81
83
 
82
-
83
84
  ## Installation
84
85
 
85
86
  Install the core, dependency-free library:
@@ -88,12 +89,29 @@ Install the core, dependency-free library:
88
89
  pip install beaver-db
89
90
  ```
90
91
 
91
- If you want vector search capabilities, install the `faiss` extra:
92
+ To include optional features, you can install them as extras:
93
+
94
+ ```bash
95
+ # For vector search capabilities
96
+ pip install "beaver-db[vector]"
97
+
98
+ # For the REST API server and CLI
99
+ pip install "beaver-db[server,cli]"
100
+
101
+ # To install all optional features at once
102
+ pip install "beaver-db[full]"
103
+ ```
104
+
105
+ ### Running with Docker
106
+ For a fully embedded and lightweight solution, you can run the BeaverDB REST API server using Docker. This is the easiest way to get a self-hosted instance up and running.
92
107
 
93
108
  ```bash
94
- pip install "beaver-db[faiss]"
109
+ docker run -p 8000:8000 -v $(pwd)/data:/app apiad/beaverdb
95
110
  ```
96
111
 
112
+ This command will start the BeaverDB server, and your database file will be stored in the data directory on your host machine. You can access the API at <http://localhost:8000>.
113
+
114
+
97
115
  ## Quickstart
98
116
 
99
117
  Get up and running in 30 seconds. This example showcases a dictionary, a list, and full-text search in a single script.
@@ -131,6 +149,53 @@ print(f"FTS Result: '{top_doc.content}'")
131
149
  db.close()
132
150
  ```
133
151
 
152
+ ## Built-in Server and CLI
153
+
154
+ Beaver comes with a built-in REST API server and a full-featured command-line client, allowing you to interact with your database without writing any code.
155
+
156
+ ### REST API Server
157
+
158
+ You can instantly expose all of your database's functionality over a RESTful API. This is perfect for building quick prototypes, microservices, or for interacting with your data from other languages.
159
+
160
+ **1. Start the server**
161
+
162
+ ```bash
163
+ # Start the server for your database file
164
+ beaver serve --database data.db --port 8000
165
+ ```
166
+
167
+ This starts a `FastAPI` server. You can now access the interactive API documentation at `http://127.0.0.1:8000/docs`.
168
+
169
+ **2. Interact with the API**
170
+
171
+ Here are a couple of examples using `curl`:
172
+
173
+ ```bash
174
+ # Set a value in the 'app_config' dictionary
175
+ curl -X PUT http://127.0.0.1:8000/dicts/app_config/api_key
176
+ -H "Content-Type: application/json"
177
+ -d '"your-secret-api-key"'
178
+
179
+ # Get the value back
180
+ curl http://127.0.0.1:8000/dicts/app_config/api_key
181
+ # Output: "your-secret-api-key"
182
+ ```
183
+
184
+ ### Command-Line Client
185
+
186
+ The CLI client allows you to call any BeaverDB method directly from your terminal.
187
+
188
+ ```bash
189
+ # Set a value in a dictionary
190
+ beaver client --database data.db dict app_config set theme light
191
+
192
+ # Get the value back
193
+ beaver client --database data.db dict app_config get theme
194
+
195
+ # Push an item to a list
196
+ beaver client --database data.db list daily_tasks push "Review PRs"
197
+ ```
198
+
134
199
  ## Things You Can Build with Beaver
135
200
 
136
201
  Here are a few ideas to inspire your next project, showcasing how to combine Beaver's features to build powerful local applications.
@@ -282,8 +347,10 @@ For enhanced data integrity and a better developer experience, BeaverDB supports
282
347
 
283
348
  This feature is designed to be flexible and works seamlessly with two kinds of models:
284
349
 
285
- * **Pydantic Models**: If you're already using Pydantic, your `BaseModel` classes will work out of the box.
286
- * **Lightweight `beaver.Model`**: For a zero-dependency solution, you can inherit from the built-in `beaver.Model` class, which is a standard Python class with serialization methods automatically included.
350
+ - **Pydantic Models**: If you're already using Pydantic, your `BaseModel` classes will work out of the box.
351
+
352
+ - **Lightweight `beaver.Model`**: For a zero-dependency solution, you can inherit from the built-in `beaver.Model` class, which is a standard Python class with serialization methods automatically included.
353
+
287
354
 
288
355
  Here’s a quick example of how to use it:
289
356
 
@@ -305,7 +372,8 @@ users["alice"] = User(name="Alice", email="alice@example.com")
305
372
 
306
373
  # The retrieved object is a proper instance of the User class
307
374
  retrieved_user = users["alice"]
308
- print(f"Retrieved: {retrieved_user.name}") # Your editor will provide autocompletion here
375
+ # Your editor will provide autocompletion here
376
+ print(f"Retrieved: {retrieved_user.name}")
309
377
  ```
310
378
 
311
379
  In the same way you can have typed message payloads in `db.channel`, typed metadata in `db.blobs`, and custom document types in `db.collection`, as well as custom types in lists and queues.
@@ -316,25 +384,25 @@ Basically everywhere you can store or get some object in BeaverDB, you can use a
316
384
 
317
385
  For more in-depth examples, check out the scripts in the `examples/` directory:
318
386
 
319
- - [`async_pubsub.py`](examples/async_pubsub.py): A demonstration of the asynchronous wrapper for the publish/subscribe system.
320
- - [`blobs.py`](examples/blobs.py): Demonstrates how to store and retrieve binary data in the database.
321
- - [`cache.py`](examples/cache.py): A practical example of using a dictionary with TTL as a cache for API calls.
322
- - [`fts.py`](examples/fts.py): A detailed look at full-text search, including targeted searches on specific metadata fields.
323
- - [`fuzzy.py`](examples/fuzzy.py): Demonstrates fuzzy search capabilities for text search.
324
- - [`general_test.py`](examples/general_test.py): A general-purpose test to run all operations randomly which allows testing long-running processes and synchronicity issues.
325
- - [`graph.py`](examples/graph.py): Shows how to create relationships between documents and perform multi-hop graph traversals.
326
- - [`kvstore.py`](examples/kvstore.py): A comprehensive demo of the namespaced dictionary feature.
327
- - [`list.py`](examples/list.py): Shows the full capabilities of the persistent list, including slicing and in-place updates.
328
- - [`logs.py`](examples/logs.py): A short example showing how to build a realtime dashboard with the logging feature.
329
- - [`pqueue.py`](examples/pqueue.py): A practical example of using the persistent priority queue for task management.
330
- - [`producer_consumer.py`](examples/producer_consumer.py): A demonstration of the distributed task queue system in a multi-process environment.
331
- - [`publisher.py`](examples/publisher.py) and [`subscriber.py`](examples/subscriber.py): A pair of examples demonstrating inter-process message passing with the publish/subscribe system.
332
- - [`pubsub.py`](examples/pubsub.py): A demonstration of the synchronous, thread-safe publish/subscribe system in a single process.
333
- - [`rerank.py`](examples/rerank.py): Shows how to combine results from vector and text search for more refined results.
334
- - [`stress_vectors.py`](examples/stress_vectors.py): A stress test for the vector search functionality.
335
- - [`textual_chat.py`](examples/textual_chat.py): A chat application built with `textual` and `beaver` to illustrate the use of several primitives (lists, dicts, and channels) at the same time.
336
- - [`type_hints.py`](examples/type_hints.py): Shows how to use type hints with `beaver` to get better IDE support and type safety.
337
- - [`vector.py`](examples/vector.py): Demonstrates how to index and search vector embeddings, including upserts.
387
+ - [`async_pubsub.py`](examples/async_pubsub.py): A demonstration of the asynchronous wrapper for the publish/subscribe system.
388
+ - [`blobs.py`](examples/blobs.py): Demonstrates how to store and retrieve binary data in the database.
389
+ - [`cache.py`](examples/cache.py): A practical example of using a dictionary with TTL as a cache for API calls.
390
+ - [`fts.py`](examples/fts.py): A detailed look at full-text search, including targeted searches on specific metadata fields.
391
+ - [`fuzzy.py`](examples/fuzzy.py): Demonstrates fuzzy search capabilities for text search.
392
+ - [`general_test.py`](examples/general_test.py): A general-purpose test to run all operations randomly which allows testing long-running processes and synchronicity issues.
393
+ - [`graph.py`](examples/graph.py): Shows how to create relationships between documents and perform multi-hop graph traversals.
394
+ - [`kvstore.py`](examples/kvstore.py): A comprehensive demo of the namespaced dictionary feature.
395
+ - [`list.py`](examples/list.py): Shows the full capabilities of the persistent list, including slicing and in-place updates.
396
+ - [`logs.py`](examples/logs.py): A short example showing how to build a realtime dashboard with the logging feature.
397
+ - [`pqueue.py`](examples/pqueue.py): A practical example of using the persistent priority queue for task management.
398
+ - [`producer_consumer.py`](examples/producer_consumer.py): A demonstration of the distributed task queue system in a multi-process environment.
399
+ - [`publisher.py`](examples/publisher.p) and [`subscriber.py`](examples/subscriber.py): A pair of examples demonstrating inter-process message passing with the publish/subscribe system.
400
+ - [`pubsub.py`](examples/pubsub.py): A demonstration of the synchronous, thread-safe publish/subscribe system in a single process.
401
+ - [`rerank.py`](examples/rerank.py): Shows how to combine results from vector and text search for more refined results.
402
+ - [`stress_vectors.py`](examples/stress_vectors.py): A stress test for the vector search functionality.
403
+ - [`textual_chat.py`](examples/textual_chat.py): A chat application built with `textual` and `beaver` to illustrate the use of several primitives (lists, dicts, and channels) at the same time.
404
+ - [`type_hints.py`](examples/type_hints.py): Shows how to use type hints with `beaver` to get better IDE support and type safety.
405
+ - [`vector.py`](examples/vector.py): Demonstrates how to index and search vector embeddings, including upserts.
338
406
 
339
407
  ## Roadmap
340
408
 
@@ -342,7 +410,9 @@ For more in-depth examples, check out the scripts in the `examples/` directory:
342
410
 
343
411
  These are some of the features and improvements planned for future releases:
344
412
 
345
- - **Async API**: Extend the async support with on-demand wrappers for all features besides channels.
413
+ - **Async API**: Extend the async support with on-demand wrappers for all features besides channels.
414
+ - **Type-Safe Models**: Enhance built-in `Model` to handle recursive and embedded types.
415
+ - **Drop-in REST Client**: Implement a `BeaverClient` class that acts as a drop-in replacement for `BeaverDB` but instead of a local database file, it works against a REST API server.
346
416
 
347
417
  Check out the [roadmap](roadmap.md) for a detailed list of upcoming features and design ideas.
348
418
 
@@ -1,18 +1,18 @@
1
- beaver/__init__.py,sha256=qyEzF1Os7w4b4Hijgz0Y0R4zTrRBrHIGT1mEkZFl2YM,101
1
+ beaver/__init__.py,sha256=QkP3H8ah0QpWqaryT3yjNFX07zjGHMoWgu4dWDHH9eQ,125
2
2
  beaver/blobs.py,sha256=YkIEskHD6oHRaJTF0P25HrTT8LqM-REyV_UBPVQxeqQ,4055
3
3
  beaver/channels.py,sha256=kIuwKMDBdDQObaKT23znsMXzfpKfE7pXSxvf-u4LlpY,9554
4
- beaver/cli.py,sha256=Q61OYGrsWzERKy69NbttlSLUh1JunPlDSAd__LeKxhM,1789
5
- beaver/collections.py,sha256=Wm684pGp-E89PCq9gcbbmRC9VMtTxolRVXnrxKlw2m8,24615
4
+ beaver/cli.py,sha256=Sxm-mYU3LGd4tIqw-5LHb0ektWebjV9vn51hm-CMJD0,2232
5
+ beaver/collections.py,sha256=NVBq4W23I4WcMH-PBdvABBx2B0TR19AHpav6SktlQVk,24818
6
6
  beaver/core.py,sha256=68vjuEbkJTHv4SltCLCrgs34BpLCeL602oJZ6CJ34Zo,14560
7
7
  beaver/dicts.py,sha256=Xp8lPfQt08O8zCbptQLWQLO79OxG6uAVER6ryj3SScQ,5495
8
8
  beaver/lists.py,sha256=rfJ8uTNLkMREYc0uGx0z1VKt2m3eR9hvbdvDD58EbmQ,10140
9
9
  beaver/logs.py,sha256=a5xenwl5NZeegIU0dWVEs67lvaHzzw-JRAZtEzNNO3E,9529
10
10
  beaver/queues.py,sha256=Fr3oie63EtceSoiC8EOEDSLu1tDI8q2MYLXd8MEeC3g,6476
11
- beaver/server.py,sha256=OixUvPTIbSYN3anPc98UiF2mM289yjJBQGla1S_HmIY,13556
11
+ beaver/server.py,sha256=sf2cGUt6aTvegUzhssHOaFiAFaJCP65EMSDX3cvhf0s,13541
12
12
  beaver/types.py,sha256=WZLINf7hy6zdKdAFQK0EVMSl5vnY_KnrHXNdXgAKuPg,1582
13
13
  beaver/vectors.py,sha256=qvI6RwUOGrhVH5d6PUmI3jKDaoDotMy0iy-bHyvmXks,18496
14
- beaver_db-0.17.5.dist-info/METADATA,sha256=gMM4Ul7WQ7lrtTPJKss-59g1Swxkek4FiioWjfPNvk4,18664
15
- beaver_db-0.17.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
- beaver_db-0.17.5.dist-info/entry_points.txt,sha256=bd5E2s45PoBdtdR9-ToKSdLNhmHp8naV1lWP5mOzlrc,42
17
- beaver_db-0.17.5.dist-info/licenses/LICENSE,sha256=1xrIY5JnMk_QDQzsqmVzPIIyCgZAkWCC8kF2Ddo1UT0,1071
18
- beaver_db-0.17.5.dist-info/RECORD,,
14
+ beaver_db-0.18.0.dist-info/METADATA,sha256=T9Uqog7NP-Ts7-2tgWNytgBaeNkLV7nPDJbnlfUHrGY,21232
15
+ beaver_db-0.18.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
+ beaver_db-0.18.0.dist-info/entry_points.txt,sha256=bd5E2s45PoBdtdR9-ToKSdLNhmHp8naV1lWP5mOzlrc,42
17
+ beaver_db-0.18.0.dist-info/licenses/LICENSE,sha256=1xrIY5JnMk_QDQzsqmVzPIIyCgZAkWCC8kF2Ddo1UT0,1071
18
+ beaver_db-0.18.0.dist-info/RECORD,,