multids 0.1.0__tar.gz → 0.2.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.
- multids-0.2.0/PKG-INFO +382 -0
- multids-0.2.0/README.md +341 -0
- multids-0.2.0/pyproject.toml +73 -0
- {multids-0.1.0 → multids-0.2.0}/src/multids/__init__.py +1 -1
- multids-0.2.0/src/multids/ai.py +41 -0
- multids-0.2.0/src/multids/cli.py +84 -0
- {multids-0.1.0 → multids-0.2.0}/src/multids/connectors/athena.py +4 -2
- multids-0.2.0/src/multids/connectors/local.py +146 -0
- {multids-0.1.0 → multids-0.2.0}/src/multids/connectors/mssql.py +22 -3
- {multids-0.1.0 → multids-0.2.0}/src/multids/connectors/opensearch.py +95 -42
- {multids-0.1.0 → multids-0.2.0}/src/multids/connectors/s3.py +142 -21
- {multids-0.1.0 → multids-0.2.0}/src/multids/connectors/sql.py +34 -10
- multids-0.2.0/src/multids/connectors/sync/__init__.py +14 -0
- multids-0.2.0/src/multids/connectors/sync/athena.py +145 -0
- multids-0.2.0/src/multids/connectors/sync/local.py +127 -0
- multids-0.2.0/src/multids/connectors/sync/mssql.py +144 -0
- multids-0.2.0/src/multids/connectors/sync/s3.py +254 -0
- multids-0.2.0/src/multids/connectors/sync/sql.py +117 -0
- multids-0.2.0/src/multids/contracts.py +108 -0
- multids-0.2.0/src/multids/errors.py +25 -0
- multids-0.2.0/src/multids/interfaces.py +147 -0
- multids-0.2.0/src/multids/reliability.py +63 -0
- multids-0.2.0/src/multids/workflows.py +187 -0
- multids-0.1.0/PKG-INFO +0 -305
- multids-0.1.0/README.md +0 -274
- multids-0.1.0/pyproject.toml +0 -57
- multids-0.1.0/src/multids/ai.py +0 -18
- multids-0.1.0/src/multids/connectors/local.py +0 -42
- multids-0.1.0/src/multids/interfaces.py +0 -67
- {multids-0.1.0 → multids-0.2.0}/LICENSE +0 -0
- {multids-0.1.0 → multids-0.2.0}/src/multids/connectors/__init__.py +0 -0
multids-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: multids
|
|
3
|
+
Version: 0.2.0
|
|
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
|
+
Provides-Extra: ai
|
|
18
|
+
Provides-Extra: all
|
|
19
|
+
Provides-Extra: local
|
|
20
|
+
Provides-Extra: mysql
|
|
21
|
+
Provides-Extra: opensearch
|
|
22
|
+
Provides-Extra: s3
|
|
23
|
+
Provides-Extra: sqlserver
|
|
24
|
+
Provides-Extra: sync
|
|
25
|
+
Requires-Dist: aioboto3 (>=10.4.0,<11.0.0) ; extra == "s3" or extra == "all"
|
|
26
|
+
Requires-Dist: aiofiles (>=23.1,<24.0) ; extra == "local" or extra == "all"
|
|
27
|
+
Requires-Dist: aioodbc ; (python_version < "3.12") and (extra == "sqlserver" or extra == "all")
|
|
28
|
+
Requires-Dist: asyncmy (>=0.2,<0.3) ; extra == "mysql" or extra == "all"
|
|
29
|
+
Requires-Dist: boto3 (>=1.24.59,<1.24.60) ; extra == "s3" or extra == "sync" or extra == "all"
|
|
30
|
+
Requires-Dist: httpx[http2] (>=0.24.0,<0.25.0) ; extra == "opensearch" or extra == "all"
|
|
31
|
+
Requires-Dist: openai (>=1.0,<2.0) ; extra == "ai" or extra == "all"
|
|
32
|
+
Requires-Dist: pymysql (>=1.1,<2.0) ; extra == "sync" or extra == "all"
|
|
33
|
+
Requires-Dist: pyodbc (>=4.0,<5.0) ; (python_version < "3.12") and (extra == "sqlserver" or extra == "sync" or extra == "all")
|
|
34
|
+
Requires-Dist: requests (>=2.31,<3.0) ; extra == "opensearch" or extra == "sync" or extra == "all"
|
|
35
|
+
Requires-Dist: sqlalchemy (>=2.0,<3.0) ; extra == "mysql" or extra == "sync" or extra == "all"
|
|
36
|
+
Project-URL: Documentation, https://aljasem-tech.github.io/multids/
|
|
37
|
+
Project-URL: Homepage, https://github.com/aljasem-tech/multids
|
|
38
|
+
Project-URL: Repository, https://github.com/aljasem-tech/multids
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
|
|
41
|
+
# multids
|
|
42
|
+
|
|
43
|
+
[](https://aljasem-tech.github.io/multids/)
|
|
44
|
+
[](https://github.com/aljasem-tech/multids/actions/workflows/ci.yml)
|
|
45
|
+
[](https://pypi.org/project/multids/)
|
|
46
|
+
[](https://pepy.tech/projects/multids)
|
|
47
|
+
[](https://github.com/aljasem-tech/multids)
|
|
48
|
+
|
|
49
|
+
Async multi–data-source connectors for Python.
|
|
50
|
+
`multids` is an async-first library for moving data across S3, OpenSearch, Athena, MySQL, SQL Server, and local files.
|
|
51
|
+
It combines protocol-based abstractions, sync adapters, streaming and bulk read/write helpers, resumable multipart uploads,
|
|
52
|
+
and optional AI hooks into a composable toolkit for practical data workflows.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Why multids
|
|
57
|
+
|
|
58
|
+
- Build async pipelines around a consistent connector interface.
|
|
59
|
+
- Use sync adapters when a blocking workflow is easier to integrate.
|
|
60
|
+
- Move data with streaming and bulk-style operations.
|
|
61
|
+
- Add AI-driven processing with lightweight hooks for enrichment or transformation.
|
|
62
|
+
- Start from examples and tests that cover common integration patterns.
|
|
63
|
+
|
|
64
|
+
## Features
|
|
65
|
+
|
|
66
|
+
- Async connectors for local files, AWS S3, OpenSearch / Elasticsearch, AWS Athena, MySQL, and SQL Server.
|
|
67
|
+
- Protocol-based abstractions for readable, writable, and connector behaviors.
|
|
68
|
+
- Sync adapters for local files and S3 workflows under `multids.connectors.sync`.
|
|
69
|
+
- Unified read/write APIs for streaming and bulk operations.
|
|
70
|
+
- JSON helpers with proper Unicode handling (no escaped `你好` / `مرحبا`).
|
|
71
|
+
- Resumable multipart uploads for S3 with checkpoint support.
|
|
72
|
+
- Optional AI hooks built around an OpenAI-compatible interface.
|
|
73
|
+
- Integration tests and example scripts for common workflows.
|
|
74
|
+
|
|
75
|
+
See the full documentation at: https://aljasem-tech.github.io/multids/
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Installation
|
|
80
|
+
|
|
81
|
+
Install the core library:
|
|
82
|
+
|
|
83
|
+
```powershell
|
|
84
|
+
pip install multids
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Optional extras:
|
|
88
|
+
|
|
89
|
+
```powershell
|
|
90
|
+
# AI features (OpenAI client, etc.)
|
|
91
|
+
|
|
92
|
+
pip install 'multids[ai]'
|
|
93
|
+
|
|
94
|
+
# S3 and local file helpers
|
|
95
|
+
|
|
96
|
+
pip install 'multids[s3]'
|
|
97
|
+
|
|
98
|
+
# OpenSearch connector
|
|
99
|
+
|
|
100
|
+
pip install 'multids[opensearch]'
|
|
101
|
+
|
|
102
|
+
# SQL Server connector (requires system ODBC driver)
|
|
103
|
+
|
|
104
|
+
pip install 'multids[sqlserver]'
|
|
105
|
+
|
|
106
|
+
# Everything commonly used together
|
|
107
|
+
|
|
108
|
+
pip install 'multids[ai,s3,opensearch,sqlserver]'
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
> Note: For SQL Server, you must have a SQL Server ODBC driver installed on your system (for example, “Microsoft ODBC
|
|
113
|
+
> Driver for SQL Server” on Linux/Windows).
|
|
114
|
+
|
|
115
|
+
If you prefer `poetry`:
|
|
116
|
+
|
|
117
|
+
```powershell
|
|
118
|
+
poetry add multids
|
|
119
|
+
poetry add multids -E ai -E s3 -E opensearch -E sqlserver
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Quick start
|
|
125
|
+
|
|
126
|
+
### Basic usage
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
|
|
130
|
+
import asyncio
|
|
131
|
+
from multids.connectors.local import LocalConnector
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
async def main():
|
|
135
|
+
local = LocalConnector()
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
data = {"message": "Hello", "lang": "你好"}
|
|
139
|
+
|
|
140
|
+
# Write JSON with unescaped Unicode
|
|
141
|
+
await local.write_json(data, "path/to/data.json")
|
|
142
|
+
|
|
143
|
+
# Read JSON back
|
|
144
|
+
result = await local.read_json("path/to/data.json")
|
|
145
|
+
print(result)
|
|
146
|
+
|
|
147
|
+
asyncio.run(main())
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
More examples are available under `examples/` in the repository.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## JSON helpers
|
|
156
|
+
|
|
157
|
+
### Local JSON
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
|
|
161
|
+
from multids.connectors.local import LocalConnector
|
|
162
|
+
|
|
163
|
+
local = LocalConnector()
|
|
164
|
+
|
|
165
|
+
data = {"message": "Hello", "lang": "你好"}
|
|
166
|
+
|
|
167
|
+
# Write JSON (un-escaped unicode)
|
|
168
|
+
|
|
169
|
+
await local.write_json(data, "path/to/data.json")
|
|
170
|
+
|
|
171
|
+
# Read JSON
|
|
172
|
+
|
|
173
|
+
result = await local.read_json("path/to/data.json")
|
|
174
|
+
print(result)
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### S3 JSON
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
|
|
182
|
+
from multids.connectors.s3 import S3Connector
|
|
183
|
+
|
|
184
|
+
s3 = S3Connector(aws_region="eu-central-1")
|
|
185
|
+
|
|
186
|
+
data = {"status": "ok", "info": "مرحبا"}
|
|
187
|
+
|
|
188
|
+
# Upload JSON object
|
|
189
|
+
|
|
190
|
+
await s3.write_json(data, bucket="my-bucket", key="status.json")
|
|
191
|
+
|
|
192
|
+
# Download and parse JSON
|
|
193
|
+
|
|
194
|
+
result = await s3.read_json(bucket="my-bucket", key="status.json")
|
|
195
|
+
print(result)
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## S3 uploads: multipart & resumable
|
|
202
|
+
|
|
203
|
+
`S3Connector` supports both single PUT and multipart uploads, plus optional resumable uploads via checkpoints.
|
|
204
|
+
|
|
205
|
+
Key options (constructor / write-time):
|
|
206
|
+
|
|
207
|
+
- `min_multipart_upload_size` (default: 5 MiB)
|
|
208
|
+
Threshold for switching from a single `put_object` to multipart upload.
|
|
209
|
+
- `part_size` (default: 8 MiB)
|
|
210
|
+
Size of each multipart part.
|
|
211
|
+
- `enforce_min_part_size` (default: `False`)
|
|
212
|
+
When `True`, enforces AWS’s minimum 5 MiB part size.
|
|
213
|
+
- `force_multipart` (write-time flag, default `False`)
|
|
214
|
+
Force multipart even for small objects (for resumable semantics).
|
|
215
|
+
|
|
216
|
+
Example: force multipart for a small stream to enable checkpointing:
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
|
|
220
|
+
async def small_stream():
|
|
221
|
+
for _ in range(100):
|
|
222
|
+
yield b"{" + b" " * 1024 + b"}\n"
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
await s3.write_stream(
|
|
226
|
+
small_stream(),
|
|
227
|
+
bucket="my-bucket",
|
|
228
|
+
key="my-object.json",
|
|
229
|
+
force_multipart=True,
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Resumable uploads with checkpoints
|
|
235
|
+
|
|
236
|
+
If you pass a `checkpoint_path`, the connector will store a small JSON file describing the multipart upload. On restart
|
|
237
|
+
you can resume:
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
|
|
241
|
+
from multids.connectors.s3 import S3Connector
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
async def upload_with_resume():
|
|
245
|
+
conn = S3Connector(part_size=5 * 1024 * 1024)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
chk = "/tmp/uploads/my-object.chk"
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
async def small_stream():
|
|
252
|
+
for _ in range(100):
|
|
253
|
+
yield b"{" + b" " * 1024 + b"}\n"
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
# First attempt: start upload and write checkpoint
|
|
257
|
+
await conn.write_stream(
|
|
258
|
+
small_stream(),
|
|
259
|
+
bucket="my-bucket",
|
|
260
|
+
key="my-object.json",
|
|
261
|
+
checkpoint_path=chk,
|
|
262
|
+
force_multipart=True,
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
# If interrupted, rerun with resume=True
|
|
266
|
+
await conn.write_stream(
|
|
267
|
+
small_stream(),
|
|
268
|
+
bucket="my-bucket",
|
|
269
|
+
key="my-object.json",
|
|
270
|
+
checkpoint_path=chk,
|
|
271
|
+
resume=True,
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
await conn.close()
|
|
275
|
+
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
The checkpoint file stores `bucket`, `key`, `upload_id`, and completed parts.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## SQL Server connector
|
|
283
|
+
|
|
284
|
+
`MSSQLConnector` provides an async SQL Server connector built on `aioodbc` (ODBC).
|
|
285
|
+
|
|
286
|
+
System requirements:
|
|
287
|
+
|
|
288
|
+
- A SQL Server ODBC driver installed on your host (for example, “ODBC Driver 18 for SQL Server”).
|
|
289
|
+
|
|
290
|
+
Install the extras:
|
|
291
|
+
|
|
292
|
+
```powershell
|
|
293
|
+
pip install 'multids[sqlserver]'
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Example:
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
|
|
300
|
+
from multids.connectors.mssql import MSSQLConnector
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
async def example():
|
|
304
|
+
conn = MSSQLConnector()
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
# Configure connection string/DSN via env or arguments, then:
|
|
308
|
+
await conn.connect_pool()
|
|
309
|
+
rows = await conn.fetch_rows("SELECT id, name FROM users")
|
|
310
|
+
await conn.close()
|
|
311
|
+
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## OpenSearch connector
|
|
317
|
+
|
|
318
|
+
`OpenSearchConnector` is an async, `httpx`-based helper for indexing and querying OpenSearch/Elasticsearch.
|
|
319
|
+
|
|
320
|
+
Install:
|
|
321
|
+
|
|
322
|
+
```powershell
|
|
323
|
+
pip install 'multids[opensearch]'
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Example:
|
|
327
|
+
|
|
328
|
+
```python
|
|
329
|
+
|
|
330
|
+
from multids.connectors.opensearch import OpenSearchConnector
|
|
331
|
+
|
|
332
|
+
oc = OpenSearchConnector("http://localhost:9200")
|
|
333
|
+
|
|
334
|
+
# Index a document
|
|
335
|
+
|
|
336
|
+
await oc.index_doc("my-index", {"name": "alice"})
|
|
337
|
+
|
|
338
|
+
# Bulk index
|
|
339
|
+
|
|
340
|
+
docs = [{"id": 1, "name": "a"}, {"id": 2, "name": "b"}]
|
|
341
|
+
await oc.bulk_index("my-index", docs, chunk_size=100)
|
|
342
|
+
|
|
343
|
+
# Search
|
|
344
|
+
|
|
345
|
+
res = await oc.search("my-index", {"query": {"match_all": {}}}, size=10)
|
|
346
|
+
|
|
347
|
+
# Scroll over results
|
|
348
|
+
|
|
349
|
+
async for hit in oc.scroll("my-index", {"query": {"match_all": {}}}):
|
|
350
|
+
print(hit)
|
|
351
|
+
|
|
352
|
+
await oc.close()
|
|
353
|
+
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Authentication examples:
|
|
357
|
+
|
|
358
|
+
```python
|
|
359
|
+
|
|
360
|
+
# API key
|
|
361
|
+
|
|
362
|
+
oc = OpenSearchConnector("https://es.example.com", api_key="BASE64_API_KEY")
|
|
363
|
+
|
|
364
|
+
# Basic auth
|
|
365
|
+
|
|
366
|
+
oc = OpenSearchConnector("https://es.example.com", basic_auth=("user", "pass"))
|
|
367
|
+
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
## Development and contributing
|
|
373
|
+
|
|
374
|
+
Development setup, virtualenv/Poetry instructions, and contribution guidelines are documented in:
|
|
375
|
+
|
|
376
|
+
- `CONTRIBUTING.md`
|
|
377
|
+
- `docs/` (developer guide)
|
|
378
|
+
|
|
379
|
+
Contributions, bug reports, and feature requests are welcome via GitHub issues and pull requests.
|
|
380
|
+
|
|
381
|
+
```
|
|
382
|
+
|
multids-0.2.0/README.md
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
# multids
|
|
2
|
+
|
|
3
|
+
[](https://aljasem-tech.github.io/multids/)
|
|
4
|
+
[](https://github.com/aljasem-tech/multids/actions/workflows/ci.yml)
|
|
5
|
+
[](https://pypi.org/project/multids/)
|
|
6
|
+
[](https://pepy.tech/projects/multids)
|
|
7
|
+
[](https://github.com/aljasem-tech/multids)
|
|
8
|
+
|
|
9
|
+
Async multi–data-source connectors for Python.
|
|
10
|
+
`multids` is an async-first library for moving data across S3, OpenSearch, Athena, MySQL, SQL Server, and local files.
|
|
11
|
+
It combines protocol-based abstractions, sync adapters, streaming and bulk read/write helpers, resumable multipart uploads,
|
|
12
|
+
and optional AI hooks into a composable toolkit for practical data workflows.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Why multids
|
|
17
|
+
|
|
18
|
+
- Build async pipelines around a consistent connector interface.
|
|
19
|
+
- Use sync adapters when a blocking workflow is easier to integrate.
|
|
20
|
+
- Move data with streaming and bulk-style operations.
|
|
21
|
+
- Add AI-driven processing with lightweight hooks for enrichment or transformation.
|
|
22
|
+
- Start from examples and tests that cover common integration patterns.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- Async connectors for local files, AWS S3, OpenSearch / Elasticsearch, AWS Athena, MySQL, and SQL Server.
|
|
27
|
+
- Protocol-based abstractions for readable, writable, and connector behaviors.
|
|
28
|
+
- Sync adapters for local files and S3 workflows under `multids.connectors.sync`.
|
|
29
|
+
- Unified read/write APIs for streaming and bulk operations.
|
|
30
|
+
- JSON helpers with proper Unicode handling (no escaped `你好` / `مرحبا`).
|
|
31
|
+
- Resumable multipart uploads for S3 with checkpoint support.
|
|
32
|
+
- Optional AI hooks built around an OpenAI-compatible interface.
|
|
33
|
+
- Integration tests and example scripts for common workflows.
|
|
34
|
+
|
|
35
|
+
See the full documentation at: https://aljasem-tech.github.io/multids/
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
Install the core library:
|
|
42
|
+
|
|
43
|
+
```powershell
|
|
44
|
+
pip install multids
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Optional extras:
|
|
48
|
+
|
|
49
|
+
```powershell
|
|
50
|
+
# AI features (OpenAI client, etc.)
|
|
51
|
+
|
|
52
|
+
pip install 'multids[ai]'
|
|
53
|
+
|
|
54
|
+
# S3 and local file helpers
|
|
55
|
+
|
|
56
|
+
pip install 'multids[s3]'
|
|
57
|
+
|
|
58
|
+
# OpenSearch connector
|
|
59
|
+
|
|
60
|
+
pip install 'multids[opensearch]'
|
|
61
|
+
|
|
62
|
+
# SQL Server connector (requires system ODBC driver)
|
|
63
|
+
|
|
64
|
+
pip install 'multids[sqlserver]'
|
|
65
|
+
|
|
66
|
+
# Everything commonly used together
|
|
67
|
+
|
|
68
|
+
pip install 'multids[ai,s3,opensearch,sqlserver]'
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
> Note: For SQL Server, you must have a SQL Server ODBC driver installed on your system (for example, “Microsoft ODBC
|
|
73
|
+
> Driver for SQL Server” on Linux/Windows).
|
|
74
|
+
|
|
75
|
+
If you prefer `poetry`:
|
|
76
|
+
|
|
77
|
+
```powershell
|
|
78
|
+
poetry add multids
|
|
79
|
+
poetry add multids -E ai -E s3 -E opensearch -E sqlserver
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Quick start
|
|
85
|
+
|
|
86
|
+
### Basic usage
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
|
|
90
|
+
import asyncio
|
|
91
|
+
from multids.connectors.local import LocalConnector
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
async def main():
|
|
95
|
+
local = LocalConnector()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
data = {"message": "Hello", "lang": "你好"}
|
|
99
|
+
|
|
100
|
+
# Write JSON with unescaped Unicode
|
|
101
|
+
await local.write_json(data, "path/to/data.json")
|
|
102
|
+
|
|
103
|
+
# Read JSON back
|
|
104
|
+
result = await local.read_json("path/to/data.json")
|
|
105
|
+
print(result)
|
|
106
|
+
|
|
107
|
+
asyncio.run(main())
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
More examples are available under `examples/` in the repository.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## JSON helpers
|
|
116
|
+
|
|
117
|
+
### Local JSON
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
|
|
121
|
+
from multids.connectors.local import LocalConnector
|
|
122
|
+
|
|
123
|
+
local = LocalConnector()
|
|
124
|
+
|
|
125
|
+
data = {"message": "Hello", "lang": "你好"}
|
|
126
|
+
|
|
127
|
+
# Write JSON (un-escaped unicode)
|
|
128
|
+
|
|
129
|
+
await local.write_json(data, "path/to/data.json")
|
|
130
|
+
|
|
131
|
+
# Read JSON
|
|
132
|
+
|
|
133
|
+
result = await local.read_json("path/to/data.json")
|
|
134
|
+
print(result)
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### S3 JSON
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
|
|
142
|
+
from multids.connectors.s3 import S3Connector
|
|
143
|
+
|
|
144
|
+
s3 = S3Connector(aws_region="eu-central-1")
|
|
145
|
+
|
|
146
|
+
data = {"status": "ok", "info": "مرحبا"}
|
|
147
|
+
|
|
148
|
+
# Upload JSON object
|
|
149
|
+
|
|
150
|
+
await s3.write_json(data, bucket="my-bucket", key="status.json")
|
|
151
|
+
|
|
152
|
+
# Download and parse JSON
|
|
153
|
+
|
|
154
|
+
result = await s3.read_json(bucket="my-bucket", key="status.json")
|
|
155
|
+
print(result)
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## S3 uploads: multipart & resumable
|
|
162
|
+
|
|
163
|
+
`S3Connector` supports both single PUT and multipart uploads, plus optional resumable uploads via checkpoints.
|
|
164
|
+
|
|
165
|
+
Key options (constructor / write-time):
|
|
166
|
+
|
|
167
|
+
- `min_multipart_upload_size` (default: 5 MiB)
|
|
168
|
+
Threshold for switching from a single `put_object` to multipart upload.
|
|
169
|
+
- `part_size` (default: 8 MiB)
|
|
170
|
+
Size of each multipart part.
|
|
171
|
+
- `enforce_min_part_size` (default: `False`)
|
|
172
|
+
When `True`, enforces AWS’s minimum 5 MiB part size.
|
|
173
|
+
- `force_multipart` (write-time flag, default `False`)
|
|
174
|
+
Force multipart even for small objects (for resumable semantics).
|
|
175
|
+
|
|
176
|
+
Example: force multipart for a small stream to enable checkpointing:
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
|
|
180
|
+
async def small_stream():
|
|
181
|
+
for _ in range(100):
|
|
182
|
+
yield b"{" + b" " * 1024 + b"}\n"
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
await s3.write_stream(
|
|
186
|
+
small_stream(),
|
|
187
|
+
bucket="my-bucket",
|
|
188
|
+
key="my-object.json",
|
|
189
|
+
force_multipart=True,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Resumable uploads with checkpoints
|
|
195
|
+
|
|
196
|
+
If you pass a `checkpoint_path`, the connector will store a small JSON file describing the multipart upload. On restart
|
|
197
|
+
you can resume:
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
|
|
201
|
+
from multids.connectors.s3 import S3Connector
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
async def upload_with_resume():
|
|
205
|
+
conn = S3Connector(part_size=5 * 1024 * 1024)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
chk = "/tmp/uploads/my-object.chk"
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
async def small_stream():
|
|
212
|
+
for _ in range(100):
|
|
213
|
+
yield b"{" + b" " * 1024 + b"}\n"
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
# First attempt: start upload and write checkpoint
|
|
217
|
+
await conn.write_stream(
|
|
218
|
+
small_stream(),
|
|
219
|
+
bucket="my-bucket",
|
|
220
|
+
key="my-object.json",
|
|
221
|
+
checkpoint_path=chk,
|
|
222
|
+
force_multipart=True,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
# If interrupted, rerun with resume=True
|
|
226
|
+
await conn.write_stream(
|
|
227
|
+
small_stream(),
|
|
228
|
+
bucket="my-bucket",
|
|
229
|
+
key="my-object.json",
|
|
230
|
+
checkpoint_path=chk,
|
|
231
|
+
resume=True,
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
await conn.close()
|
|
235
|
+
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
The checkpoint file stores `bucket`, `key`, `upload_id`, and completed parts.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## SQL Server connector
|
|
243
|
+
|
|
244
|
+
`MSSQLConnector` provides an async SQL Server connector built on `aioodbc` (ODBC).
|
|
245
|
+
|
|
246
|
+
System requirements:
|
|
247
|
+
|
|
248
|
+
- A SQL Server ODBC driver installed on your host (for example, “ODBC Driver 18 for SQL Server”).
|
|
249
|
+
|
|
250
|
+
Install the extras:
|
|
251
|
+
|
|
252
|
+
```powershell
|
|
253
|
+
pip install 'multids[sqlserver]'
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Example:
|
|
257
|
+
|
|
258
|
+
```python
|
|
259
|
+
|
|
260
|
+
from multids.connectors.mssql import MSSQLConnector
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
async def example():
|
|
264
|
+
conn = MSSQLConnector()
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
# Configure connection string/DSN via env or arguments, then:
|
|
268
|
+
await conn.connect_pool()
|
|
269
|
+
rows = await conn.fetch_rows("SELECT id, name FROM users")
|
|
270
|
+
await conn.close()
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## OpenSearch connector
|
|
277
|
+
|
|
278
|
+
`OpenSearchConnector` is an async, `httpx`-based helper for indexing and querying OpenSearch/Elasticsearch.
|
|
279
|
+
|
|
280
|
+
Install:
|
|
281
|
+
|
|
282
|
+
```powershell
|
|
283
|
+
pip install 'multids[opensearch]'
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Example:
|
|
287
|
+
|
|
288
|
+
```python
|
|
289
|
+
|
|
290
|
+
from multids.connectors.opensearch import OpenSearchConnector
|
|
291
|
+
|
|
292
|
+
oc = OpenSearchConnector("http://localhost:9200")
|
|
293
|
+
|
|
294
|
+
# Index a document
|
|
295
|
+
|
|
296
|
+
await oc.index_doc("my-index", {"name": "alice"})
|
|
297
|
+
|
|
298
|
+
# Bulk index
|
|
299
|
+
|
|
300
|
+
docs = [{"id": 1, "name": "a"}, {"id": 2, "name": "b"}]
|
|
301
|
+
await oc.bulk_index("my-index", docs, chunk_size=100)
|
|
302
|
+
|
|
303
|
+
# Search
|
|
304
|
+
|
|
305
|
+
res = await oc.search("my-index", {"query": {"match_all": {}}}, size=10)
|
|
306
|
+
|
|
307
|
+
# Scroll over results
|
|
308
|
+
|
|
309
|
+
async for hit in oc.scroll("my-index", {"query": {"match_all": {}}}):
|
|
310
|
+
print(hit)
|
|
311
|
+
|
|
312
|
+
await oc.close()
|
|
313
|
+
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Authentication examples:
|
|
317
|
+
|
|
318
|
+
```python
|
|
319
|
+
|
|
320
|
+
# API key
|
|
321
|
+
|
|
322
|
+
oc = OpenSearchConnector("https://es.example.com", api_key="BASE64_API_KEY")
|
|
323
|
+
|
|
324
|
+
# Basic auth
|
|
325
|
+
|
|
326
|
+
oc = OpenSearchConnector("https://es.example.com", basic_auth=("user", "pass"))
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Development and contributing
|
|
333
|
+
|
|
334
|
+
Development setup, virtualenv/Poetry instructions, and contribution guidelines are documented in:
|
|
335
|
+
|
|
336
|
+
- `CONTRIBUTING.md`
|
|
337
|
+
- `docs/` (developer guide)
|
|
338
|
+
|
|
339
|
+
Contributions, bug reports, and feature requests are welcome via GitHub issues and pull requests.
|
|
340
|
+
|
|
341
|
+
```
|