doctopus-ai 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 (44) hide show
  1. doctopus_ai-0.1.0/.gitignore +6 -0
  2. doctopus_ai-0.1.0/CONTRIBUTING.md +126 -0
  3. doctopus_ai-0.1.0/LICENSE +21 -0
  4. doctopus_ai-0.1.0/PKG-INFO +471 -0
  5. doctopus_ai-0.1.0/README.md +420 -0
  6. doctopus_ai-0.1.0/pyproject.toml +64 -0
  7. doctopus_ai-0.1.0/src/doctopus/__init__.py +35 -0
  8. doctopus_ai-0.1.0/src/doctopus/backends/__init__.py +0 -0
  9. doctopus_ai-0.1.0/src/doctopus/backends/base.py +50 -0
  10. doctopus_ai-0.1.0/src/doctopus/backends/docling.py +104 -0
  11. doctopus_ai-0.1.0/src/doctopus/backends/markdown.py +135 -0
  12. doctopus_ai-0.1.0/src/doctopus/backends/markitdown.py +50 -0
  13. doctopus_ai-0.1.0/src/doctopus/backends/ollama.py +120 -0
  14. doctopus_ai-0.1.0/src/doctopus/backends/paddleocr.py +174 -0
  15. doctopus_ai-0.1.0/src/doctopus/backends/pymupdf4llm.py +87 -0
  16. doctopus_ai-0.1.0/src/doctopus/backends/registry.py +48 -0
  17. doctopus_ai-0.1.0/src/doctopus/backends/sidecar.py +156 -0
  18. doctopus_ai-0.1.0/src/doctopus/backends/xberg.py +103 -0
  19. doctopus_ai-0.1.0/src/doctopus/bench/__init__.py +0 -0
  20. doctopus_ai-0.1.0/src/doctopus/bench/run.py +97 -0
  21. doctopus_ai-0.1.0/src/doctopus/core/__init__.py +0 -0
  22. doctopus_ai-0.1.0/src/doctopus/core/chunk.py +129 -0
  23. doctopus_ai-0.1.0/src/doctopus/core/errors.py +19 -0
  24. doctopus_ai-0.1.0/src/doctopus/core/gateway.py +135 -0
  25. doctopus_ai-0.1.0/src/doctopus/core/models.py +97 -0
  26. doctopus_ai-0.1.0/src/doctopus/interfaces/__init__.py +0 -0
  27. doctopus_ai-0.1.0/src/doctopus/interfaces/api.py +108 -0
  28. doctopus_ai-0.1.0/src/doctopus/interfaces/cli.py +196 -0
  29. doctopus_ai-0.1.0/src/doctopus/interfaces/mcp_server.py +116 -0
  30. doctopus_ai-0.1.0/src/doctopus/interfaces/static/index.html +74 -0
  31. doctopus_ai-0.1.0/src/doctopus/interfaces/static/logo.png +0 -0
  32. doctopus_ai-0.1.0/src/doctopus/routing/__init__.py +0 -0
  33. doctopus_ai-0.1.0/src/doctopus/routing/inspect.py +31 -0
  34. doctopus_ai-0.1.0/src/doctopus/routing/router.py +89 -0
  35. doctopus_ai-0.1.0/tests/layout_quality.py +19 -0
  36. doctopus_ai-0.1.0/tests/make_fixtures.py +84 -0
  37. doctopus_ai-0.1.0/tests/mcp_smoke.py +25 -0
  38. doctopus_ai-0.1.0/tests/ocr_quality.py +27 -0
  39. doctopus_ai-0.1.0/tests/test_chunk.py +75 -0
  40. doctopus_ai-0.1.0/tests/test_core.py +200 -0
  41. doctopus_ai-0.1.0/tests/test_markdown_norm.py +56 -0
  42. doctopus_ai-0.1.0/tests/test_ollama.py +47 -0
  43. doctopus_ai-0.1.0/tests/test_paddleocr.py +328 -0
  44. doctopus_ai-0.1.0/tests/test_sidecar.py +35 -0
@@ -0,0 +1,6 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .cache/
5
+ bench_results/
6
+ site/
@@ -0,0 +1,126 @@
1
+ # Contributing to Doctopus
2
+
3
+ Thanks for your interest in contributing. Doctopus is a self-hosted document-processing gateway: one canonical document schema behind Python, CLI, REST, and MCP interfaces, with backend routing and at most one fallback.
4
+
5
+ ## Getting started
6
+
7
+ Prerequisites:
8
+
9
+ - **Python 3.12** (the project pins `>=3.12,<3.13`)
10
+ - [uv](https://docs.astral.sh/uv/)
11
+
12
+ ```bash
13
+ git clone https://github.com/adityasasidhar/doctopus.git
14
+ cd doctopus
15
+ uv sync --extra dev
16
+ uv run pytest
17
+ ```
18
+
19
+ Optional extras declared in `pyproject.toml` — install only what your change touches:
20
+
21
+ ```bash
22
+ uv sync --extra docling # optional Docling backend (large; ~4 GB RAM for auto-selection)
23
+ uv sync --extra paddleocr # optional CPU PaddleOCR PP-StructureV3 (explicit backend selection)
24
+ uv sync --extra ollama # Ollama-backed extraction
25
+ uv sync --extra markitdown # MarkItDown-backed extraction
26
+ ```
27
+
28
+ ## Project layout
29
+
30
+ ```text
31
+ src/doctopus/
32
+ core/ # Document schema (models), gateway, chunking, errors
33
+ routing/ # inspect_file and the routing decision (router)
34
+ backends/ # Backend protocol, registry, and adapters (xberg, docling, ...)
35
+ interfaces/ # CLI (typer), REST API (FastAPI), MCP server, demo UI
36
+ bench/ # benchmark runner
37
+ tests/ # pytest suite, smoke scripts, fixture generator
38
+ fixtures/ # sample documents and ground truth
39
+ docs/ # documentation site (MkDocs); design specs and plans under docs/superpowers/
40
+ ```
41
+
42
+ Design rules that keep the codebase coherent:
43
+
44
+ - **One output shape.** All backends return `RawResult` (`backends/base.py`); the gateway wraps it into the versioned `Document` (schema `1.0`). Do not add backend-specific fields to the public schema without a schema discussion first.
45
+ - **Never invent data.** Information an engine cannot provide stays `null`.
46
+ - **Keep Lite light.** Heavy optional imports stay lazy (see the `_docling()` factory in `backends/registry.py`) so `uv sync` without extras remains small.
47
+ - **Routing is inspect → route → extract**, with at most one alternative on failure or a suspicious result. Suspicion thresholds and fallback behavior live in `routing/router.py` and `core/gateway.py`; treat them as documented heuristics, and update the README table if you change them.
48
+
49
+ ## Development workflow
50
+
51
+ 1. Branch from `main` (`git checkout -b feat/your-change`).
52
+ 2. Make your change, keeping commits small and focused.
53
+ 3. Add or update tests for the behavior you changed.
54
+ 4. Run the checks below.
55
+ 5. Open a pull request describing the motivation, the approach, and how you tested it.
56
+
57
+ Commit messages follow [Conventional Commits](https://www.conventionalcommits.org/), e.g. `feat(backends): add markdown fallback backend` or `fix(gateway): keep original result when escalation yields less text`.
58
+
59
+ ## Running tests
60
+
61
+ ```bash
62
+ uv run pytest # full unit test suite
63
+ uv run python tests/mcp_smoke.py # MCP server smoke test
64
+ ```
65
+
66
+ The fast tests in `tests/test_core.py` use fake backends on purpose so routing, RAM gating, escalation, and safety logic can be tested without heavy imports. Follow that pattern when testing gateway or router behavior.
67
+
68
+ Quality and layout scripts (require fixtures):
69
+
70
+ ```bash
71
+ uv run python tests/make_fixtures.py # regenerate fixtures/ (needs the dev extra)
72
+ uv run python tests/ocr_quality.py # OCR scoring against ground truth
73
+ uv run python tests/layout_quality.py # reading-order / table scoring
74
+ ```
75
+
76
+ Fixture PDFs under `fixtures/` are generated or curated inputs; ground truth lives in the adjacent `.truth.json` files. If you add a fixture, include its ground truth and note how it was produced.
77
+
78
+ ## Benchmarks
79
+
80
+ If your change affects performance or extraction quality, reproduce the suite and record results:
81
+
82
+ ```bash
83
+ uv sync --extra dev --extra docling
84
+ uv run python tests/make_fixtures.py
85
+ uv run python -m doctopus.bench.run
86
+ ```
87
+
88
+ Paste the output into your PR (the reference table lives in `bench_results/results.md` and the README). Benchmarks run in fresh subprocesses; report the machine you ran them on, since numbers are hardware-dependent.
89
+
90
+ ## Adding or changing a backend
91
+
92
+ 1. Implement the `Backend` protocol from `backends/base.py`: `id`, `info()`, `supports(ext)`, and `async process(path, *, ocr=None) -> RawResult`.
93
+ 2. Return honest values: set `quality` only if the engine reports it, leave the rest `None`.
94
+ 3. Register it in `backends/registry.py` with a lazy factory if the import is heavy.
95
+ 4. Make sure `uv run doctopus backends list` shows it and `uv run doctopus plan <file>` can select or escalate to it.
96
+ 5. Add unit tests with a fake or minimal backend; add an end-to-end check only if the backend is installable in CI-sized environments.
97
+
98
+ The `paddleocr` adapter wraps PP-StructureV3 for PDFs and images. Keep pipeline initialization and prediction iteration in its locked worker thread; backend discovery must not import Paddle or load models. It is excluded from automatic selection and fallback until benchmarked. Canonical table blocks retain provenance, while the chunker emits their corresponding `Table` entries only once. Run `uv run pytest tests/test_paddleocr.py` for adapter and interface contract tests without model downloads.
99
+
100
+ ## Documentation
101
+
102
+ - User-facing behavior changes (new flags, endpoints, routing rules, schema fields) must be reflected in `README.md` and the documentation site under `docs/`.
103
+ - Preview the site with `uv sync --group docs` then `uv run mkdocs serve`. CI builds it with `mkdocs build --strict`, so broken links fail the build.
104
+ - The Python API reference is generated from docstrings with mkdocstrings; keep public docstrings accurate.
105
+ - Design proposals and implementation plans go in `docs/superpowers/specs/` and `docs/superpowers/plans/`, dated `YYYY-MM-DD-<slug>.md`.
106
+ - Keep the routing diagram and selection table in the README accurate.
107
+
108
+ ## Style
109
+
110
+ - Python 3.12 syntax; type annotations on public functions.
111
+ - Follow the surrounding style in each module (the codebase favors compact, direct code over deep class hierarchies).
112
+ - Prefer `pathlib.Path` over string paths.
113
+ - Errors surface through `doctopus.core.errors` (`DoctopusError` hierarchy); use them rather than bare `ValueError` for user-facing failures.
114
+
115
+ ## Pull request checklist
116
+
117
+ - [ ] `uv run pytest` passes
118
+ - [ ] New behavior has tests; bug fixes have a regression test
119
+ - [ ] README / docs updated where user-visible
120
+ - [ ] Benchmarks re-run if performance or quality is affected
121
+ - [ ] Heavy imports stay lazy; Lite install stays light
122
+ - [ ] No invented data — unknowns remain `null`
123
+
124
+ ## License
125
+
126
+ By contributing, you agree that your contributions are licensed under the Apache License 2.0, the same license as the project.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aditya Sasidhar
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.