ferres-db-python 0.1.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.
@@ -0,0 +1,277 @@
1
+ Metadata-Version: 2.4
2
+ Name: ferres-db-python
3
+ Version: 0.1.0
4
+ Summary: Python SDK for FerresDB vector database
5
+ Home-page: https://github.com/ferres-db/ferres-db
6
+ Author: FerresDB Team
7
+ License: MIT
8
+ Project-URL: Repository, https://github.com/ferres-db/ferres-db-python-sdk
9
+ Keywords: vector,database,embeddings,similarity-search
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: httpx>=0.24.0
23
+ Requires-Dist: structlog>=23.0.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
26
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
27
+ Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
28
+ Requires-Dist: black>=23.0.0; extra == "dev"
29
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
30
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
31
+ Dynamic: home-page
32
+ Dynamic: requires-python
33
+
34
+ # FerresDB Python SDK
35
+
36
+ Python SDK for interacting with FerresDB vector database.
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install ferres-db-python
42
+ ```
43
+
44
+ Or install from source:
45
+
46
+ ```bash
47
+ cd sdk/python
48
+ pip install -e .
49
+ ```
50
+
51
+ ## Authentication
52
+
53
+ All data routes (collections, points, search, API keys) require authentication. Pass the **API key** when creating the client; the SDK sends the `Authorization: Bearer <api_key>` header on every request.
54
+
55
+ ```python
56
+ client = VectorDBClient(
57
+ base_url="http://localhost:8080",
58
+ api_key="ferres_sk_...", # required for protected routes
59
+ )
60
+ ```
61
+
62
+ Without `api_key`, the server will respond with 401 on protected routes.
63
+
64
+ ## Running FerresDB with Docker
65
+
66
+ To use the SDK against a real FerresDB instance, you can run the official images.
67
+
68
+ ### Pull images
69
+
70
+ ```bash
71
+ docker pull ferresdb/ferres-db-core
72
+ docker pull ferresdb/ferres-db-frontend
73
+ ```
74
+
75
+ ### Start the backend (API)
76
+
77
+ ```bash
78
+ docker run -d \
79
+ --name ferres-db-core \
80
+ -p 8080:8080 \
81
+ -e PORT=8080 \
82
+ -e STORAGE_PATH=/data \
83
+ -e FERRESDB_API_KEYS=ferres_sk_your_key_here \
84
+ -v ferres-data:/data \
85
+ ferresdb/ferres-db-core
86
+ ```
87
+
88
+ - **API:** http://localhost:8080
89
+
90
+ ### Start the frontend (dashboard)
91
+
92
+ ```bash
93
+ docker run -d \
94
+ --name ferres-db-frontend \
95
+ -p 3000:80 \
96
+ -e VITE_API_BASE_URL=http://localhost:8080 \
97
+ -e VITE_API_KEY=ferres_sk_your_key_here \
98
+ ferresdb/ferres-db-frontend
99
+ ```
100
+
101
+ - **Dashboard:** http://localhost:3000
102
+
103
+ ### Use the SDK
104
+
105
+ With the backend running at `http://localhost:8080` and the same API key:
106
+
107
+ ```python
108
+ from vector_db_client import VectorDBClient
109
+
110
+ client = VectorDBClient(
111
+ base_url="http://localhost:8080",
112
+ api_key="ferres_sk_your_key_here",
113
+ )
114
+ # create collections, upsert, search, etc.
115
+ ```
116
+
117
+ ## Quick Start
118
+
119
+ ```python
120
+ import asyncio
121
+ from vector_db_client import VectorDBClient, Point, DistanceMetric
122
+
123
+ async def main():
124
+ # Create client (api_key required for collections, points, etc.)
125
+ async with VectorDBClient(
126
+ base_url="http://localhost:8080",
127
+ api_key="ferres_sk_...",
128
+ ) as client:
129
+ # Create a collection
130
+ collection = await client.create_collection(
131
+ name="my-collection",
132
+ dimension=128,
133
+ distance=DistanceMetric.COSINE,
134
+ )
135
+
136
+ # Upsert points
137
+ points = [
138
+ Point(id="1", vector=[0.1, 0.2, 0.3], metadata={"text": "hello"}),
139
+ Point(id="2", vector=[0.4, 0.5, 0.6], metadata={"text": "world"}),
140
+ ]
141
+ result = await client.upsert_points("my-collection", points)
142
+ print(f"Upserted {result.upserted} points")
143
+
144
+ # Search for similar vectors
145
+ results = await client.search(
146
+ collection="my-collection",
147
+ vector=[0.1, 0.2, 0.3],
148
+ limit=10,
149
+ )
150
+ for result in results:
151
+ print(f"ID: {result.id}, Score: {result.score}")
152
+
153
+ asyncio.run(main())
154
+ ```
155
+
156
+ ## Features
157
+
158
+ - **Type hints**: Full type annotations for better IDE support
159
+ - **Automatic retry**: Exponential backoff for transient failures
160
+ - **Structured logging**: Uses structlog for better observability
161
+ - **Automatic batching**: Large upsert operations are automatically split into batches
162
+ - **Async/await**: Built on httpx for async operations
163
+
164
+ ## API Reference
165
+
166
+ ### VectorDBClient
167
+
168
+ #### `__init__(base_url: str, api_key: str = None, timeout: int = 30)`
169
+
170
+ Initialize the client.
171
+
172
+ - `base_url`: Base URL of the FerresDB server (e.g., "http://localhost:8080")
173
+ - `api_key`: Optional API key for authentication (recommended for all data routes)
174
+ - `timeout`: Request timeout in seconds
175
+
176
+ #### `create_collection(name: str, dimension: int, distance: DistanceMetric, enable_bm25: bool = None, bm25_text_field: str = None) -> Collection`
177
+
178
+ Create a new collection. Use `enable_bm25=True` and `bm25_text_field="content"` for hybrid search.
179
+
180
+ #### `list_collections() -> List[CollectionListItem]`
181
+
182
+ List all collections.
183
+
184
+ #### `list_keys() -> List[ApiKeyInfo]`
185
+
186
+ List API keys (metadata only; requires Editor/Admin). Returns `id`, `name`, `key_prefix`, `created_at`.
187
+
188
+ #### `create_key(name: str) -> CreateKeyResponse`
189
+
190
+ Create a new API key. The raw `key` is returned only once; store it securely.
191
+
192
+ #### `delete_key(key_id: int) -> None`
193
+
194
+ Delete an API key by id (from `list_keys` or `create_key`).
195
+
196
+ #### `delete_collection(name: str) -> None`
197
+
198
+ Delete a collection.
199
+
200
+ #### `upsert_points(collection: str, points: List[Point]) -> UpsertResult`
201
+
202
+ Upsert points into a collection. Automatically batches if more than 1000 points.
203
+
204
+ #### `delete_points(collection: str, ids: List[str]) -> None`
205
+
206
+ Delete points by IDs.
207
+
208
+ #### `search(collection: str, vector: List[float], limit: int = 10, filter: dict = None) -> List[SearchResult]`
209
+
210
+ Search for similar vectors.
211
+
212
+ ## Models
213
+
214
+ ### Point
215
+
216
+ - `id: str`: Point identifier
217
+ - `vector: List[float]`: Vector coordinates
218
+ - `metadata: Dict[str, Any]`: Arbitrary metadata
219
+
220
+ ### Collection
221
+
222
+ - `name: str`: Collection name
223
+ - `dimension: int`: Vector dimension
224
+ - `distance: DistanceMetric`: Distance metric
225
+
226
+ ### SearchResult
227
+
228
+ - `id: str`: Point ID
229
+ - `score: float`: Similarity score
230
+ - `metadata: Dict[str, Any]`: Point metadata
231
+
232
+ ### ApiKeyInfo
233
+
234
+ - `id: int`: Key id
235
+ - `name: str`: Display name
236
+ - `key_prefix: str`: Prefix (raw key never returned in list)
237
+ - `created_at: int`: Unix timestamp
238
+
239
+ ### CreateKeyResponse
240
+
241
+ - `id: int`, `name: str`, `key: str`, `key_prefix: str`, `created_at: int` — `key` is the raw secret (returned only on create).
242
+
243
+ ## Exceptions
244
+
245
+ - `VectorDBError`: Base exception
246
+ - `CollectionNotFoundError`: Collection not found (404)
247
+ - `CollectionAlreadyExistsError`: Collection already exists (409)
248
+ - `InvalidDimensionError`: Invalid dimension (400)
249
+ - `InvalidPayloadError`: Invalid payload (400)
250
+ - `InternalError`: Internal server error (500)
251
+ - `ConnectionError`: Connection error
252
+
253
+ ## Development
254
+
255
+ Install development dependencies:
256
+
257
+ ```bash
258
+ pip install -e ".[dev]"
259
+ ```
260
+
261
+ Run tests:
262
+
263
+ ```bash
264
+ pytest
265
+ ```
266
+
267
+ Format code:
268
+
269
+ ```bash
270
+ black vector_db_client tests
271
+ ```
272
+
273
+ Type checking:
274
+
275
+ ```bash
276
+ mypy vector_db_client
277
+ ```
@@ -0,0 +1,244 @@
1
+ # FerresDB Python SDK
2
+
3
+ Python SDK for interacting with FerresDB vector database.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install ferres-db-python
9
+ ```
10
+
11
+ Or install from source:
12
+
13
+ ```bash
14
+ cd sdk/python
15
+ pip install -e .
16
+ ```
17
+
18
+ ## Authentication
19
+
20
+ All data routes (collections, points, search, API keys) require authentication. Pass the **API key** when creating the client; the SDK sends the `Authorization: Bearer <api_key>` header on every request.
21
+
22
+ ```python
23
+ client = VectorDBClient(
24
+ base_url="http://localhost:8080",
25
+ api_key="ferres_sk_...", # required for protected routes
26
+ )
27
+ ```
28
+
29
+ Without `api_key`, the server will respond with 401 on protected routes.
30
+
31
+ ## Running FerresDB with Docker
32
+
33
+ To use the SDK against a real FerresDB instance, you can run the official images.
34
+
35
+ ### Pull images
36
+
37
+ ```bash
38
+ docker pull ferresdb/ferres-db-core
39
+ docker pull ferresdb/ferres-db-frontend
40
+ ```
41
+
42
+ ### Start the backend (API)
43
+
44
+ ```bash
45
+ docker run -d \
46
+ --name ferres-db-core \
47
+ -p 8080:8080 \
48
+ -e PORT=8080 \
49
+ -e STORAGE_PATH=/data \
50
+ -e FERRESDB_API_KEYS=ferres_sk_your_key_here \
51
+ -v ferres-data:/data \
52
+ ferresdb/ferres-db-core
53
+ ```
54
+
55
+ - **API:** http://localhost:8080
56
+
57
+ ### Start the frontend (dashboard)
58
+
59
+ ```bash
60
+ docker run -d \
61
+ --name ferres-db-frontend \
62
+ -p 3000:80 \
63
+ -e VITE_API_BASE_URL=http://localhost:8080 \
64
+ -e VITE_API_KEY=ferres_sk_your_key_here \
65
+ ferresdb/ferres-db-frontend
66
+ ```
67
+
68
+ - **Dashboard:** http://localhost:3000
69
+
70
+ ### Use the SDK
71
+
72
+ With the backend running at `http://localhost:8080` and the same API key:
73
+
74
+ ```python
75
+ from vector_db_client import VectorDBClient
76
+
77
+ client = VectorDBClient(
78
+ base_url="http://localhost:8080",
79
+ api_key="ferres_sk_your_key_here",
80
+ )
81
+ # create collections, upsert, search, etc.
82
+ ```
83
+
84
+ ## Quick Start
85
+
86
+ ```python
87
+ import asyncio
88
+ from vector_db_client import VectorDBClient, Point, DistanceMetric
89
+
90
+ async def main():
91
+ # Create client (api_key required for collections, points, etc.)
92
+ async with VectorDBClient(
93
+ base_url="http://localhost:8080",
94
+ api_key="ferres_sk_...",
95
+ ) as client:
96
+ # Create a collection
97
+ collection = await client.create_collection(
98
+ name="my-collection",
99
+ dimension=128,
100
+ distance=DistanceMetric.COSINE,
101
+ )
102
+
103
+ # Upsert points
104
+ points = [
105
+ Point(id="1", vector=[0.1, 0.2, 0.3], metadata={"text": "hello"}),
106
+ Point(id="2", vector=[0.4, 0.5, 0.6], metadata={"text": "world"}),
107
+ ]
108
+ result = await client.upsert_points("my-collection", points)
109
+ print(f"Upserted {result.upserted} points")
110
+
111
+ # Search for similar vectors
112
+ results = await client.search(
113
+ collection="my-collection",
114
+ vector=[0.1, 0.2, 0.3],
115
+ limit=10,
116
+ )
117
+ for result in results:
118
+ print(f"ID: {result.id}, Score: {result.score}")
119
+
120
+ asyncio.run(main())
121
+ ```
122
+
123
+ ## Features
124
+
125
+ - **Type hints**: Full type annotations for better IDE support
126
+ - **Automatic retry**: Exponential backoff for transient failures
127
+ - **Structured logging**: Uses structlog for better observability
128
+ - **Automatic batching**: Large upsert operations are automatically split into batches
129
+ - **Async/await**: Built on httpx for async operations
130
+
131
+ ## API Reference
132
+
133
+ ### VectorDBClient
134
+
135
+ #### `__init__(base_url: str, api_key: str = None, timeout: int = 30)`
136
+
137
+ Initialize the client.
138
+
139
+ - `base_url`: Base URL of the FerresDB server (e.g., "http://localhost:8080")
140
+ - `api_key`: Optional API key for authentication (recommended for all data routes)
141
+ - `timeout`: Request timeout in seconds
142
+
143
+ #### `create_collection(name: str, dimension: int, distance: DistanceMetric, enable_bm25: bool = None, bm25_text_field: str = None) -> Collection`
144
+
145
+ Create a new collection. Use `enable_bm25=True` and `bm25_text_field="content"` for hybrid search.
146
+
147
+ #### `list_collections() -> List[CollectionListItem]`
148
+
149
+ List all collections.
150
+
151
+ #### `list_keys() -> List[ApiKeyInfo]`
152
+
153
+ List API keys (metadata only; requires Editor/Admin). Returns `id`, `name`, `key_prefix`, `created_at`.
154
+
155
+ #### `create_key(name: str) -> CreateKeyResponse`
156
+
157
+ Create a new API key. The raw `key` is returned only once; store it securely.
158
+
159
+ #### `delete_key(key_id: int) -> None`
160
+
161
+ Delete an API key by id (from `list_keys` or `create_key`).
162
+
163
+ #### `delete_collection(name: str) -> None`
164
+
165
+ Delete a collection.
166
+
167
+ #### `upsert_points(collection: str, points: List[Point]) -> UpsertResult`
168
+
169
+ Upsert points into a collection. Automatically batches if more than 1000 points.
170
+
171
+ #### `delete_points(collection: str, ids: List[str]) -> None`
172
+
173
+ Delete points by IDs.
174
+
175
+ #### `search(collection: str, vector: List[float], limit: int = 10, filter: dict = None) -> List[SearchResult]`
176
+
177
+ Search for similar vectors.
178
+
179
+ ## Models
180
+
181
+ ### Point
182
+
183
+ - `id: str`: Point identifier
184
+ - `vector: List[float]`: Vector coordinates
185
+ - `metadata: Dict[str, Any]`: Arbitrary metadata
186
+
187
+ ### Collection
188
+
189
+ - `name: str`: Collection name
190
+ - `dimension: int`: Vector dimension
191
+ - `distance: DistanceMetric`: Distance metric
192
+
193
+ ### SearchResult
194
+
195
+ - `id: str`: Point ID
196
+ - `score: float`: Similarity score
197
+ - `metadata: Dict[str, Any]`: Point metadata
198
+
199
+ ### ApiKeyInfo
200
+
201
+ - `id: int`: Key id
202
+ - `name: str`: Display name
203
+ - `key_prefix: str`: Prefix (raw key never returned in list)
204
+ - `created_at: int`: Unix timestamp
205
+
206
+ ### CreateKeyResponse
207
+
208
+ - `id: int`, `name: str`, `key: str`, `key_prefix: str`, `created_at: int` — `key` is the raw secret (returned only on create).
209
+
210
+ ## Exceptions
211
+
212
+ - `VectorDBError`: Base exception
213
+ - `CollectionNotFoundError`: Collection not found (404)
214
+ - `CollectionAlreadyExistsError`: Collection already exists (409)
215
+ - `InvalidDimensionError`: Invalid dimension (400)
216
+ - `InvalidPayloadError`: Invalid payload (400)
217
+ - `InternalError`: Internal server error (500)
218
+ - `ConnectionError`: Connection error
219
+
220
+ ## Development
221
+
222
+ Install development dependencies:
223
+
224
+ ```bash
225
+ pip install -e ".[dev]"
226
+ ```
227
+
228
+ Run tests:
229
+
230
+ ```bash
231
+ pytest
232
+ ```
233
+
234
+ Format code:
235
+
236
+ ```bash
237
+ black vector_db_client tests
238
+ ```
239
+
240
+ Type checking:
241
+
242
+ ```bash
243
+ mypy vector_db_client
244
+ ```