flexorch-sdk 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.
Files changed (30) hide show
  1. flexorch_sdk-0.1.0/.github/workflows/ci.yml +28 -0
  2. flexorch_sdk-0.1.0/.gitignore +46 -0
  3. flexorch_sdk-0.1.0/CHANGELOG.md +50 -0
  4. flexorch_sdk-0.1.0/CONTRIBUTING.md +43 -0
  5. flexorch_sdk-0.1.0/LICENSE +21 -0
  6. flexorch_sdk-0.1.0/PKG-INFO +344 -0
  7. flexorch_sdk-0.1.0/README.md +316 -0
  8. flexorch_sdk-0.1.0/examples/basic_process.py +15 -0
  9. flexorch_sdk-0.1.0/examples/batch_process.py +21 -0
  10. flexorch_sdk-0.1.0/examples/s3_import.py +39 -0
  11. flexorch_sdk-0.1.0/pyproject.toml +43 -0
  12. flexorch_sdk-0.1.0/src/flexorch_sdk/__init__.py +63 -0
  13. flexorch_sdk-0.1.0/src/flexorch_sdk/_transport.py +123 -0
  14. flexorch_sdk-0.1.0/src/flexorch_sdk/client.py +184 -0
  15. flexorch_sdk-0.1.0/src/flexorch_sdk/errors.py +75 -0
  16. flexorch_sdk-0.1.0/src/flexorch_sdk/models/__init__.py +6 -0
  17. flexorch_sdk-0.1.0/src/flexorch_sdk/models/connector.py +45 -0
  18. flexorch_sdk-0.1.0/src/flexorch_sdk/models/dataset.py +106 -0
  19. flexorch_sdk-0.1.0/src/flexorch_sdk/models/job.py +85 -0
  20. flexorch_sdk-0.1.0/src/flexorch_sdk/models/search.py +29 -0
  21. flexorch_sdk-0.1.0/src/flexorch_sdk/resources/__init__.py +13 -0
  22. flexorch_sdk-0.1.0/src/flexorch_sdk/resources/connectors.py +54 -0
  23. flexorch_sdk-0.1.0/src/flexorch_sdk/resources/datasets.py +24 -0
  24. flexorch_sdk-0.1.0/src/flexorch_sdk/resources/jobs.py +24 -0
  25. flexorch_sdk-0.1.0/src/flexorch_sdk/resources/usage.py +47 -0
  26. flexorch_sdk-0.1.0/src/flexorch_sdk/resources/webhooks.py +59 -0
  27. flexorch_sdk-0.1.0/tests/test_client.py +99 -0
  28. flexorch_sdk-0.1.0/tests/test_jobs.py +95 -0
  29. flexorch_sdk-0.1.0/tests/test_resources.py +134 -0
  30. flexorch_sdk-0.1.0/tests/test_s3_and_search.py +187 -0
@@ -0,0 +1,28 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main, develop]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - uses: actions/setup-python@v5
20
+ with:
21
+ python-version: ${{ matrix.python-version }}
22
+ cache: pip
23
+
24
+ - name: Install
25
+ run: pip install -e ".[dev]"
26
+
27
+ - name: Test
28
+ run: python -m pytest tests/ -q --tb=short
@@ -0,0 +1,46 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.pyo
5
+ *.pyd
6
+ .Python
7
+
8
+ # Distribution / packaging
9
+ dist/
10
+ build/
11
+ *.egg-info/
12
+ *.egg
13
+ MANIFEST
14
+
15
+ # Virtual environments
16
+ .venv/
17
+ venv/
18
+ env/
19
+ ENV/
20
+
21
+ # Testing
22
+ .pytest_cache/
23
+ .coverage
24
+ htmlcov/
25
+ .tox/
26
+
27
+ # Type checkers
28
+ .mypy_cache/
29
+ .pyright/
30
+ .ruff_cache/
31
+
32
+ # IDE
33
+ .vscode/
34
+ .idea/
35
+ *.swp
36
+ *.swo
37
+
38
+ # OS
39
+ .DS_Store
40
+ Thumbs.db
41
+
42
+ # Secrets
43
+ .env
44
+ .env.*
45
+ !.env.example
46
+ .pypirc
@@ -0,0 +1,50 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
+ Versioning follows [Semantic Versioning](https://semver.org/).
7
+
8
+ ---
9
+
10
+ ## [0.1.0] — 2026-05-24
11
+
12
+ Initial release.
13
+
14
+ ### Added
15
+
16
+ **Core**
17
+ - `FlexOrchClient` — main entry point; reads `FLEXORCH_API_KEY` env var automatically
18
+ - `Transport` — httpx-based HTTP layer with automatic retry (3×, exponential backoff) on `429` and `5xx`
19
+ - Context manager support (`with FlexOrchClient() as client: ...`)
20
+
21
+ **Processing**
22
+ - `client.process(file_path, locale, pipeline_config)` — upload a document and start the pipeline
23
+ - `client.process_many(file_paths, locale)` — sequential batch processing
24
+ - `client.process_from_s3(connector_id, keys, locale)` — import directly from an S3 connector
25
+
26
+ **Jobs**
27
+ - `Job.wait(timeout, poll_interval)` — blocking poll until `completed` or `failed`
28
+ - `Job.dataset()` — fetch the linked dataset once the job is done
29
+ - `client.jobs.get(job_id)` / `client.jobs.list(page, page_size)`
30
+
31
+ **Datasets**
32
+ - `Dataset.export(format, path)` — download in `json`, `jsonl`, `csv`, `parquet`, `md`, `xml`, `xlsx`, or `rag`
33
+ - `Dataset.export_to_s3(connector_id, format, prefix)` — push directly to S3
34
+ - `Dataset.index()` / `Dataset.index_status()` — semantic indexing (Pro+)
35
+ - `client.datasets.get(dataset_id)` / `client.datasets.list()`
36
+
37
+ **Semantic search**
38
+ - `client.search(query, top_k, filters)` — cosine similarity search across indexed datasets (Pro+)
39
+
40
+ **Connectors**
41
+ - `client.connectors.create(name, type, config)` — register an S3 connector
42
+ - `client.connectors.list()` / `get(id)` / `delete(id)` / `test(id)`
43
+
44
+ **Usage & Webhooks**
45
+ - `client.usage.current()` — credits used/remaining, plan, reset date
46
+ - `client.webhooks.register(url, events)` / `list()` / `delete(id)`
47
+
48
+ **Errors**
49
+ - `FlexOrchError`, `AuthError`, `QuotaError`, `RateLimitError`, `NotFoundError`,
50
+ `ValidationError`, `ServerError`, `JobFailedError`, `TimeoutError`
@@ -0,0 +1,43 @@
1
+ # Contributing
2
+
3
+ Thank you for your interest in contributing to flexorch-sdk.
4
+
5
+ ## Setup
6
+
7
+ ```bash
8
+ git clone https://github.com/flexorch/flexorch-sdk
9
+ cd flexorch-sdk
10
+ pip install -e ".[dev]"
11
+ ```
12
+
13
+ ## Running tests
14
+
15
+ ```bash
16
+ pytest
17
+ ```
18
+
19
+ Tests use [respx](https://lundberg.github.io/respx/) to mock httpx — no network calls or API key required.
20
+
21
+ ## Code style
22
+
23
+ - Line length: 100 characters (`ruff` configured in `pyproject.toml`)
24
+ - Type hints required on all public functions
25
+ - No `any` in public interfaces — use explicit types
26
+
27
+ ```bash
28
+ pip install ruff
29
+ ruff check src/ tests/
30
+ ```
31
+
32
+ ## Submitting changes
33
+
34
+ 1. Fork the repository
35
+ 2. Create a feature branch: `git checkout -b feat/your-feature`
36
+ 3. Add tests for new behaviour
37
+ 4. Open a pull request against `main`
38
+
39
+ ## Reporting issues
40
+
41
+ Open an issue at [github.com/flexorch/flexorch-sdk/issues](https://github.com/flexorch/flexorch-sdk/issues).
42
+
43
+ For security issues, email [privacy@flexorch.com](mailto:privacy@flexorch.com) instead of opening a public issue.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Flexorch Technology
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,344 @@
1
+ Metadata-Version: 2.4
2
+ Name: flexorch-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for the FlexOrch API — process documents, build LLM-ready datasets
5
+ Project-URL: Homepage, https://flexorch.com
6
+ Project-URL: Repository, https://github.com/flexorch/flexorch-sdk
7
+ Project-URL: Issues, https://github.com/flexorch/flexorch-sdk/issues
8
+ Project-URL: Changelog, https://github.com/flexorch/flexorch-sdk/blob/main/CHANGELOG.md
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: dataset,document,flexorch,llm,pipeline
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: httpx>=0.27
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
25
+ Requires-Dist: pytest>=7; extra == 'dev'
26
+ Requires-Dist: respx>=0.21; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # flexorch-sdk
30
+
31
+ [![PyPI](https://img.shields.io/pypi/v/flexorch-sdk)](https://pypi.org/project/flexorch-sdk/)
32
+ [![Python](https://img.shields.io/pypi/pyversions/flexorch-sdk)](https://pypi.org/project/flexorch-sdk/)
33
+ [![CI](https://github.com/flexorch/flexorch-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/flexorch/flexorch-sdk/actions)
34
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
35
+
36
+ Python SDK for the [FlexOrch](https://flexorch.com) API.
37
+
38
+ FlexOrch turns unstructured documents (PDF, DOCX, invoices, emails…) into clean, structured, LLM-ready datasets — with automatic PII detection and masking, quality scoring, and multiple export formats.
39
+
40
+ ---
41
+
42
+ ## Install
43
+
44
+ ```bash
45
+ pip install flexorch-sdk
46
+ ```
47
+
48
+ Requires Python 3.10+. The only dependency is [`httpx`](https://www.python-httpx.org/).
49
+
50
+ ---
51
+
52
+ ## Quick start
53
+
54
+ ```python
55
+ from flexorch_sdk import FlexOrchClient
56
+
57
+ client = FlexOrchClient("fx_your_key_here")
58
+
59
+ # Upload a document and wait for the pipeline to finish
60
+ job = client.process("contract.pdf", locale="tr").wait()
61
+
62
+ print(job.quality_grade) # "A"
63
+ print(job.quality_score) # 0.91
64
+
65
+ # Download the resulting dataset
66
+ dataset = job.dataset()
67
+ dataset.export("jsonl", path="output.jsonl")
68
+ ```
69
+
70
+ ---
71
+
72
+ ## Auth
73
+
74
+ Pass your API key directly or set the `FLEXORCH_API_KEY` environment variable:
75
+
76
+ ```bash
77
+ export FLEXORCH_API_KEY=fx_...
78
+ ```
79
+
80
+ ```python
81
+ from flexorch_sdk import FlexOrchClient
82
+
83
+ client = FlexOrchClient() # reads FLEXORCH_API_KEY automatically
84
+ ```
85
+
86
+ Get your API key from [app.flexorch.com](https://app.flexorch.com) → Settings.
87
+
88
+ ---
89
+
90
+ ## Supported input formats
91
+
92
+ | Category | Formats |
93
+ |---|---|
94
+ | Documents | PDF (text + scanned), DOCX, TXT |
95
+ | Spreadsheets | XLSX |
96
+ | Email | EML, MSG |
97
+ | E-invoices | XML/UBL (Peppol, GİB TR), FatturaPA (IT), XRechnung (DE), ZUGFeRD/Factur-X |
98
+ | Images | JPG, PNG, TIFF (OCR) |
99
+ | Web | HTML, HTM |
100
+
101
+ ---
102
+
103
+ ## Export formats
104
+
105
+ `json` · `jsonl` · `csv` · `parquet` · `md` · `xml` · `xlsx` · `rag`
106
+
107
+ ```python
108
+ dataset.export("jsonl", path="output.jsonl") # write to file
109
+ raw = dataset.export("parquet") # return bytes
110
+ ```
111
+
112
+ The `rag` format produces LlamaIndex/LangChain-compatible chunks with metadata.
113
+
114
+ ---
115
+
116
+ ## Processing
117
+
118
+ ### Single file
119
+
120
+ ```python
121
+ job = client.process("invoice.pdf", locale="de").wait()
122
+ ```
123
+
124
+ `locale` is an [IETF language tag](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry)
125
+ used to activate the right PII detectors (`tr`, `de`, `en`, `fr`, `it`, `nl`, `es`, `pl`, `und` = all).
126
+
127
+ ### Batch
128
+
129
+ ```python
130
+ jobs = client.process_many(["a.pdf", "b.pdf", "c.pdf"], locale="und")
131
+ for job in jobs:
132
+ job.wait()
133
+ print(job.quality_grade, job.quality_score)
134
+ ```
135
+
136
+ ### From S3
137
+
138
+ ```python
139
+ # Register a connector once; store conn.id for reuse
140
+ conn = client.connectors.create(
141
+ "Production S3", "s3",
142
+ {
143
+ "bucket": "my-bucket",
144
+ "region": "eu-central-1",
145
+ "access_key_id": "AKIA...",
146
+ "secret_access_key": "...",
147
+ },
148
+ )
149
+
150
+ # Verify connectivity
151
+ result = client.connectors.test(conn.id)
152
+ print(result.success, result.latency_ms) # True, 38
153
+
154
+ # Process files from S3
155
+ jobs = client.process_from_s3(conn.id, ["invoices/inv-001.pdf", "invoices/inv-002.pdf"])
156
+ for job in jobs:
157
+ job.wait()
158
+ ```
159
+
160
+ ---
161
+
162
+ ## Job polling
163
+
164
+ `Job.wait()` blocks until the pipeline completes or times out.
165
+
166
+ ```python
167
+ job = client.process("large-report.pdf").wait(
168
+ timeout=600, # seconds before TimeoutError (default: 300)
169
+ poll_interval=5, # polling interval in seconds (default: 2)
170
+ )
171
+
172
+ print(job.status) # "completed"
173
+ print(job.quality_grade) # "A" | "B" | "C" | "D"
174
+ print(job.quality_score) # 0.0 – 1.0
175
+ print(job.has_dataset) # True
176
+ ```
177
+
178
+ ---
179
+
180
+ ## Dataset operations
181
+
182
+ ```python
183
+ ds = job.dataset() # fetch dataset linked to this job
184
+ ds = client.datasets.get("dataset-id")
185
+
186
+ print(ds.name) # "contract-2024-q1"
187
+ print(ds.row_count) # 142
188
+ print(ds.available_formats) # ["json", "jsonl", "csv", "parquet"]
189
+
190
+ # Download locally
191
+ ds.export("jsonl", path="output.jsonl")
192
+
193
+ # Push directly to S3
194
+ push = ds.export_to_s3(conn.id, "jsonl", prefix="processed/datasets/")
195
+ print(push["s3_key"]) # "processed/datasets/contract-2024-q1.jsonl"
196
+ print(push["size_bytes"]) # 84320
197
+
198
+ # Semantic indexing (Pro+)
199
+ ds.index()
200
+ status = ds.index_status() # {"status": "ready", "chunks_indexed": 48}
201
+ ```
202
+
203
+ ---
204
+
205
+ ## Semantic search (Pro+)
206
+
207
+ ```python
208
+ results = client.search(
209
+ "payment terms net 30",
210
+ top_k=10,
211
+ filters={
212
+ "document_type": "invoice",
213
+ "language": "de",
214
+ "quality_grade": "A",
215
+ "pii_masked": True,
216
+ },
217
+ )
218
+
219
+ for r in results:
220
+ print(f"{r.score:.3f} [{r.dataset_id}] {r.text[:120]}")
221
+ ```
222
+
223
+ ---
224
+
225
+ ## Resources
226
+
227
+ ```python
228
+ # Jobs
229
+ jobs = client.jobs.list(page=1, page_size=20)
230
+ job = client.jobs.get("job-id")
231
+
232
+ # Datasets
233
+ datasets = client.datasets.list()
234
+ ds = client.datasets.get("dataset-id")
235
+
236
+ # Usage
237
+ usage = client.usage.current()
238
+ print(f"{usage.credits_used} / {usage.credits_limit} credits used")
239
+ print(f"Plan: {usage.plan} — resets {usage.reset_at}")
240
+
241
+ # Webhooks
242
+ client.webhooks.register("https://your-server.com/hook", events=["dataset.ready"])
243
+ client.webhooks.list()
244
+ client.webhooks.delete("webhook-id")
245
+
246
+ # Connectors
247
+ client.connectors.create("name", "s3", {...})
248
+ client.connectors.list()
249
+ client.connectors.get("connector-id")
250
+ client.connectors.test("connector-id")
251
+ client.connectors.delete("connector-id")
252
+ ```
253
+
254
+ ---
255
+
256
+ ## Error handling
257
+
258
+ ```python
259
+ from flexorch_sdk import (
260
+ FlexOrchClient,
261
+ AuthError, # 401 — invalid or missing API key
262
+ QuotaError, # 402 — credit limit reached or trial expired
263
+ RateLimitError, # 429 — too many requests; has .retry_after (seconds)
264
+ NotFoundError, # 404
265
+ ValidationError, # 422 — bad request parameters
266
+ ServerError, # 5xx
267
+ JobFailedError, # pipeline failed; has .job_id and .failure_reason
268
+ TimeoutError, # Job.wait() exceeded timeout; has .job_id
269
+ )
270
+
271
+ try:
272
+ job = client.process("doc.pdf").wait(timeout=120)
273
+ except AuthError:
274
+ print("Invalid API key — check FLEXORCH_API_KEY")
275
+ except QuotaError as e:
276
+ print(f"Out of credits — reset at {e.reset_at}")
277
+ except JobFailedError as e:
278
+ print(f"Pipeline failed for job {e.job_id}: {e.failure_reason}")
279
+ except TimeoutError as e:
280
+ print(f"Job {e.job_id} still running after timeout — poll manually")
281
+ ```
282
+
283
+ The SDK automatically retries `429` and `5xx` responses with exponential backoff (up to 3 attempts by default).
284
+
285
+ ---
286
+
287
+ ## Configuration
288
+
289
+ ```python
290
+ client = FlexOrchClient(
291
+ api_key="fx_...",
292
+ base_url="https://api.flexorch.com/v1", # override for self-hosted
293
+ timeout=60.0, # HTTP timeout per request in seconds
294
+ max_retries=5, # retry attempts for transient errors
295
+ )
296
+ ```
297
+
298
+ ### Context manager
299
+
300
+ ```python
301
+ with FlexOrchClient() as client:
302
+ job = client.process("report.pdf").wait()
303
+ job.dataset().export("jsonl", path="report.jsonl")
304
+ # HTTP connection pool released automatically
305
+ ```
306
+
307
+ ---
308
+
309
+ ## Examples
310
+
311
+ See [`examples/`](examples/) for runnable scripts:
312
+
313
+ | File | Description |
314
+ |---|---|
315
+ | [`basic_process.py`](examples/basic_process.py) | Process a single document and export as JSONL |
316
+ | [`batch_process.py`](examples/batch_process.py) | Process multiple files with error handling |
317
+ | [`s3_import.py`](examples/s3_import.py) | Import from S3, process, export results back to S3 |
318
+
319
+ ---
320
+
321
+ ## Development
322
+
323
+ ```bash
324
+ git clone https://github.com/flexorch/flexorch-sdk
325
+ cd flexorch-sdk
326
+ pip install -e ".[dev]"
327
+ pytest
328
+ ```
329
+
330
+ Tests use [respx](https://lundberg.github.io/respx/) to mock httpx — no network calls, no API key needed.
331
+
332
+ ---
333
+
334
+ ## Links
335
+
336
+ - [Platform](https://app.flexorch.com)
337
+ - [API reference](https://flexorch.com/developers)
338
+ - [flexorch-audit](https://github.com/flexorch/flexorch-audit) — open-source PII detection library
339
+
340
+ ---
341
+
342
+ ## License
343
+
344
+ [MIT](LICENSE)