beaver-db 0.16.8__py3-none-any.whl → 0.17.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/cli.py ADDED
@@ -0,0 +1,34 @@
1
+ import typer
2
+ import rich
3
+
4
+ app = typer.Typer()
5
+
6
+
7
+ @app.command()
8
+ def serve(
9
+ database: str = typer.Option(
10
+ "beaver.db", "--database", "-d", help="Path to the database file."
11
+ ),
12
+ host: str = typer.Option(
13
+ "127.0.0.1", "--host", "-h", help="The host to bind the server to."
14
+ ),
15
+ port: int = typer.Option(
16
+ 8000, "--port", "-p", help="The port to run the server on."
17
+ ),
18
+ ):
19
+ """
20
+ Starts a RESTful API server for a BeaverDB instance.
21
+ """
22
+ try:
23
+ from .server import serve as run_server
24
+ except ImportError as e:
25
+ rich.print(f"[red]Error: {e}[/]")
26
+ rich.print('[yellow]Please install the server dependencies with `pip install "beaver-db[server]"`[/]')
27
+ raise typer.Exit(code=1)
28
+
29
+ rich.print(f"[blue]Starting server for database at '{database}' on http://{host}:{port}[/]")
30
+ run_server(db_path=database, host=host, port=port)
31
+
32
+
33
+ if __name__ == "__main__":
34
+ app()
beaver/server.py ADDED
@@ -0,0 +1,132 @@
1
+ try:
2
+ from fastapi import FastAPI, HTTPException, Body
3
+ import uvicorn
4
+ except ImportError:
5
+ raise ImportError(
6
+ "FastAPI and Uvicorn are required to serve the database. "
7
+ 'Please install them with `pip install "beaver-db[server]"`'
8
+ )
9
+ from typing import Any
10
+ from .core import BeaverDB
11
+
12
+
13
+ def build(db: BeaverDB) -> FastAPI:
14
+ """
15
+ Constructs a FastAPI application instance for a given BeaverDB instance.
16
+
17
+ Args:
18
+ db: An active BeaverDB instance.
19
+
20
+ Returns:
21
+ A FastAPI application with all endpoints configured.
22
+ """
23
+ app = FastAPI(
24
+ title="BeaverDB",
25
+ description="A RESTful API for a BeaverDB instance.",
26
+ version="0.1.0",
27
+ )
28
+
29
+ # --- Dicts Endpoints ---
30
+
31
+ @app.get("/dicts/{name}")
32
+ def get_all_dict_items(name: str) -> dict:
33
+ """Retrieves all key-value pairs in a dictionary."""
34
+ d = db.dict(name)
35
+ return {k: v for k, v in d.items()}
36
+
37
+ @app.get("/dicts/{name}/{key}")
38
+ def get_dict_item(name: str, key: str) -> Any:
39
+ """Retrieves the value for a specific key."""
40
+ d = db.dict(name)
41
+ try:
42
+ return d[key]
43
+ except KeyError:
44
+ raise HTTPException(status_code=404, detail=f"Key '{key}' not found in dictionary '{name}'")
45
+
46
+ @app.post("/dicts/{name}/{key}")
47
+ def set_dict_item(name: str, key: str, value: Any = Body(...)):
48
+ """Sets the value for a specific key."""
49
+ d = db.dict(name)
50
+ d[key] = value
51
+ return {"status": "ok"}
52
+
53
+ @app.delete("/dicts/{name}/{key}")
54
+ def delete_dict_item(name: str, key: str):
55
+ """Deletes a key-value pair."""
56
+ d = db.dict(name)
57
+ try:
58
+ del d[key]
59
+ return {"status": "ok"}
60
+ except KeyError:
61
+ raise HTTPException(status_code=404, detail=f"Key '{key}' not found in dictionary '{name}'")
62
+
63
+ # --- Lists Endpoints ---
64
+
65
+ @app.get("/lists/{name}")
66
+ def get_list(name: str) -> list:
67
+ """Retrieves all items in the list."""
68
+ l = db.list(name)
69
+ return l[:]
70
+
71
+ @app.get("/lists/{name}/{index}")
72
+ def get_list_item(name: str, index: int) -> Any:
73
+ """Retrieves the item at a specific index."""
74
+ l = db.list(name)
75
+ try:
76
+ return l[index]
77
+ except IndexError:
78
+ raise HTTPException(status_code=404, detail=f"Index {index} out of bounds for list '{name}'")
79
+
80
+ @app.post("/lists/{name}")
81
+ def push_list_item(name: str, value: Any = Body(...)):
82
+ """Adds an item to the end of the list."""
83
+ l = db.list(name)
84
+ l.push(value)
85
+ return {"status": "ok"}
86
+
87
+ @app.put("/lists/{name}/{index}")
88
+ def update_list_item(name: str, index: int, value: Any = Body(...)):
89
+ """Updates the item at a specific index."""
90
+ l = db.list(name)
91
+ try:
92
+ l[index] = value
93
+ return {"status": "ok"}
94
+ except IndexError:
95
+ raise HTTPException(status_code=404, detail=f"Index {index} out of bounds for list '{name}'")
96
+
97
+ @app.delete("/lists/{name}/{index}")
98
+ def delete_list_item(name: str, index: int):
99
+ """Deletes the item at a specific index."""
100
+ l = db.list(name)
101
+ try:
102
+ del l[index]
103
+ return {"status": "ok"}
104
+ except IndexError:
105
+ raise HTTPException(status_code=404, detail=f"Index {index} out of bounds for list '{name}'")
106
+
107
+ # TODO: Add endpoints for all BeaverDB modalities
108
+ # - Queues
109
+ # - Collections
110
+ # - Channels
111
+ # - Logs
112
+ # - Blobs
113
+
114
+ @app.get("/")
115
+ def read_root():
116
+ return {"message": "Welcome to the BeaverDB API"}
117
+
118
+ return app
119
+
120
+
121
+ def serve(db_path: str, host: str, port: int):
122
+ """
123
+ Initializes a BeaverDB instance and runs a Uvicorn server for it.
124
+
125
+ Args:
126
+ db_path: The path to the SQLite database file.
127
+ host: The host to bind the server to.
128
+ port: The port to run the server on.
129
+ """
130
+ db = BeaverDB(db_path)
131
+ app = build(db)
132
+ uvicorn.run(app, host=host, port=port)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beaver-db
3
- Version: 0.16.8
3
+ Version: 0.17.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
@@ -9,8 +9,17 @@ Classifier: Programming Language :: Python :: 3.13
9
9
  Classifier: Topic :: Database
10
10
  Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
11
11
  Requires-Python: >=3.13
12
- Provides-Extra: faiss
13
- Requires-Dist: faiss-cpu>=1.12.0; extra == 'faiss'
12
+ Provides-Extra: cli
13
+ Requires-Dist: typer>=0.19.2; extra == 'cli'
14
+ Provides-Extra: full
15
+ Requires-Dist: faiss-cpu>=1.12.0; extra == 'full'
16
+ Requires-Dist: fastapi[standard]>=0.118.0; extra == 'full'
17
+ Requires-Dist: typer>=0.19.2; extra == 'full'
18
+ Provides-Extra: server
19
+ Requires-Dist: fastapi[standard]>=0.118.0; extra == 'server'
20
+ Requires-Dist: typer>=0.19.2; extra == 'server'
21
+ Provides-Extra: vector
22
+ Requires-Dist: faiss-cpu>=1.12.0; extra == 'vector'
14
23
  Description-Content-Type: text/markdown
15
24
 
16
25
  # beaver 🦫
@@ -1,15 +1,18 @@
1
1
  beaver/__init__.py,sha256=qyEzF1Os7w4b4Hijgz0Y0R4zTrRBrHIGT1mEkZFl2YM,101
2
2
  beaver/blobs.py,sha256=YkIEskHD6oHRaJTF0P25HrTT8LqM-REyV_UBPVQxeqQ,4055
3
3
  beaver/channels.py,sha256=kIuwKMDBdDQObaKT23znsMXzfpKfE7pXSxvf-u4LlpY,9554
4
+ beaver/cli.py,sha256=ExphB5Tx2hiyhLdtafQmANa6GA3KE5sbbI9tHWj_yY0,948
4
5
  beaver/collections.py,sha256=Wm684pGp-E89PCq9gcbbmRC9VMtTxolRVXnrxKlw2m8,24615
5
6
  beaver/core.py,sha256=68vjuEbkJTHv4SltCLCrgs34BpLCeL602oJZ6CJ34Zo,14560
6
7
  beaver/dicts.py,sha256=Xp8lPfQt08O8zCbptQLWQLO79OxG6uAVER6ryj3SScQ,5495
7
8
  beaver/lists.py,sha256=rfJ8uTNLkMREYc0uGx0z1VKt2m3eR9hvbdvDD58EbmQ,10140
8
9
  beaver/logs.py,sha256=a5xenwl5NZeegIU0dWVEs67lvaHzzw-JRAZtEzNNO3E,9529
9
10
  beaver/queues.py,sha256=Fr3oie63EtceSoiC8EOEDSLu1tDI8q2MYLXd8MEeC3g,6476
11
+ beaver/server.py,sha256=lmzMu51cXa1Qdezg140hmsMLCxVSq8YGX0EPQfuGidk,4043
10
12
  beaver/types.py,sha256=WZLINf7hy6zdKdAFQK0EVMSl5vnY_KnrHXNdXgAKuPg,1582
11
13
  beaver/vectors.py,sha256=qvI6RwUOGrhVH5d6PUmI3jKDaoDotMy0iy-bHyvmXks,18496
12
- beaver_db-0.16.8.dist-info/METADATA,sha256=SN90Fv3zk6_Xa38nkVDdWNr6mifgnfi_6dJtfEeg7PA,18240
13
- beaver_db-0.16.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- beaver_db-0.16.8.dist-info/licenses/LICENSE,sha256=1xrIY5JnMk_QDQzsqmVzPIIyCgZAkWCC8kF2Ddo1UT0,1071
15
- beaver_db-0.16.8.dist-info/RECORD,,
14
+ beaver_db-0.17.0.dist-info/METADATA,sha256=NHuwsDxsE2k8qPuBWttjBMLhfh7f9NIMIhAmFjiVTgg,18615
15
+ beaver_db-0.17.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
+ beaver_db-0.17.0.dist-info/entry_points.txt,sha256=bd5E2s45PoBdtdR9-ToKSdLNhmHp8naV1lWP5mOzlrc,42
17
+ beaver_db-0.17.0.dist-info/licenses/LICENSE,sha256=1xrIY5JnMk_QDQzsqmVzPIIyCgZAkWCC8kF2Ddo1UT0,1071
18
+ beaver_db-0.17.0.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ beaver = beaver.cli:app