multids 0.2.1__tar.gz → 1.0.0rc2__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.
- multids-1.0.0rc2/PKG-INFO +534 -0
- multids-1.0.0rc2/README.md +487 -0
- {multids-0.2.1 → multids-1.0.0rc2}/pyproject.toml +30 -8
- multids-1.0.0rc2/src/multids/__init__.py +16 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/cli.py +3 -2
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/connectors/athena.py +92 -17
- multids-1.0.0rc2/src/multids/connectors/mssql.py +242 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/connectors/opensearch.py +72 -20
- multids-1.0.0rc2/src/multids/connectors/postgres.py +249 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/connectors/s3.py +246 -35
- multids-1.0.0rc2/src/multids/connectors/sql.py +349 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/connectors/sync/__init__.py +4 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/connectors/sync/athena.py +51 -9
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/connectors/sync/mssql.py +99 -29
- multids-1.0.0rc2/src/multids/connectors/sync/opensearch.py +344 -0
- multids-1.0.0rc2/src/multids/connectors/sync/postgres.py +236 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/connectors/sync/s3.py +114 -13
- multids-1.0.0rc2/src/multids/connectors/sync/sql.py +266 -0
- multids-1.0.0rc2/src/multids/error_mapping.py +169 -0
- multids-1.0.0rc2/src/multids/py.typed +0 -0
- multids-1.0.0rc2/src/multids/reliability.py +244 -0
- multids-1.0.0rc2/src/multids/telemetry.py +250 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/workflows.py +19 -0
- multids-0.2.1/PKG-INFO +0 -382
- multids-0.2.1/README.md +0 -341
- multids-0.2.1/src/multids/__init__.py +0 -6
- multids-0.2.1/src/multids/connectors/mssql.py +0 -151
- multids-0.2.1/src/multids/connectors/sql.py +0 -131
- multids-0.2.1/src/multids/connectors/sync/sql.py +0 -117
- multids-0.2.1/src/multids/reliability.py +0 -63
- {multids-0.2.1 → multids-1.0.0rc2}/LICENSE +0 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/ai.py +0 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/connectors/__init__.py +0 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/connectors/local.py +0 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/connectors/sync/local.py +0 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/contracts.py +0 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/errors.py +0 -0
- {multids-0.2.1 → multids-1.0.0rc2}/src/multids/interfaces.py +0 -0
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: multids
|
|
3
|
+
Version: 1.0.0rc2
|
|
4
|
+
Summary: Async multi-data-source connectors (S3, OpenSearch, Athena, MySQL, SQL Server, local files) with AI hooks.
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Author: Khaldoun Aljasem
|
|
7
|
+
Author-email: khaldoun.aljasem@gmail.com
|
|
8
|
+
Requires-Python: >=3.11,<4.0
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
18
|
+
Provides-Extra: ai
|
|
19
|
+
Provides-Extra: all
|
|
20
|
+
Provides-Extra: local
|
|
21
|
+
Provides-Extra: mysql
|
|
22
|
+
Provides-Extra: opensearch
|
|
23
|
+
Provides-Extra: postgres
|
|
24
|
+
Provides-Extra: s3
|
|
25
|
+
Provides-Extra: sqlserver
|
|
26
|
+
Provides-Extra: sync
|
|
27
|
+
Requires-Dist: aioboto3 (>=10.4) ; extra == "s3" or extra == "all"
|
|
28
|
+
Requires-Dist: aiofiles (>=23.1,<24.0) ; extra == "local" or extra == "all"
|
|
29
|
+
Requires-Dist: aioodbc ; (python_version < "3.12") and (extra == "sqlserver" or extra == "all")
|
|
30
|
+
Requires-Dist: asyncmy (>=0.2,<0.3) ; extra == "mysql" or extra == "all"
|
|
31
|
+
Requires-Dist: asyncpg (>=0.29) ; extra == "postgres" or extra == "all"
|
|
32
|
+
Requires-Dist: boto3 (>=1.24.59) ; extra == "s3" or extra == "sync" or extra == "all"
|
|
33
|
+
Requires-Dist: cryptography (>=41.0) ; extra == "mysql" or extra == "sync" or extra == "all"
|
|
34
|
+
Requires-Dist: greenlet (>=2.0) ; extra == "mysql" or extra == "all"
|
|
35
|
+
Requires-Dist: httpx[http2] (>=0.27.0,<0.28.0) ; extra == "opensearch" or extra == "all"
|
|
36
|
+
Requires-Dist: openai (>=1.0,<2.0) ; extra == "ai" or extra == "all"
|
|
37
|
+
Requires-Dist: psycopg2-binary (>=2.9) ; extra == "postgres" or extra == "sync" or extra == "all"
|
|
38
|
+
Requires-Dist: pymysql (>=1.1,<2.0) ; extra == "sync" or extra == "all"
|
|
39
|
+
Requires-Dist: pyodbc (>=4.0,<5.0) ; (python_version < "3.12") and (extra == "sqlserver" or extra == "sync" or extra == "all")
|
|
40
|
+
Requires-Dist: requests (>=2.31,<3.0) ; extra == "opensearch" or extra == "sync" or extra == "all"
|
|
41
|
+
Requires-Dist: sqlalchemy (>=2.0,<2.1) ; extra == "mysql" or extra == "sync" or extra == "all"
|
|
42
|
+
Project-URL: Documentation, https://aljasem-tech.github.io/multids/
|
|
43
|
+
Project-URL: Homepage, https://github.com/aljasem-tech/multids
|
|
44
|
+
Project-URL: Repository, https://github.com/aljasem-tech/multids
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
|
|
47
|
+
# multids
|
|
48
|
+
|
|
49
|
+
[](https://aljasem-tech.github.io/multids/)
|
|
50
|
+
[](https://github.com/aljasem-tech/multids/actions/workflows/ci.yml)
|
|
51
|
+
[](https://pypi.org/project/multids/)
|
|
52
|
+
[](https://pypi.org/project/multids/)
|
|
53
|
+
[](https://github.com/aljasem-tech/multids/blob/main/LICENSE)
|
|
54
|
+
|
|
55
|
+
Async-first connectors for moving data across S3, OpenSearch, Athena, MySQL, SQL Server, and local files — with a
|
|
56
|
+
single, consistent API for streaming, bulk I/O, resumable uploads, and AI enrichment.
|
|
57
|
+
|
|
58
|
+
`multids` gives you one interface for many backends. Write a pipeline once, then point it at local files for testing
|
|
59
|
+
and at S3 or a database for production. Every connector supports both async and sync usage, typed errors, automatic
|
|
60
|
+
retries, and structured telemetry.
|
|
61
|
+
|
|
62
|
+
Full documentation: **https://aljasem-tech.github.io/multids/**
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Connectors at a glance
|
|
67
|
+
|
|
68
|
+
| Backend | Async | Sync | Install | Good for |
|
|
69
|
+
|--------------|:-----:|:----:|-----------------|-------------------------------------------|
|
|
70
|
+
| Local files | ✅ | ✅ | `multids[local]` | Local disk, temp workspaces, testing |
|
|
71
|
+
| Amazon S3 | ✅ | ✅ | `multids[s3]` | Object storage, data lakes, multipart |
|
|
72
|
+
| OpenSearch | ✅ | ✅ | `multids[opensearch]`| Search, indexing, analytics |
|
|
73
|
+
| Athena | ✅ | ✅ | `multids[s3]` | Querying S3 data with SQL (read-only) |
|
|
74
|
+
| MySQL | ✅ | ✅ | `multids[mysql]` | Relational data via SQLAlchemy |
|
|
75
|
+
| PostgreSQL | ✅ | ✅ | `multids[postgres]` | Relational data via asyncpg (COPY inserts) |
|
|
76
|
+
| SQL Server | ✅ | ✅ | `multids[sqlserver]` | Relational data via ODBC |
|
|
77
|
+
|
|
78
|
+
Every connector implements the same core operations — `read_stream`, `read_bytes`, `write_stream`, `write_bytes`,
|
|
79
|
+
`read_json`, `write_json` — plus backend-specific methods like `bulk_insert` (SQL) and `bulk_index` (OpenSearch).
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Installation
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install multids
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Install only the backends you need:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pip install 'multids[s3]' # S3 + local files
|
|
93
|
+
pip install 'multids[opensearch]' # OpenSearch / Elasticsearch
|
|
94
|
+
pip install 'multids[mysql]' # MySQL (asyncmy + SQLAlchemy)
|
|
95
|
+
pip install 'multids[postgres]' # PostgreSQL (asyncpg + psycopg2)
|
|
96
|
+
pip install 'multids[sqlserver]' # SQL Server (aioodbc + pyodbc)
|
|
97
|
+
pip install 'multids[local]' # Local files (aiofiles)
|
|
98
|
+
pip install 'multids[ai]' # OpenAI-compatible AI hooks
|
|
99
|
+
|
|
100
|
+
# Or install everything:
|
|
101
|
+
pip install 'multids[all]'
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
> **SQL Server note:** the `sqlserver` extra requires an ODBC driver on your system (e.g. *ODBC Driver 18 for SQL
|
|
105
|
+
> Server*). It is not available on Python 3.12+ because `pyodbc` does not publish wheels for those versions.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Quick start
|
|
110
|
+
|
|
111
|
+
### Async: write and read JSON locally
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
import asyncio
|
|
115
|
+
from multids.connectors.local import LocalConnector
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
async def main():
|
|
119
|
+
local = LocalConnector()
|
|
120
|
+
|
|
121
|
+
data = {"message": "Hello", "lang": "你好"}
|
|
122
|
+
|
|
123
|
+
# Write JSON with unescaped Unicode
|
|
124
|
+
await local.write_json(data, "path/to/data.json")
|
|
125
|
+
|
|
126
|
+
# Read it back
|
|
127
|
+
result = await local.read_json("path/to/data.json")
|
|
128
|
+
print(result)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
asyncio.run(main())
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Async: upload to S3
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
import asyncio
|
|
138
|
+
from multids.connectors.s3 import S3Connector
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
async def main():
|
|
142
|
+
s3 = S3Connector(region_name="eu-central-1")
|
|
143
|
+
|
|
144
|
+
# Small payloads use a single PUT automatically
|
|
145
|
+
await s3.write_bytes(b"hello world", "my-bucket", "greeting.txt")
|
|
146
|
+
|
|
147
|
+
# Large streams use multipart upload automatically
|
|
148
|
+
async def gen():
|
|
149
|
+
for _ in range(100):
|
|
150
|
+
yield b"x" * (1024 * 1024) # 1 MiB chunks
|
|
151
|
+
|
|
152
|
+
await s3.write_stream(gen(), "my-bucket", "large-file.bin")
|
|
153
|
+
|
|
154
|
+
# Read back
|
|
155
|
+
data = await s3.read_bytes("my-bucket", "greeting.txt")
|
|
156
|
+
print(data)
|
|
157
|
+
|
|
158
|
+
await s3.close()
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
asyncio.run(main())
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Sync: same API, blocking calls
|
|
165
|
+
|
|
166
|
+
Prefer synchronous code? Every core connector has a sync twin under `multids.connectors.sync`:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from multids.connectors.sync.local import SyncLocalConnector
|
|
170
|
+
from multids.connectors.sync.s3 import SyncS3Connector
|
|
171
|
+
|
|
172
|
+
# Local files
|
|
173
|
+
local = SyncLocalConnector()
|
|
174
|
+
local.write_bytes(b"hello", "out.txt")
|
|
175
|
+
print(local.read_bytes("out.txt"))
|
|
176
|
+
|
|
177
|
+
# S3
|
|
178
|
+
s3 = SyncS3Connector(region_name="eu-central-1")
|
|
179
|
+
s3.write_bytes(b"hello from sync", "my-bucket", "sync.txt")
|
|
180
|
+
print(s3.read_bytes("my-bucket", "sync.txt"))
|
|
181
|
+
s3.close()
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Error handling
|
|
185
|
+
|
|
186
|
+
All connectors raise stable, typed errors from `multids.errors` — you never need to import a backend SDK's exception:
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
import asyncio
|
|
190
|
+
from multids.errors import ConnectorConnectionError, ConnectorOperationError
|
|
191
|
+
from multids.connectors.s3 import S3Connector
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
async def main():
|
|
195
|
+
s3 = S3Connector()
|
|
196
|
+
try:
|
|
197
|
+
await s3.read_bytes("my-bucket", "missing-key")
|
|
198
|
+
except ConnectorOperationError:
|
|
199
|
+
print("Backend rejected the request (e.g. 404, invalid input)")
|
|
200
|
+
except ConnectorConnectionError:
|
|
201
|
+
print("Backend unreachable after retries — check network/credentials")
|
|
202
|
+
finally:
|
|
203
|
+
await s3.close()
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
asyncio.run(main())
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
| Error | Meaning |
|
|
210
|
+
|------------------------------|-----------------------------------------------------------------|
|
|
211
|
+
| `ConnectorError` | Base class for all connector errors |
|
|
212
|
+
| `ConnectorDependencyError` | An optional dependency (driver) is not installed |
|
|
213
|
+
| `ConnectorConnectionError` | Backend unreachable or timed out after retries (safe to retry) |
|
|
214
|
+
| `ConnectorOperationError` | Backend rejected a valid request |
|
|
215
|
+
| `ConnectorSchemaError` | Request/result shape is wrong (subclass of `ConnectorOperationError`) |
|
|
216
|
+
| `ConnectorDataError` | A row/document was rejected (subclass of `ConnectorOperationError`) |
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## S3: multipart and resumable uploads
|
|
221
|
+
|
|
222
|
+
`S3Connector` automatically switches from a single `put_object` to a multipart upload when the payload exceeds
|
|
223
|
+
`min_multipart_upload_size` (default 5 MiB). You can also force multipart for checkpoint-based resume.
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
import asyncio
|
|
227
|
+
from multids.connectors.s3 import S3Connector
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
async def main():
|
|
231
|
+
s3 = S3Connector(part_size=5 * 1024 * 1024)
|
|
232
|
+
|
|
233
|
+
async def stream():
|
|
234
|
+
for _ in range(100):
|
|
235
|
+
yield b"{" + b" " * 1024 + b"}\n"
|
|
236
|
+
|
|
237
|
+
checkpoint = "/tmp/uploads/my-object.chk"
|
|
238
|
+
|
|
239
|
+
# First attempt: start upload and write a checkpoint
|
|
240
|
+
await s3.write_stream(
|
|
241
|
+
stream(),
|
|
242
|
+
"my-bucket",
|
|
243
|
+
"my-object.json",
|
|
244
|
+
checkpoint_path=checkpoint,
|
|
245
|
+
force_multipart=True,
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
# If interrupted, rerun with resume=True — committed parts are not re-uploaded
|
|
249
|
+
await s3.write_stream(
|
|
250
|
+
stream(),
|
|
251
|
+
"my-bucket",
|
|
252
|
+
"my-object.json",
|
|
253
|
+
checkpoint_path=checkpoint,
|
|
254
|
+
resume=True,
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
await s3.close()
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
asyncio.run(main())
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
The checkpoint file stores the `bucket`, `key`, `upload_id`, and completed parts so a retry continues from the last
|
|
264
|
+
committed part instead of restarting from byte 0.
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## SQL connectors (MySQL, SQL Server)
|
|
269
|
+
|
|
270
|
+
SQL connectors provide `execute`, `fetch_rows`, `bulk_insert`, and record-streaming helpers. They use SQLAlchemy
|
|
271
|
+
under the hood and create their engine lazily on first use.
|
|
272
|
+
|
|
273
|
+
```python
|
|
274
|
+
import asyncio
|
|
275
|
+
from multids.connectors.sql import MySQLConnector
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
async def main():
|
|
279
|
+
mysql = MySQLConnector("mysql+asyncmy://user:pass@localhost:3306/db")
|
|
280
|
+
|
|
281
|
+
rows = [{"id": i, "name": f"name-{i}"} for i in range(1000)]
|
|
282
|
+
result = await mysql.bulk_insert("users", rows, chunk_size=200)
|
|
283
|
+
print(f"Inserted {result.items_written} rows")
|
|
284
|
+
|
|
285
|
+
fetched = await mysql.fetch_rows("SELECT id, name FROM users LIMIT 10")
|
|
286
|
+
for row in fetched:
|
|
287
|
+
print(row)
|
|
288
|
+
|
|
289
|
+
await mysql.close()
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
asyncio.run(main())
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Sync equivalent:
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
from multids.connectors.sync.sql import SyncMySQLConnector
|
|
299
|
+
|
|
300
|
+
mysql = SyncMySQLConnector("mysql+pymysql://user:pass@localhost:3306/db")
|
|
301
|
+
mysql.bulk_insert("users", [{"id": 1, "name": "alice"}], chunk_size=100)
|
|
302
|
+
rows = mysql.fetch_rows("SELECT id, name FROM users")
|
|
303
|
+
mysql.close()
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
For SQL Server, use `MSSQLConnector` (async) or `SyncMSSQLConnector` (sync) with an ODBC connection string:
|
|
307
|
+
|
|
308
|
+
```python
|
|
309
|
+
import asyncio
|
|
310
|
+
from multids.connectors.mssql import MSSQLConnector
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
async def main():
|
|
314
|
+
conn = MSSQLConnector(
|
|
315
|
+
"DRIVER={ODBC Driver 18 for SQL Server};SERVER=localhost,1433;DATABASE=master;UID=sa;PWD=YourPassword;TrustServerCertificate=yes"
|
|
316
|
+
)
|
|
317
|
+
await conn.connect_pool()
|
|
318
|
+
rows = await conn.fetch_rows("SELECT id, name FROM users")
|
|
319
|
+
await conn.close()
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
asyncio.run(main())
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### PostgreSQL
|
|
326
|
+
|
|
327
|
+
`PostgreSQLConnector` uses `asyncpg` directly and supports native COPY-protocol bulk inserts for high-throughput
|
|
328
|
+
ingestion:
|
|
329
|
+
|
|
330
|
+
```python
|
|
331
|
+
import asyncio
|
|
332
|
+
from multids.connectors.postgres import PostgreSQLConnector
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
async def main():
|
|
336
|
+
pg = PostgreSQLConnector("postgresql://user:pass@localhost:5432/db")
|
|
337
|
+
|
|
338
|
+
# Bulk insert via COPY (fastest path)
|
|
339
|
+
rows = [{"id": i, "name": f"name-{i}"} for i in range(10000)]
|
|
340
|
+
result = await pg.bulk_insert("users", rows)
|
|
341
|
+
print(f"Inserted {result.items_written} rows via COPY")
|
|
342
|
+
|
|
343
|
+
# Streaming reads with $1-style parameters
|
|
344
|
+
async for row in pg.fetch_rows("SELECT * FROM users WHERE id > $1", 100):
|
|
345
|
+
print(row)
|
|
346
|
+
|
|
347
|
+
await pg.close()
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
asyncio.run(main())
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
Sync equivalent:
|
|
354
|
+
|
|
355
|
+
```python
|
|
356
|
+
from multids.connectors.sync.postgres import SyncPostgreSQLConnector
|
|
357
|
+
|
|
358
|
+
pg = SyncPostgreSQLConnector("postgresql://user:pass@localhost:5432/db")
|
|
359
|
+
pg.bulk_insert("users", [{"id": 1, "name": "alice"}])
|
|
360
|
+
rows = list(pg.fetch_rows("SELECT * FROM users WHERE id > %s", (0,)))
|
|
361
|
+
pg.close()
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
## OpenSearch
|
|
367
|
+
|
|
368
|
+
`OpenSearchConnector` is an async, `httpx`-based client for indexing, searching, and scrolling OpenSearch /
|
|
369
|
+
Elasticsearch.
|
|
370
|
+
|
|
371
|
+
```python
|
|
372
|
+
import asyncio
|
|
373
|
+
from multids.connectors.opensearch import OpenSearchConnector
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
async def main():
|
|
377
|
+
oc = OpenSearchConnector("http://localhost:9200")
|
|
378
|
+
|
|
379
|
+
# Index a single document
|
|
380
|
+
await oc.index_doc("my-index", {"name": "alice"})
|
|
381
|
+
|
|
382
|
+
# Bulk index
|
|
383
|
+
docs = [{"id": 1, "name": "a"}, {"id": 2, "name": "b"}]
|
|
384
|
+
await oc.bulk_index("my-index", docs, chunk_size=100)
|
|
385
|
+
|
|
386
|
+
# Search
|
|
387
|
+
result = await oc.search("my-index", {"query": {"match_all": {}}}, size=10)
|
|
388
|
+
|
|
389
|
+
# Scroll over large result sets
|
|
390
|
+
async for hit in oc.scroll("my-index", {"query": {"match_all": {}}}):
|
|
391
|
+
print(hit)
|
|
392
|
+
|
|
393
|
+
await oc.close()
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
asyncio.run(main())
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Authentication:
|
|
400
|
+
|
|
401
|
+
```python
|
|
402
|
+
from multids.connectors.opensearch import OpenSearchConnector
|
|
403
|
+
|
|
404
|
+
# API key
|
|
405
|
+
oc = OpenSearchConnector("https://es.example.com", api_key="BASE64_API_KEY")
|
|
406
|
+
|
|
407
|
+
# Basic auth
|
|
408
|
+
oc = OpenSearchConnector("https://es.example.com", basic_auth=("user", "pass"))
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
Synchronous variant:
|
|
412
|
+
|
|
413
|
+
```python
|
|
414
|
+
from multids.connectors.sync.opensearch import SyncOpenSearchConnector
|
|
415
|
+
|
|
416
|
+
oc = SyncOpenSearchConnector("http://localhost:9200")
|
|
417
|
+
|
|
418
|
+
# Index a single document
|
|
419
|
+
oc.index_doc("my-index", {"name": "alice"})
|
|
420
|
+
|
|
421
|
+
# Bulk index
|
|
422
|
+
docs = [{"id": 1, "name": "a"}, {"id": 2, "name": "b"}]
|
|
423
|
+
oc.bulk_index("my-index", docs, chunk_size=100)
|
|
424
|
+
|
|
425
|
+
# Search
|
|
426
|
+
result = oc.search("my-index", {"query": {"match_all": {}}}, size=10)
|
|
427
|
+
|
|
428
|
+
# Scroll over large result sets
|
|
429
|
+
for hit in oc.scroll("my-index", {"query": {"match_all": {}}}):
|
|
430
|
+
print(hit)
|
|
431
|
+
|
|
432
|
+
oc.close()
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
## AI enrichment
|
|
438
|
+
|
|
439
|
+
`multids.ai` provides a pluggable text-generation interface that works with any OpenAI-compatible client. Use it to
|
|
440
|
+
enrich records before indexing them:
|
|
441
|
+
|
|
442
|
+
```python
|
|
443
|
+
import asyncio
|
|
444
|
+
from openai import AsyncOpenAI
|
|
445
|
+
from multids.ai import OpenAIClient
|
|
446
|
+
from multids.connectors.opensearch import OpenSearchConnector
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
async def main():
|
|
450
|
+
ai = OpenAIClient(AsyncOpenAI())
|
|
451
|
+
oc = OpenSearchConnector("http://localhost:9200")
|
|
452
|
+
|
|
453
|
+
docs = [{"id": "1", "text": "OpenSearch + AI"}]
|
|
454
|
+
for doc in docs:
|
|
455
|
+
response = await ai.generate(doc["text"], model="gpt-4o-mini")
|
|
456
|
+
doc["summary"] = response["content"]
|
|
457
|
+
|
|
458
|
+
await oc.bulk_index("my-index", docs)
|
|
459
|
+
await oc.close()
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
asyncio.run(main())
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
## Data workflows
|
|
468
|
+
|
|
469
|
+
`multids.workflows` connects two connectors without buffering the whole payload in memory:
|
|
470
|
+
|
|
471
|
+
```python
|
|
472
|
+
import asyncio
|
|
473
|
+
from multids.connectors.local import LocalConnector
|
|
474
|
+
from multids.connectors.s3 import S3Connector
|
|
475
|
+
from multids.workflows import copy_stream
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
async def main():
|
|
479
|
+
local = LocalConnector(base_path="./exports")
|
|
480
|
+
s3 = S3Connector(region_name="eu-central-1")
|
|
481
|
+
|
|
482
|
+
result = await copy_stream(
|
|
483
|
+
local,
|
|
484
|
+
s3,
|
|
485
|
+
source_args=("daily/events.jsonl",),
|
|
486
|
+
destination_args=("my-bucket", "exports/events.jsonl"),
|
|
487
|
+
)
|
|
488
|
+
print(f"Copied {result.bytes_copied} bytes in {result.chunks_copied} chunks")
|
|
489
|
+
|
|
490
|
+
await local.close()
|
|
491
|
+
await s3.close()
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
asyncio.run(main())
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
See [docs/workflows.md](docs/workflows.md) for record transforms, batching, and checkpoints.
|
|
498
|
+
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
## CLI
|
|
502
|
+
|
|
503
|
+
A built-in CLI handles safe local-file operations:
|
|
504
|
+
|
|
505
|
+
```bash
|
|
506
|
+
multids ping --path ./data
|
|
507
|
+
multids copy ./data/input.jsonl ./out/input.jsonl
|
|
508
|
+
multids validate workflow.json
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
---
|
|
512
|
+
|
|
513
|
+
## Documentation
|
|
514
|
+
|
|
515
|
+
| Guide | Description |
|
|
516
|
+
|--------------------|----------------------------------------------------------|
|
|
517
|
+
| [Quickstart](docs/quickstart.md) | Install and run your first connector |
|
|
518
|
+
| [Usage](docs/usage.md) | Patterns for every backend, sync and async |
|
|
519
|
+
| [API reference](docs/api.md) | Method signatures, errors, contracts |
|
|
520
|
+
| [Data workflows](docs/workflows.md) | Copy, transform, and batch between connectors |
|
|
521
|
+
| [Reliability](docs/observability.md) | Retries, timeouts, telemetry, error handling |
|
|
522
|
+
| [Support matrix](docs/support.md) | Python versions, extras, CI coverage |
|
|
523
|
+
|
|
524
|
+
---
|
|
525
|
+
|
|
526
|
+
## Contributing
|
|
527
|
+
|
|
528
|
+
Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, testing, and the pull
|
|
529
|
+
request process.
|
|
530
|
+
|
|
531
|
+
## License
|
|
532
|
+
|
|
533
|
+
MIT — see [LICENSE](LICENSE).
|
|
534
|
+
|