datasheet-lens 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 (53) hide show
  1. datasheet_lens-0.1.0/.gitignore +15 -0
  2. datasheet_lens-0.1.0/LICENSE +21 -0
  3. datasheet_lens-0.1.0/PKG-INFO +182 -0
  4. datasheet_lens-0.1.0/README.md +148 -0
  5. datasheet_lens-0.1.0/doc/agent-workflow.md +256 -0
  6. datasheet_lens-0.1.0/doc/architecture.md +220 -0
  7. datasheet_lens-0.1.0/doc/cli.md +465 -0
  8. datasheet_lens-0.1.0/doc/development.md +146 -0
  9. datasheet_lens-0.1.0/doc/distributors.md +185 -0
  10. datasheet_lens-0.1.0/doc/installation.md +228 -0
  11. datasheet_lens-0.1.0/doc/mcp-server.md +170 -0
  12. datasheet_lens-0.1.0/doc/projects.md +461 -0
  13. datasheet_lens-0.1.0/doc/use-cases.md +287 -0
  14. datasheet_lens-0.1.0/pyproject.toml +63 -0
  15. datasheet_lens-0.1.0/src/datasheet_lens/__init__.py +9 -0
  16. datasheet_lens-0.1.0/src/datasheet_lens/agents.py +129 -0
  17. datasheet_lens-0.1.0/src/datasheet_lens/cli.py +914 -0
  18. datasheet_lens-0.1.0/src/datasheet_lens/config.py +14 -0
  19. datasheet_lens-0.1.0/src/datasheet_lens/distributors.py +316 -0
  20. datasheet_lens-0.1.0/src/datasheet_lens/elements.py +330 -0
  21. datasheet_lens-0.1.0/src/datasheet_lens/errors.py +6 -0
  22. datasheet_lens-0.1.0/src/datasheet_lens/fetch.py +136 -0
  23. datasheet_lens-0.1.0/src/datasheet_lens/fileutil.py +38 -0
  24. datasheet_lens-0.1.0/src/datasheet_lens/identify.py +435 -0
  25. datasheet_lens-0.1.0/src/datasheet_lens/indexer.py +407 -0
  26. datasheet_lens-0.1.0/src/datasheet_lens/keys.py +188 -0
  27. datasheet_lens-0.1.0/src/datasheet_lens/knowledge.py +125 -0
  28. datasheet_lens-0.1.0/src/datasheet_lens/links.py +50 -0
  29. datasheet_lens-0.1.0/src/datasheet_lens/pages.py +173 -0
  30. datasheet_lens-0.1.0/src/datasheet_lens/pdflock.py +26 -0
  31. datasheet_lens-0.1.0/src/datasheet_lens/pdftext.py +198 -0
  32. datasheet_lens-0.1.0/src/datasheet_lens/project.py +1401 -0
  33. datasheet_lens-0.1.0/src/datasheet_lens/server.py +1005 -0
  34. datasheet_lens-0.1.0/src/datasheet_lens/setup.py +125 -0
  35. datasheet_lens-0.1.0/src/datasheet_lens/store.py +537 -0
  36. datasheet_lens-0.1.0/src/datasheet_lens/version_check.py +218 -0
  37. datasheet_lens-0.1.0/tests/conftest.py +100 -0
  38. datasheet_lens-0.1.0/tests/test_agents.py +109 -0
  39. datasheet_lens-0.1.0/tests/test_cli.py +20 -0
  40. datasheet_lens-0.1.0/tests/test_concrete.py +281 -0
  41. datasheet_lens-0.1.0/tests/test_distributors.py +186 -0
  42. datasheet_lens-0.1.0/tests/test_elements.py +166 -0
  43. datasheet_lens-0.1.0/tests/test_fetch.py +152 -0
  44. datasheet_lens-0.1.0/tests/test_identify.py +225 -0
  45. datasheet_lens-0.1.0/tests/test_indexer.py +180 -0
  46. datasheet_lens-0.1.0/tests/test_keys.py +83 -0
  47. datasheet_lens-0.1.0/tests/test_pages.py +143 -0
  48. datasheet_lens-0.1.0/tests/test_project.py +614 -0
  49. datasheet_lens-0.1.0/tests/test_regression.py +136 -0
  50. datasheet_lens-0.1.0/tests/test_remove.py +159 -0
  51. datasheet_lens-0.1.0/tests/test_server.py +228 -0
  52. datasheet_lens-0.1.0/tests/test_store.py +84 -0
  53. datasheet_lens-0.1.0/tests/test_version_check.py +112 -0
@@ -0,0 +1,15 @@
1
+ .venv/
2
+ .venvs/
3
+ __pycache__/
4
+ .pytest_cache/
5
+ dist/
6
+ *.egg-info/
7
+ # Raw output of the converters in spike 2. convert.py makes it again.
8
+ spike/*/verify/convert/*/raw/
9
+ *.py[cod]
10
+ # A project of datasheet-lens in the root of this repository, for development
11
+ # tests. The datasheets are third-party documents.
12
+ /datasheet-lens.toml
13
+ /datasheets/
14
+ # Files that the user gives for a task (for example datasheets to add).
15
+ /tmp/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Turbyho
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,182 @@
1
+ Metadata-Version: 2.5
2
+ Name: datasheet-lens
3
+ Version: 0.1.0
4
+ Summary: Index of component datasheets, and pages of the original on demand, for LLM agents
5
+ Project-URL: Homepage, https://github.com/turbyho/datasheet-lens
6
+ Project-URL: Source, https://github.com/turbyho/datasheet-lens
7
+ Project-URL: Documentation, https://github.com/turbyho/datasheet-lens/tree/main/doc
8
+ Project-URL: Issues, https://github.com/turbyho/datasheet-lens/issues
9
+ Author: Turbyho
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: datasheet,electronics,kicad,llm,mcp,pdf
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
23
+ Requires-Python: >=3.11
24
+ Requires-Dist: keyring>=25.6
25
+ Requires-Dist: mcp>=2.3
26
+ Requires-Dist: packaging>=24
27
+ Requires-Dist: pypdfium2>=5.14
28
+ Requires-Dist: tomlkit>=0.15
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=8; extra == 'dev'
31
+ Provides-Extra: layout
32
+ Requires-Dist: docling>=2.144; extra == 'layout'
33
+ Description-Content-Type: text/markdown
34
+
35
+ <!-- mcp-name: io.github.turbyho/datasheet-lens -->
36
+
37
+ # datasheet-lens
38
+
39
+ datasheet-lens gives the content of component datasheets (PDF) to an LLM agent,
40
+ for electronics design (KiCad and other CAD tools) and firmware work.
41
+
42
+ The tool does not convert a datasheet to text. A conversion makes errors that look
43
+ correct: lost superscripts, merged table rows, shifted columns, wrong values from
44
+ graphs. datasheet-lens builds an index to find the content, and gives the original
45
+ pages and regions to the model on demand. The model reads only the parts that the
46
+ work needs, and reads each value from the original.
47
+
48
+ Status: in development (version 0.1). The tools work and have tests. The
49
+ interfaces can change.
50
+
51
+ ## Features
52
+
53
+ - **Drill-down into a document.** An index (outline, table and figure captions,
54
+ page quality), a text search, a page map with element IDs, and images of an
55
+ element, a region, a caption ("Table 57", with docling also when the table
56
+ continues on more pages) or a full page at 300 to 600 dpi.
57
+ - **Central store, shared by all projects.** Each user has one store (default
58
+ `~/.datasheet-lens`) for all design projects. Each PDF is stored one time
59
+ (SHA-256), with its index, its element map, its parts and the facts that sessions
60
+ read from it. A datasheet that one project added is at once available to each
61
+ other project: it is not downloaded, indexed or read again. A part can have a
62
+ datasheet, a manual and errata.
63
+ - **Facts.** A value that a session read is saved with its source (document, page,
64
+ element), so that a later session finds it.
65
+ - **Project file.** `datasheet-lens.toml` in the repository of a design holds the
66
+ parts of the design and their documents. The team gets it with the repository.
67
+ `project_check` compares it with the parts of the CAD project.
68
+ - **Orderable parts.** The ordering codes of a datasheet, and the lifecycle state,
69
+ stock and prices from the official API of a distributor (Mouser now). No
70
+ scraping.
71
+
72
+ ## Typical uses
73
+
74
+ datasheet-lens helps to manage the input documents of a design project, and to keep
75
+ them in the repository. It keeps the BOM equal to the CAD project. It lets the agent
76
+ check the BOM, and check the design against the original datasheets.
77
+
78
+ - Keep the datasheets of a design complete and in git, the same for each person of
79
+ the team.
80
+ - Compare the project with the parts of the CAD project: missing, extra and
81
+ different parts.
82
+ - Select the concrete orderable MPN of a base part, and make sure that it can be
83
+ ordered.
84
+ - Review a schematic against the datasheets: pins, absolute maximum ratings, logic
85
+ levels, application circuits.
86
+ - Compare a footprint with the package drawing of the datasheet.
87
+ - Read register maps, bit fields and timing values for firmware, and keep them as
88
+ facts with their source.
89
+ - Use the same parts in more projects: the datasheets and the facts of one project
90
+ are at once available in each other project of the same user.
91
+
92
+ datasheet-lens does not read the schematic itself. The parts come from the CAD tool,
93
+ its MCP server or a BOM file. See [doc/use-cases.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/use-cases.md) for the steps
94
+ of each use.
95
+
96
+ ## Installation
97
+
98
+ datasheet-lens needs Python 3.11 or newer. It works on Linux, macOS and Windows.
99
+
100
+ ```sh
101
+ pipx install git+https://github.com/turbyho/datasheet-lens.git
102
+ datasheet-lens init
103
+ ```
104
+
105
+ `datasheet-lens init` makes the central store (default `~/.datasheet-lens`, or the
106
+ folder in the environment variable `DATASHEET_LENS_HOME`). It can also install
107
+ docling, which gives a better element map (tables and figures). docling is
108
+ optional: it needs some GB of disk. Without it, the tool uses the text layer.
109
+
110
+ Register the MCP server (stdio) in Claude Code:
111
+
112
+ ```sh
113
+ claude mcp add --scope user datasheet-lens -- datasheet-lens-mcp
114
+ ```
115
+
116
+ For a different MCP client, set the command `datasheet-lens-mcp` with no
117
+ arguments. The server gives its instructions to the agent. See
118
+ [doc/installation.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/installation.md) and [doc/mcp-server.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/mcp-server.md).
119
+
120
+ ## Quick start
121
+
122
+ In the root folder of the repository of the design:
123
+
124
+ ```sh
125
+ datasheet-lens project init # the project file, and a block in AGENTS.md, CLAUDE.md
126
+ datasheet-lens add PATH|URL # add a datasheet; it proposes the MPN of the part
127
+ datasheet-lens sync # copy the documents into the project folder
128
+ datasheet-lens check BOM.csv # compare the project with a BOM of the CAD project
129
+ ```
130
+
131
+ The agent uses the same functions through the MCP server. The block in
132
+ `AGENTS.md` or `CLAUDE.md` tells the agent the procedure. `project init` changes
133
+ only the files that exist: make one of them first if you want the block.
134
+
135
+ | Command | What it does |
136
+ |---|---|
137
+ | `add PATH\|URL` | Add a document to the store and to the project |
138
+ | `ls`, `sync` | Show the project, or synchronize its copies |
139
+ | `check BOM.csv` | Compare the project with a BOM (CSV) of the CAD project, and find conflicts between the MPN and Value fields (tested only with BOM exports of KiCad and Eagle) |
140
+ | `set MPN -m NEW` | Change the MPN, base part, category or manufacturer of a project part |
141
+ | `rm MPN` | Remove a part (or `-d DOC`, a document) from the project |
142
+ | `search TEXT --part MPN` | Find a text in the documents of a part |
143
+ | `codes DOC` | Show the orderable codes of a datasheet |
144
+ | `links MPN` | Show search links for a datasheet, stock, a symbol, a footprint, a 3D model |
145
+ | `find MPN` | Find a part at the distributors (lifecycle, stock, prices) |
146
+ | `stock` | Show the lifecycle state and the stock of each project part |
147
+ | `key NAME` | Save the API key of a distributor |
148
+ | `dist NAME ...` | Select the distributors (globally, or `--local` for the project) |
149
+
150
+ All commands and options are in [doc/cli.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/cli.md).
151
+
152
+ Each user has a personal API key for each distributor. Get a free Mouser key at
153
+ the [Mouser API Hub](https://www.mouser.com/api-hub/) (Search API), then run
154
+ `datasheet-lens key mouser`. See [doc/distributors.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/distributors.md).
155
+
156
+ ## Documentation
157
+
158
+ | Document | Content |
159
+ |---|---|
160
+ | [doc/installation.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/installation.md) | Requirements, installation, `init`, docling, store location, upgrade, uninstall |
161
+ | [doc/use-cases.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/use-cases.md) | Typical uses, step by step |
162
+ | [doc/mcp-server.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/mcp-server.md) | MCP server: registration, instructions, all tools |
163
+ | [doc/agent-workflow.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/agent-workflow.md) | How an agent reads a datasheet, with an example |
164
+ | [doc/projects.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/projects.md) | Project file, layout, sync, team workflow, consistency with the CAD project |
165
+ | [doc/cli.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/cli.md) | Reference of all CLI commands and options |
166
+ | [doc/distributors.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/distributors.md) | Distributor data, API keys, distributor selection, search links |
167
+ | [doc/architecture.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/architecture.md) | For developers: design decisions and module map |
168
+ | [doc/development.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/development.md) | Development setup, tests, code and text style |
169
+
170
+ ## Development
171
+
172
+ ```sh
173
+ python3 -m venv .venv
174
+ .venv/bin/pip install -e ".[dev]"
175
+ .venv/bin/python -m pytest
176
+ ```
177
+
178
+ See [doc/development.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/development.md).
179
+
180
+ ## License
181
+
182
+ MIT. See `LICENSE`.
@@ -0,0 +1,148 @@
1
+ <!-- mcp-name: io.github.turbyho/datasheet-lens -->
2
+
3
+ # datasheet-lens
4
+
5
+ datasheet-lens gives the content of component datasheets (PDF) to an LLM agent,
6
+ for electronics design (KiCad and other CAD tools) and firmware work.
7
+
8
+ The tool does not convert a datasheet to text. A conversion makes errors that look
9
+ correct: lost superscripts, merged table rows, shifted columns, wrong values from
10
+ graphs. datasheet-lens builds an index to find the content, and gives the original
11
+ pages and regions to the model on demand. The model reads only the parts that the
12
+ work needs, and reads each value from the original.
13
+
14
+ Status: in development (version 0.1). The tools work and have tests. The
15
+ interfaces can change.
16
+
17
+ ## Features
18
+
19
+ - **Drill-down into a document.** An index (outline, table and figure captions,
20
+ page quality), a text search, a page map with element IDs, and images of an
21
+ element, a region, a caption ("Table 57", with docling also when the table
22
+ continues on more pages) or a full page at 300 to 600 dpi.
23
+ - **Central store, shared by all projects.** Each user has one store (default
24
+ `~/.datasheet-lens`) for all design projects. Each PDF is stored one time
25
+ (SHA-256), with its index, its element map, its parts and the facts that sessions
26
+ read from it. A datasheet that one project added is at once available to each
27
+ other project: it is not downloaded, indexed or read again. A part can have a
28
+ datasheet, a manual and errata.
29
+ - **Facts.** A value that a session read is saved with its source (document, page,
30
+ element), so that a later session finds it.
31
+ - **Project file.** `datasheet-lens.toml` in the repository of a design holds the
32
+ parts of the design and their documents. The team gets it with the repository.
33
+ `project_check` compares it with the parts of the CAD project.
34
+ - **Orderable parts.** The ordering codes of a datasheet, and the lifecycle state,
35
+ stock and prices from the official API of a distributor (Mouser now). No
36
+ scraping.
37
+
38
+ ## Typical uses
39
+
40
+ datasheet-lens helps to manage the input documents of a design project, and to keep
41
+ them in the repository. It keeps the BOM equal to the CAD project. It lets the agent
42
+ check the BOM, and check the design against the original datasheets.
43
+
44
+ - Keep the datasheets of a design complete and in git, the same for each person of
45
+ the team.
46
+ - Compare the project with the parts of the CAD project: missing, extra and
47
+ different parts.
48
+ - Select the concrete orderable MPN of a base part, and make sure that it can be
49
+ ordered.
50
+ - Review a schematic against the datasheets: pins, absolute maximum ratings, logic
51
+ levels, application circuits.
52
+ - Compare a footprint with the package drawing of the datasheet.
53
+ - Read register maps, bit fields and timing values for firmware, and keep them as
54
+ facts with their source.
55
+ - Use the same parts in more projects: the datasheets and the facts of one project
56
+ are at once available in each other project of the same user.
57
+
58
+ datasheet-lens does not read the schematic itself. The parts come from the CAD tool,
59
+ its MCP server or a BOM file. See [doc/use-cases.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/use-cases.md) for the steps
60
+ of each use.
61
+
62
+ ## Installation
63
+
64
+ datasheet-lens needs Python 3.11 or newer. It works on Linux, macOS and Windows.
65
+
66
+ ```sh
67
+ pipx install git+https://github.com/turbyho/datasheet-lens.git
68
+ datasheet-lens init
69
+ ```
70
+
71
+ `datasheet-lens init` makes the central store (default `~/.datasheet-lens`, or the
72
+ folder in the environment variable `DATASHEET_LENS_HOME`). It can also install
73
+ docling, which gives a better element map (tables and figures). docling is
74
+ optional: it needs some GB of disk. Without it, the tool uses the text layer.
75
+
76
+ Register the MCP server (stdio) in Claude Code:
77
+
78
+ ```sh
79
+ claude mcp add --scope user datasheet-lens -- datasheet-lens-mcp
80
+ ```
81
+
82
+ For a different MCP client, set the command `datasheet-lens-mcp` with no
83
+ arguments. The server gives its instructions to the agent. See
84
+ [doc/installation.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/installation.md) and [doc/mcp-server.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/mcp-server.md).
85
+
86
+ ## Quick start
87
+
88
+ In the root folder of the repository of the design:
89
+
90
+ ```sh
91
+ datasheet-lens project init # the project file, and a block in AGENTS.md, CLAUDE.md
92
+ datasheet-lens add PATH|URL # add a datasheet; it proposes the MPN of the part
93
+ datasheet-lens sync # copy the documents into the project folder
94
+ datasheet-lens check BOM.csv # compare the project with a BOM of the CAD project
95
+ ```
96
+
97
+ The agent uses the same functions through the MCP server. The block in
98
+ `AGENTS.md` or `CLAUDE.md` tells the agent the procedure. `project init` changes
99
+ only the files that exist: make one of them first if you want the block.
100
+
101
+ | Command | What it does |
102
+ |---|---|
103
+ | `add PATH\|URL` | Add a document to the store and to the project |
104
+ | `ls`, `sync` | Show the project, or synchronize its copies |
105
+ | `check BOM.csv` | Compare the project with a BOM (CSV) of the CAD project, and find conflicts between the MPN and Value fields (tested only with BOM exports of KiCad and Eagle) |
106
+ | `set MPN -m NEW` | Change the MPN, base part, category or manufacturer of a project part |
107
+ | `rm MPN` | Remove a part (or `-d DOC`, a document) from the project |
108
+ | `search TEXT --part MPN` | Find a text in the documents of a part |
109
+ | `codes DOC` | Show the orderable codes of a datasheet |
110
+ | `links MPN` | Show search links for a datasheet, stock, a symbol, a footprint, a 3D model |
111
+ | `find MPN` | Find a part at the distributors (lifecycle, stock, prices) |
112
+ | `stock` | Show the lifecycle state and the stock of each project part |
113
+ | `key NAME` | Save the API key of a distributor |
114
+ | `dist NAME ...` | Select the distributors (globally, or `--local` for the project) |
115
+
116
+ All commands and options are in [doc/cli.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/cli.md).
117
+
118
+ Each user has a personal API key for each distributor. Get a free Mouser key at
119
+ the [Mouser API Hub](https://www.mouser.com/api-hub/) (Search API), then run
120
+ `datasheet-lens key mouser`. See [doc/distributors.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/distributors.md).
121
+
122
+ ## Documentation
123
+
124
+ | Document | Content |
125
+ |---|---|
126
+ | [doc/installation.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/installation.md) | Requirements, installation, `init`, docling, store location, upgrade, uninstall |
127
+ | [doc/use-cases.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/use-cases.md) | Typical uses, step by step |
128
+ | [doc/mcp-server.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/mcp-server.md) | MCP server: registration, instructions, all tools |
129
+ | [doc/agent-workflow.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/agent-workflow.md) | How an agent reads a datasheet, with an example |
130
+ | [doc/projects.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/projects.md) | Project file, layout, sync, team workflow, consistency with the CAD project |
131
+ | [doc/cli.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/cli.md) | Reference of all CLI commands and options |
132
+ | [doc/distributors.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/distributors.md) | Distributor data, API keys, distributor selection, search links |
133
+ | [doc/architecture.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/architecture.md) | For developers: design decisions and module map |
134
+ | [doc/development.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/development.md) | Development setup, tests, code and text style |
135
+
136
+ ## Development
137
+
138
+ ```sh
139
+ python3 -m venv .venv
140
+ .venv/bin/pip install -e ".[dev]"
141
+ .venv/bin/python -m pytest
142
+ ```
143
+
144
+ See [doc/development.md](https://github.com/turbyho/datasheet-lens/blob/main/doc/development.md).
145
+
146
+ ## License
147
+
148
+ MIT. See `LICENSE`.
@@ -0,0 +1,256 @@
1
+ # Agent workflow
2
+
3
+ This document tells how an LLM agent reads a datasheet with datasheet-lens. The
4
+ agent uses the MCP tools (see [mcp-server.md](mcp-server.md)). The server
5
+ instructions and the tool descriptions give the agent the same method in short form.
6
+
7
+ ## The principle
8
+
9
+ datasheet-lens does not convert a datasheet to text. A conversion makes errors that
10
+ look correct: lost superscripts, merged table rows, shifted columns, and wrong values
11
+ from graphs. The text layer of a PDF can also lose signs, units and subscripts.
12
+
13
+ Thus the agent uses the index and the text layer only to find the content. It reads
14
+ each value from the original page: a PNG image (`get_page_image`) or the PDF pages
15
+ (`get_pdf_pages`). It reads only the parts that the work needs.
16
+
17
+ ## Read a datasheet step by step
18
+
19
+ ### 1. Find the document
20
+
21
+ | Tool | Use |
22
+ |---|---|
23
+ | `project_status` | The parts and documents of the user project. |
24
+ | `list_documents(part)` | The documents of one part in the store. A part can have a datasheet, a manual, errata and application notes. |
25
+ | `list_parts` | All parts in the store. |
26
+ | `add_document` | A new document from a local PDF or a URL, when the store does not have it. |
27
+
28
+ Each result gives the document reference: the first 12 characters of the SHA-256 of
29
+ the file. The other tools use this reference.
30
+
31
+ ### 2. Find known facts
32
+
33
+ Before the agent reads a value, it calls `find_facts` with the part or the document.
34
+ A fact is a value that a session read before and saved with its source. A fact is
35
+ not the source of truth. For an important value, the agent compares the fact with
36
+ the original and sets its state (see step 9).
37
+
38
+ `get_page_map` and `get_page_image` also give a line with the known facts of their
39
+ page.
40
+
41
+ ### 3. Get the index
42
+
43
+ `get_index(document)` gives:
44
+
45
+ - The outline, from the PDF bookmarks or from the numbered headings, with pages.
46
+ - The table and figure captions, with page and position.
47
+ - The pages that have no text layer (read them as images).
48
+ - The pages with a raster image below 300 dpi.
49
+ - A page map of headings, for a short document or a document with no outline.
50
+
51
+ A large document (more than 300 outline entries) gives only the top two levels.
52
+ `get_outline(document, section)` gives the entries under one section, for example
53
+ `section="8.27"`. `list_items(document, kind)` gives all tables, figures and
54
+ captions with their element IDs.
55
+
56
+ ### 4. Search the text
57
+
58
+ `search_text` finds a word, a register name, a pin name or a value. Give
59
+ `document` for one document, or `part` for all documents of a part.
60
+
61
+ | Parameter | Effect |
62
+ |---|---|
63
+ | `mode="text"` | A substring, case is ignored (default). `"VDD"` also finds `"AVDD"`. The space between a number and its unit is optional: `"100 nF"` also finds `"100nF"`. |
64
+ | `mode="word"` | Whole words only. `"nF"` does not find `"configuration"`. |
65
+ | `mode="regex"` | A Python regular expression, case is ignored. For example `"Pin Functions?"`. |
66
+ | `max_lines` | The maximum number of hit lines (1 to 200, default 30). |
67
+ | `repeated=true` | Also show the lines that repeat on many pages (page headers and footers). |
68
+
69
+ Each hit line gives the document reference, the page, and the table or figure that
70
+ holds the line (an element ID such as `p5.T1`) or the region of the line. The tool
71
+ gives the element or region for the hits on the first 10 pages with hits. A last
72
+ line tells how many page header and footer lines it did not show.
73
+
74
+ ### 5. Get the page map
75
+
76
+ `get_page_map(document, page)` gives the elements of one page: headings, tables,
77
+ figures, formulas and captions. Each line has the element ID, the type, the region
78
+ `[x0, y0, x1, y1]` in pt (origin at the top left of the page) and the text or
79
+ caption. The other text elements are only counted. `all_elements=true` lists them
80
+ too. `get_element_text` gives the full text of headings and paragraphs.
81
+
82
+ An element ID has the form `p<page>.<code><n>`, for example `p7.T1`. The codes are:
83
+
84
+ | Code | Element |
85
+ |---|---|
86
+ | `H` | Heading |
87
+ | `P` | Paragraph or text block |
88
+ | `L` | List item |
89
+ | `T` | Table |
90
+ | `F` | Figure |
91
+ | `Q` | Formula |
92
+ | `C` | Caption |
93
+ | `N` | Footnote |
94
+ | `K` | Code |
95
+ | `R` | Page header or footer (not shown) |
96
+
97
+ With the `text` backend (no docling), the map has no tables and figures. It has
98
+ headings, text blocks and captions.
99
+
100
+ ### 6. Read the original
101
+
102
+ `get_page_image` gives the original as a PNG image. Give one of these:
103
+
104
+ | Parameter | Image |
105
+ |---|---|
106
+ | `element="p7.T1"` | The region of the element, with a small margin. |
107
+ | `caption="Table 57"` | The table or figure with this caption label. A table that continues on the next pages gives one image for each page (6 images or fewer). |
108
+ | `page` and `bbox=[x0, y0, x1, y1]` | A region of the page, in pt, origin at the top left. |
109
+ | `page` only | The full page. |
110
+
111
+ An element, a caption or a region is rendered at 300 to 600 dpi. A full page gets
112
+ the resolution that fits `max_px` on its long edge (256 to 8000, default 2576). A
113
+ region also stays within `max_px`: a large region that does not fit at 300 dpi gets
114
+ a lower resolution. Prefer an element, a caption or a region, because a full page
115
+ costs more input. For a table that fills the page, a full page at `max_px=1600` is
116
+ sufficient.
117
+
118
+ With the `text` backend, a caption gives the full page of the caption, because the
119
+ map has no table regions.
120
+
121
+ `get_pdf_pages(document, pages)` gives the original pages as a new PDF, for a client
122
+ that can read a PDF. The pages are a list such as `"7"` or `"3-5,8"`, 50 pages or
123
+ fewer.
124
+
125
+ ### 7. Save the facts
126
+
127
+ `save_fact` saves each value that the work uses, with its source:
128
+
129
+ - `document`, `page`, and `element` or `bbox`: where the value is.
130
+ - `subject`: what the value is, for example `"VDD maximum"`.
131
+ - `value` and `unit`: one value as the original shows it. For MIN, TYP and MAX,
132
+ save one fact for each column, and give `column`.
133
+ - `conditions`: for example `"TA = 25 °C, VDD = 3.3 V"`.
134
+ - `note`: for example a footnote of the table.
135
+ - `model`: the model ID of the agent.
136
+ - `part`: the part, when the document covers more parts.
137
+
138
+ A new fact has the state `unchecked`. When the page has a fact with the same subject
139
+ or element, the result gives a note. If the new fact is a copy, set its state to
140
+ `disputed`.
141
+
142
+ ### 8. Find facts later
143
+
144
+ A later session calls `find_facts` with a text, a document or a part. A concrete
145
+ MPN also finds the facts of the datasheet of its base part. Each line gives the fact
146
+ number, subject, value, column, conditions, source, state and author.
147
+
148
+ ### 9. Check a fact
149
+
150
+ After the agent compares a fact with the original, it calls `set_fact_status`:
151
+
152
+ | State | Meaning |
153
+ |---|---|
154
+ | `unchecked` | Nobody compared the fact with the original. |
155
+ | `checked` | The agent compared the fact with the original. |
156
+ | `disputed` | The original or a different source does not agree. |
157
+
158
+ The `note` is added to the existing note of the fact.
159
+
160
+ ## Base part and concrete MPN
161
+
162
+ A datasheet describes a base part, for example `TLV755P`. A BOM needs a concrete
163
+ orderable MPN, with its package, voltage, grade and packing, for example
164
+ `TLV75533PDBVR`. datasheet-lens keeps the two:
165
+
166
+ - In the store, the datasheet is linked to the base part. A concrete part refers to
167
+ its base part and gets its documents.
168
+ - In the project file, a part has the concrete MPN in `mpn` and the base part in
169
+ `base`.
170
+
171
+ To find the concrete MPN:
172
+
173
+ 1. `get_ordering_codes(document)` gives the orderable codes in the text layer, with
174
+ page and line. A line of an ordering table comes first. It can give the package,
175
+ the packing, the temperature range and the state (`ACTIVE`, `NRND`).
176
+ 2. Some datasheets give only a scheme of their codes, with an example. Then
177
+ `get_ordering_codes` gives no list. Find the ordering information with
178
+ `search_text("ordering")`, and read it with `get_page_image`.
179
+ 3. A code of the datasheet is not always sold. `search_distributors(mpn)` gives the
180
+ concrete MPNs that a distributor has, with lifecycle state and stock. See
181
+ [distributors.md](distributors.md).
182
+
183
+ When a project part is probably a base part, `project_add_part` gives a note. The
184
+ note gives the codes that the datasheet text has, and the call that changes the
185
+ part, for example
186
+ `project_update_part(mpn='TLV755P', new_mpn='TLV75533PDBVR', base='TLV755P')`.
187
+
188
+ A datasheet can cover more parts, for example `ADC34J22`, `ADC34J23` and `ADC34J24`.
189
+ Give one of them as `part` and the others as `variants` to `add_document`. The store
190
+ then links the datasheet to each variant.
191
+
192
+ ## Search links
193
+
194
+ When the store has no datasheet and a distributor gives none, `part_links(mpn)` gives
195
+ search links:
196
+
197
+ - Datasheet, price and stock: DigiKey, Mouser, Farnell, LCSC, Octopart, Findchips.
198
+ - Symbol, footprint and 3D model: Component Search Engine, SnapMagic, Ultra
199
+ Librarian.
200
+
201
+ datasheet-lens does not open these pages. The agent opens one with a web tool, or
202
+ gives the links to the user. For a datasheet that it finds, the agent calls
203
+ `add_document` with the URL.
204
+
205
+ ## Example
206
+
207
+ The user asks: "What is the maximum supply voltage of the OPA2134, and what is the
208
+ offset voltage at 25 °C?" The values in this example are placeholders.
209
+
210
+ ```text
211
+ agent: find_facts(part="OPA2134")
212
+ server: No facts.
213
+
214
+ agent: list_documents(part="OPA2134")
215
+ server: 3f9c0a1b2c4d 35 pages opa2134.pdf (datasheet)
216
+
217
+ agent: get_index(document="3f9c0a1b2c4d")
218
+ server: # opa2134.pdf
219
+ ## Outline
220
+ - 1 Features (p.1)
221
+ ...
222
+ - 6.1 Absolute Maximum Ratings (p.4)
223
+ - 6.5 Electrical Characteristics (p.5)
224
+ ## Tables and figures
225
+ ...
226
+
227
+ agent: search_text(text="Supply voltage", document="3f9c0a1b2c4d", mode="word")
228
+ server: 3f9c0a1b2c4d p.4 p4.T1: Supply voltage, VS = (V+) – (V–) ...
229
+ 3f9c0a1b2c4d p.5 p5.T1: ...
230
+
231
+ agent: get_page_image(document="3f9c0a1b2c4d", element="p4.T1")
232
+ server: 3f9c0a1b2c4d page 4, region [...], 412 dpi, 2400 x 610 px
233
+ <image>
234
+
235
+ agent: save_fact(document="3f9c0a1b2c4d", page=4, element="p4.T1",
236
+ subject="Supply voltage maximum", value="<value>", unit="V",
237
+ column="MAX", model="<model ID>")
238
+ server: fact #1 saved (unchecked)
239
+
240
+ agent: get_page_map(document="3f9c0a1b2c4d", page=5)
241
+ server: p5.H1 section_header [...] 6.5 Electrical Characteristics
242
+ p5.T1 table [...] ...
243
+ + 4 text elements (p5.P1 … p5.P4); ...
244
+
245
+ agent: get_page_image(document="3f9c0a1b2c4d", element="p5.T1")
246
+ server: 3f9c0a1b2c4d page 5, region [...], 300 dpi, ...
247
+ <image>
248
+
249
+ agent: save_fact(document="3f9c0a1b2c4d", page=5, element="p5.T1",
250
+ subject="Input offset voltage", value="<value>", unit="mV",
251
+ column="TYP", conditions="TA = 25 °C", model="<model ID>")
252
+ server: fact #2 saved (unchecked)
253
+ ```
254
+
255
+ The agent then gives the two values to the user, with the page and the table of
256
+ each value. A later session finds them with `find_facts(part="OPA2134")`.