webcite 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 (37) hide show
  1. webcite-0.1.0/.gitignore +9 -0
  2. webcite-0.1.0/CHANGELOG.md +17 -0
  3. webcite-0.1.0/LICENSE +21 -0
  4. webcite-0.1.0/Makefile +26 -0
  5. webcite-0.1.0/PKG-INFO +248 -0
  6. webcite-0.1.0/README.md +214 -0
  7. webcite-0.1.0/examples/frameworks/crewai_mcp.py +62 -0
  8. webcite-0.1.0/examples/frameworks/google_adk_mcp.py +44 -0
  9. webcite-0.1.0/examples/frameworks/haystack_pipeline.py +26 -0
  10. webcite-0.1.0/examples/frameworks/langchain_agent.py +25 -0
  11. webcite-0.1.0/examples/frameworks/openai_agents_mcp.py +43 -0
  12. webcite-0.1.0/examples/frameworks/pydantic_ai_mcp.py +39 -0
  13. webcite-0.1.0/examples/quickstart_fixtures.py +40 -0
  14. webcite-0.1.0/llms.txt +30 -0
  15. webcite-0.1.0/pyproject.toml +68 -0
  16. webcite-0.1.0/src/webcite/__init__.py +41 -0
  17. webcite-0.1.0/src/webcite/_async_client.py +453 -0
  18. webcite-0.1.0/src/webcite/_base.py +166 -0
  19. webcite-0.1.0/src/webcite/_client.py +440 -0
  20. webcite-0.1.0/src/webcite/_errors.py +207 -0
  21. webcite-0.1.0/src/webcite/_requests.py +283 -0
  22. webcite-0.1.0/src/webcite/_version.py +1 -0
  23. webcite-0.1.0/src/webcite/py.typed +0 -0
  24. webcite-0.1.0/src/webcite/types.py +182 -0
  25. webcite-0.1.0/tests/__init__.py +0 -0
  26. webcite-0.1.0/tests/conftest.py +69 -0
  27. webcite-0.1.0/tests/fixtures/README.md +8 -0
  28. webcite-0.1.0/tests/fixtures/balance.json +1 -0
  29. webcite-0.1.0/tests/fixtures/claim-apple-fy2024.json +1 -0
  30. webcite-0.1.0/tests/fixtures/claim-great-wall.json +1 -0
  31. webcite-0.1.0/tests/fixtures/doc-bls-table.json +1 -0
  32. webcite-0.1.0/tests/fixtures/doc-irs-w9.json +1 -0
  33. webcite-0.1.0/tests/fixtures/openapi.json +1 -0
  34. webcite-0.1.0/tests/test_client.py +107 -0
  35. webcite-0.1.0/tests/test_contract.py +97 -0
  36. webcite-0.1.0/tests/test_errors_retries.py +88 -0
  37. webcite-0.1.0/tests/test_stream_ask_async.py +93 -0
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .mypy_cache/
8
+ .ruff_cache/
9
+ .pytest_cache/
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to this package are recorded here. The project follows
4
+ [semantic versioning](https://semver.org/).
5
+
6
+ ## 0.1.0 (unreleased)
7
+
8
+ First version.
9
+
10
+ - `Webcite` and `AsyncWebcite` clients over `httpx` for every operation in the public OpenAPI
11
+ document (28 operations) plus the credit balance route (29 methods in all).
12
+ - API key from `api_key=` or `WEBCITE_API_KEY`; base URL from `base_url=` or `WEBCITE_API_URL`.
13
+ - Typed errors carrying the server's message, a next step and a documentation link.
14
+ - Retries with backoff for GET requests and keyed verifications on 429 and 5xx only.
15
+ - 15-minute default timeout for long extractions; `wait_for_ask()` polling helper.
16
+ - Verification streaming that fails loudly when the stream ends without a result and `done`.
17
+ - No telemetry.
webcite-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Marvin
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.
webcite-0.1.0/Makefile ADDED
@@ -0,0 +1,26 @@
1
+ VENV ?= .venv
2
+ PY := $(VENV)/bin/python
3
+
4
+ .PHONY: install check lint typecheck test build update-openapi
5
+
6
+ install:
7
+ uv venv -p 3.9 $(VENV) || python3 -m venv $(VENV)
8
+ uv pip install -p $(VENV) -e ".[dev]" || $(PY) -m pip install -e ".[dev]"
9
+
10
+ lint:
11
+ $(VENV)/bin/ruff check src tests examples
12
+ $(VENV)/bin/ruff format --check src tests examples
13
+
14
+ typecheck:
15
+ $(VENV)/bin/mypy
16
+
17
+ test:
18
+ $(VENV)/bin/pytest -q
19
+
20
+ check: lint typecheck test
21
+
22
+ build:
23
+ rm -rf dist && uv build
24
+
25
+ update-openapi:
26
+ curl -fsS https://api.webcite.co/api/v1/openapi.json -o tests/fixtures/openapi.json
webcite-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,248 @@
1
+ Metadata-Version: 2.4
2
+ Name: webcite
3
+ Version: 0.1.0
4
+ Summary: Parse documents to Markdown and verify claims against sources, with citations bound to quotes. Python SDK for the Webcite API.
5
+ Project-URL: Homepage, https://webcite.co/api-docs
6
+ Project-URL: Documentation, https://webcite.co/api-docs
7
+ Project-URL: Repository, https://github.com/strategyconnect/webcite-python
8
+ Project-URL: Changelog, https://github.com/strategyconnect/webcite-python/blob/main/CHANGELOG.md
9
+ Author: Webcite
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: ai-agents,citations,claim-verification,document-parsing,fact-checking,grounding,hallucination-detection,mcp,ocr,pdf-to-markdown,rag,source-search,webcite
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Classifier: Topic :: Text Processing
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: >=3.9
28
+ Requires-Dist: httpx<1,>=0.25
29
+ Provides-Extra: dev
30
+ Requires-Dist: mypy>=1.10; extra == 'dev'
31
+ Requires-Dist: pytest>=8; extra == 'dev'
32
+ Requires-Dist: ruff>=0.5; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # Webcite Python SDK
36
+
37
+ Webcite is an API for document parsing and claim verification. It reads PDFs, scans,
38
+ spreadsheets and office files into Markdown with per-page provenance, checks claims against
39
+ web sources or your own documents, and returns citations bound to the quotes that support or
40
+ contradict them. On ParseBench 2, Webcite extraction scored 91.74 overall (ranking pending
41
+ approval by LlamaIndex). This package is the official Python client for the
42
+ [Webcite API](https://webcite.co/api-docs).
43
+
44
+ ```bash
45
+ pip install webcite
46
+ ```
47
+
48
+ Python 3.9 or newer. The only dependency is `httpx`.
49
+
50
+ ## First call
51
+
52
+ ```python
53
+ from webcite import Webcite
54
+
55
+ client = Webcite() # reads WEBCITE_API_KEY
56
+ result = client.verify("The Great Wall of China is visible from the Moon with the naked eye.")
57
+ group = result["claim_groups"][0]
58
+ print(group["verdict"]["result"], result["usage"]["credits"])
59
+ for citation in group["citations"][:1]:
60
+ print(citation["stance"], citation["url"])
61
+ ```
62
+
63
+ Recorded output (from the saved response at
64
+ [webcite.co/samples/claim-great-wall.json](https://webcite.co/samples/claim-great-wall.json),
65
+ recorded from the API on 24 November 2026):
66
+
67
+ ```text
68
+ contradicted 4
69
+ contradicts https://www.nasa.gov/image-article/great-wall/
70
+ ```
71
+
72
+ A verification costs 4 credits with the default stance and verdict. The Free plan includes
73
+ 100 credits.
74
+
75
+ ## Parse a document
76
+
77
+ ```python
78
+ from webcite import Webcite
79
+
80
+ client = Webcite()
81
+ asset = client.upload("irs-form-w9-page-1.pdf")["data"]
82
+ doc = client.extract(asset["asset_id"])
83
+ print(doc["state"], doc["usage"]["credits"])
84
+ print(doc["markdown"].splitlines()[0])
85
+ ```
86
+
87
+ Recorded output (saved response at
88
+ [webcite.co/samples/doc-irs-w9.json](https://webcite.co/samples/doc-irs-w9.json)):
89
+
90
+ ```text
91
+ complete 0.4966
92
+ Form **W-9**
93
+ ```
94
+
95
+ Uploading is free. Extraction is charged per page at cost. Check `state` before using
96
+ `markdown`: `complete: false` and `lost` name parts that were not recovered. The request stays
97
+ open until every page is read; there is no job to poll. `extract_pages()` returns anchored
98
+ chunks for indexing and `extract_figures()` returns every recognised number with its source.
99
+
100
+ ## Check quotes against sources
101
+
102
+ ```python
103
+ sec = "https://www.sec.gov/Archives/edgar/data/320193/000032019324000123/aapl-20240928.htm"
104
+ results = client.verify_batch([
105
+ {"id": "q1", "quote": "Total net sales 391,035", "url": sec},
106
+ {"id": "q2", "quote": "Revenue was $12 million.", "asset_id": asset["asset_id"], "page": 1},
107
+ ])
108
+ for item in results:
109
+ print(item)
110
+ ```
111
+
112
+ ## Search sources and preview evidence
113
+
114
+ ```python
115
+ found = client.search("Apple total net sales fiscal 2024", limit=5)
116
+ preview = client.source_preview(url=found["citations"][0]["url"], quote="Total net sales")
117
+ ```
118
+
119
+ ## Stream a verification
120
+
121
+ ```python
122
+ for event in client.verify_stream("The Eiffel Tower is 330 meters tall"):
123
+ print(event["data"].get("type"))
124
+ ```
125
+
126
+ The iterator raises `IncompleteStreamError` (with the events received so far) if the stream
127
+ ends without a `result` and a later `done` event, or reports `error`.
128
+
129
+ ## Ask a question over a document
130
+
131
+ ```python
132
+ job = client.ask("What was revenue in FY2025?", doc["markdown"])
133
+ answer = client.wait_for_ask(job["id"]) # polls GET /api/v1/ask/{id}
134
+ print(answer["status"])
135
+ ```
136
+
137
+ `wait_for_ask` stops on `done` or `failed`. After `max_wait` seconds (600 by default) it returns
138
+ the latest job view instead of raising, so you can keep polling.
139
+
140
+ ## Credits
141
+
142
+ ```python
143
+ print(client.balance()["credits"]["remaining"]) # free
144
+ ```
145
+
146
+ ## Async
147
+
148
+ ```python
149
+ import asyncio
150
+ from webcite import AsyncWebcite
151
+
152
+ async def main() -> None:
153
+ async with AsyncWebcite() as client:
154
+ result = await client.verify("The Eiffel Tower is 330 meters tall")
155
+ print(result["claim_groups"][0]["verdict"]["result"])
156
+
157
+ asyncio.run(main())
158
+ ```
159
+
160
+ Every method on `Webcite` exists on `AsyncWebcite`.
161
+
162
+ ## Authentication
163
+
164
+ Create a key on the [API Keys page](https://webcite.co/api-keys) (sign-in required) and set it
165
+ as `WEBCITE_API_KEY`, or pass `Webcite(api_key=...)`. The key is sent in the `x-api-key`
166
+ header. Keep it on your server; never put it in frontend code, a public repository or a chat
167
+ with an AI agent. The `webcite` command line tool in the
168
+ [TypeScript package](https://github.com/strategyconnect/webcite-js) can store a key with
169
+ `webcite login`.
170
+
171
+ ## Self-hosted deployments
172
+
173
+ Set `WEBCITE_API_URL` or pass `base_url`:
174
+
175
+ ```python
176
+ client = Webcite(base_url="https://webcite.internal.example.com")
177
+ ```
178
+
179
+ The default is `https://api.webcite.co`. A key works only against the environment that issued it.
180
+
181
+ ## Errors
182
+
183
+ Every error is a `webcite.WebciteError` with `status`, `code`, `message` (the server's text),
184
+ `next_step`, `doc_url` and `retry_after`.
185
+
186
+ | Error | When |
187
+ | --- | --- |
188
+ | `AuthenticationError` | 401, or no key. `next_step` points to the API keys page. |
189
+ | `PermissionDeniedError` | 403. App keys cannot upload or extract. |
190
+ | `NotFoundError` | 404. The ID does not belong to this account. |
191
+ | `ConflictError` | 409. An Idempotency-Key was reused with a different payload. |
192
+ | `InsufficientCreditsError` | The balance is below the cost. Nothing was charged. |
193
+ | `RateLimitError` | 429. `retry_after` is in seconds. |
194
+ | `ServerError` | 5xx. |
195
+ | `WebciteTimeoutError`, `WebciteConnectionError` | The request did not complete. |
196
+ | `IncompleteStreamError` | A stream ended without a result and `done`. |
197
+
198
+ ```python
199
+ import webcite
200
+
201
+ try:
202
+ client.verify("...")
203
+ except webcite.InsufficientCreditsError as err:
204
+ print(err.message, err.next_step)
205
+ ```
206
+
207
+ ## Retries and timeouts
208
+
209
+ GET requests and `verify()` are retried up to twice on 429 and 5xx, with backoff that honours
210
+ `Retry-After`. `verify()` sends an `Idempotency-Key`, so a retry is not charged twice. Other
211
+ paid calls (extraction, batch, upload) are never repeated automatically; a timeout does not
212
+ prove the server did no work. The default timeout is 15 minutes, matching the extraction docs;
213
+ pass `timeout=` (seconds or an `httpx.Timeout`) and `max_retries=` to change them.
214
+
215
+ The SDK sends no telemetry. Each request carries `x-webcite-surface: sdk-python` and a
216
+ `webcite-python/<version>` user agent, which Webcite stores as labels only.
217
+
218
+ ## Use with agent frameworks
219
+
220
+ Short runnable examples are in [`examples/frameworks/`](examples/frameworks):
221
+
222
+ | Framework | File | How it connects |
223
+ |---|---|---|
224
+ | LangChain | `langchain_agent.py` | [`langchain-webcite`](https://github.com/strategyconnect/langchain-webcite) tools and retriever |
225
+ | Haystack | `haystack_pipeline.py` | [`webcite-haystack`](https://github.com/strategyconnect/webcite-haystack) components |
226
+ | CrewAI | `crewai_mcp.py` | Hosted MCP server |
227
+ | Google ADK | `google_adk_mcp.py` | Hosted MCP server through `McpToolset` |
228
+ | OpenAI Agents SDK | `openai_agents_mcp.py` | Hosted MCP server through `MCPServerStreamableHttp` |
229
+ | Pydantic AI | `pydantic_ai_mcp.py` | Hosted MCP server through `MCPToolset` |
230
+
231
+ The MCP examples list the Webcite tools without calling a model when run with no arguments.
232
+
233
+ ## Links
234
+
235
+ - API documentation: https://webcite.co/api-docs (each page has a Markdown copy)
236
+ - OpenAPI: https://api.webcite.co/api/v1/openapi.json
237
+ - Errors and rate limits: https://webcite.co/api-docs/errors
238
+ - MCP server for AI agents: https://webcite.co/api-docs/mcp
239
+ - TypeScript SDK and CLI: https://github.com/strategyconnect/webcite-js
240
+
241
+ ## Development
242
+
243
+ ```bash
244
+ make install
245
+ make check # ruff, mypy --strict, pytest; no network calls
246
+ ```
247
+
248
+ MIT licensed.
@@ -0,0 +1,214 @@
1
+ # Webcite Python SDK
2
+
3
+ Webcite is an API for document parsing and claim verification. It reads PDFs, scans,
4
+ spreadsheets and office files into Markdown with per-page provenance, checks claims against
5
+ web sources or your own documents, and returns citations bound to the quotes that support or
6
+ contradict them. On ParseBench 2, Webcite extraction scored 91.74 overall (ranking pending
7
+ approval by LlamaIndex). This package is the official Python client for the
8
+ [Webcite API](https://webcite.co/api-docs).
9
+
10
+ ```bash
11
+ pip install webcite
12
+ ```
13
+
14
+ Python 3.9 or newer. The only dependency is `httpx`.
15
+
16
+ ## First call
17
+
18
+ ```python
19
+ from webcite import Webcite
20
+
21
+ client = Webcite() # reads WEBCITE_API_KEY
22
+ result = client.verify("The Great Wall of China is visible from the Moon with the naked eye.")
23
+ group = result["claim_groups"][0]
24
+ print(group["verdict"]["result"], result["usage"]["credits"])
25
+ for citation in group["citations"][:1]:
26
+ print(citation["stance"], citation["url"])
27
+ ```
28
+
29
+ Recorded output (from the saved response at
30
+ [webcite.co/samples/claim-great-wall.json](https://webcite.co/samples/claim-great-wall.json),
31
+ recorded from the API on 24 November 2026):
32
+
33
+ ```text
34
+ contradicted 4
35
+ contradicts https://www.nasa.gov/image-article/great-wall/
36
+ ```
37
+
38
+ A verification costs 4 credits with the default stance and verdict. The Free plan includes
39
+ 100 credits.
40
+
41
+ ## Parse a document
42
+
43
+ ```python
44
+ from webcite import Webcite
45
+
46
+ client = Webcite()
47
+ asset = client.upload("irs-form-w9-page-1.pdf")["data"]
48
+ doc = client.extract(asset["asset_id"])
49
+ print(doc["state"], doc["usage"]["credits"])
50
+ print(doc["markdown"].splitlines()[0])
51
+ ```
52
+
53
+ Recorded output (saved response at
54
+ [webcite.co/samples/doc-irs-w9.json](https://webcite.co/samples/doc-irs-w9.json)):
55
+
56
+ ```text
57
+ complete 0.4966
58
+ Form **W-9**
59
+ ```
60
+
61
+ Uploading is free. Extraction is charged per page at cost. Check `state` before using
62
+ `markdown`: `complete: false` and `lost` name parts that were not recovered. The request stays
63
+ open until every page is read; there is no job to poll. `extract_pages()` returns anchored
64
+ chunks for indexing and `extract_figures()` returns every recognised number with its source.
65
+
66
+ ## Check quotes against sources
67
+
68
+ ```python
69
+ sec = "https://www.sec.gov/Archives/edgar/data/320193/000032019324000123/aapl-20240928.htm"
70
+ results = client.verify_batch([
71
+ {"id": "q1", "quote": "Total net sales 391,035", "url": sec},
72
+ {"id": "q2", "quote": "Revenue was $12 million.", "asset_id": asset["asset_id"], "page": 1},
73
+ ])
74
+ for item in results:
75
+ print(item)
76
+ ```
77
+
78
+ ## Search sources and preview evidence
79
+
80
+ ```python
81
+ found = client.search("Apple total net sales fiscal 2024", limit=5)
82
+ preview = client.source_preview(url=found["citations"][0]["url"], quote="Total net sales")
83
+ ```
84
+
85
+ ## Stream a verification
86
+
87
+ ```python
88
+ for event in client.verify_stream("The Eiffel Tower is 330 meters tall"):
89
+ print(event["data"].get("type"))
90
+ ```
91
+
92
+ The iterator raises `IncompleteStreamError` (with the events received so far) if the stream
93
+ ends without a `result` and a later `done` event, or reports `error`.
94
+
95
+ ## Ask a question over a document
96
+
97
+ ```python
98
+ job = client.ask("What was revenue in FY2025?", doc["markdown"])
99
+ answer = client.wait_for_ask(job["id"]) # polls GET /api/v1/ask/{id}
100
+ print(answer["status"])
101
+ ```
102
+
103
+ `wait_for_ask` stops on `done` or `failed`. After `max_wait` seconds (600 by default) it returns
104
+ the latest job view instead of raising, so you can keep polling.
105
+
106
+ ## Credits
107
+
108
+ ```python
109
+ print(client.balance()["credits"]["remaining"]) # free
110
+ ```
111
+
112
+ ## Async
113
+
114
+ ```python
115
+ import asyncio
116
+ from webcite import AsyncWebcite
117
+
118
+ async def main() -> None:
119
+ async with AsyncWebcite() as client:
120
+ result = await client.verify("The Eiffel Tower is 330 meters tall")
121
+ print(result["claim_groups"][0]["verdict"]["result"])
122
+
123
+ asyncio.run(main())
124
+ ```
125
+
126
+ Every method on `Webcite` exists on `AsyncWebcite`.
127
+
128
+ ## Authentication
129
+
130
+ Create a key on the [API Keys page](https://webcite.co/api-keys) (sign-in required) and set it
131
+ as `WEBCITE_API_KEY`, or pass `Webcite(api_key=...)`. The key is sent in the `x-api-key`
132
+ header. Keep it on your server; never put it in frontend code, a public repository or a chat
133
+ with an AI agent. The `webcite` command line tool in the
134
+ [TypeScript package](https://github.com/strategyconnect/webcite-js) can store a key with
135
+ `webcite login`.
136
+
137
+ ## Self-hosted deployments
138
+
139
+ Set `WEBCITE_API_URL` or pass `base_url`:
140
+
141
+ ```python
142
+ client = Webcite(base_url="https://webcite.internal.example.com")
143
+ ```
144
+
145
+ The default is `https://api.webcite.co`. A key works only against the environment that issued it.
146
+
147
+ ## Errors
148
+
149
+ Every error is a `webcite.WebciteError` with `status`, `code`, `message` (the server's text),
150
+ `next_step`, `doc_url` and `retry_after`.
151
+
152
+ | Error | When |
153
+ | --- | --- |
154
+ | `AuthenticationError` | 401, or no key. `next_step` points to the API keys page. |
155
+ | `PermissionDeniedError` | 403. App keys cannot upload or extract. |
156
+ | `NotFoundError` | 404. The ID does not belong to this account. |
157
+ | `ConflictError` | 409. An Idempotency-Key was reused with a different payload. |
158
+ | `InsufficientCreditsError` | The balance is below the cost. Nothing was charged. |
159
+ | `RateLimitError` | 429. `retry_after` is in seconds. |
160
+ | `ServerError` | 5xx. |
161
+ | `WebciteTimeoutError`, `WebciteConnectionError` | The request did not complete. |
162
+ | `IncompleteStreamError` | A stream ended without a result and `done`. |
163
+
164
+ ```python
165
+ import webcite
166
+
167
+ try:
168
+ client.verify("...")
169
+ except webcite.InsufficientCreditsError as err:
170
+ print(err.message, err.next_step)
171
+ ```
172
+
173
+ ## Retries and timeouts
174
+
175
+ GET requests and `verify()` are retried up to twice on 429 and 5xx, with backoff that honours
176
+ `Retry-After`. `verify()` sends an `Idempotency-Key`, so a retry is not charged twice. Other
177
+ paid calls (extraction, batch, upload) are never repeated automatically; a timeout does not
178
+ prove the server did no work. The default timeout is 15 minutes, matching the extraction docs;
179
+ pass `timeout=` (seconds or an `httpx.Timeout`) and `max_retries=` to change them.
180
+
181
+ The SDK sends no telemetry. Each request carries `x-webcite-surface: sdk-python` and a
182
+ `webcite-python/<version>` user agent, which Webcite stores as labels only.
183
+
184
+ ## Use with agent frameworks
185
+
186
+ Short runnable examples are in [`examples/frameworks/`](examples/frameworks):
187
+
188
+ | Framework | File | How it connects |
189
+ |---|---|---|
190
+ | LangChain | `langchain_agent.py` | [`langchain-webcite`](https://github.com/strategyconnect/langchain-webcite) tools and retriever |
191
+ | Haystack | `haystack_pipeline.py` | [`webcite-haystack`](https://github.com/strategyconnect/webcite-haystack) components |
192
+ | CrewAI | `crewai_mcp.py` | Hosted MCP server |
193
+ | Google ADK | `google_adk_mcp.py` | Hosted MCP server through `McpToolset` |
194
+ | OpenAI Agents SDK | `openai_agents_mcp.py` | Hosted MCP server through `MCPServerStreamableHttp` |
195
+ | Pydantic AI | `pydantic_ai_mcp.py` | Hosted MCP server through `MCPToolset` |
196
+
197
+ The MCP examples list the Webcite tools without calling a model when run with no arguments.
198
+
199
+ ## Links
200
+
201
+ - API documentation: https://webcite.co/api-docs (each page has a Markdown copy)
202
+ - OpenAPI: https://api.webcite.co/api/v1/openapi.json
203
+ - Errors and rate limits: https://webcite.co/api-docs/errors
204
+ - MCP server for AI agents: https://webcite.co/api-docs/mcp
205
+ - TypeScript SDK and CLI: https://github.com/strategyconnect/webcite-js
206
+
207
+ ## Development
208
+
209
+ ```bash
210
+ make install
211
+ make check # ruff, mypy --strict, pytest; no network calls
212
+ ```
213
+
214
+ MIT licensed.
@@ -0,0 +1,62 @@
1
+ """Use Webcite's hosted MCP server from a CrewAI agent.
2
+
3
+ pip install crewai "crewai-tools[mcp]"
4
+ export WEBCITE_API_KEY=... # from https://webcite.co/api-keys
5
+ python crewai_mcp.py
6
+
7
+ Environment variables:
8
+ WEBCITE_API_KEY required; tool calls spend credits in the key's account.
9
+ OPENAI_API_KEY or MODEL the crew runs only when one of them is set.
10
+
11
+ Without a model key the script connects to https://api.webcite.co/mcp and lists the
12
+ Webcite tools, which spends no credits.
13
+ """
14
+
15
+ import os
16
+
17
+ from crewai import Agent, Crew, Task
18
+ from crewai.mcp import MCPServerHTTP
19
+
20
+ WEBCITE_MCP_URL = "https://api.webcite.co/mcp"
21
+ CLAIM = "The Great Wall of China is visible from the Moon with the naked eye."
22
+
23
+
24
+ def webcite_server(api_key: str) -> MCPServerHTTP:
25
+ return MCPServerHTTP(
26
+ url=WEBCITE_MCP_URL,
27
+ headers={"Authorization": f"Bearer {api_key}"},
28
+ cache_tools_list=True,
29
+ )
30
+
31
+
32
+ def main() -> None:
33
+ api_key = os.environ.get("WEBCITE_API_KEY")
34
+ if not api_key:
35
+ print("Set WEBCITE_API_KEY (from https://webcite.co/api-keys) and run this file again.")
36
+ return
37
+
38
+ agent = Agent(
39
+ role="Fact checker",
40
+ goal="Say whether a claim holds, citing the sources Webcite returns",
41
+ backstory="You call Webcite's verify_claim tool before you report on any claim.",
42
+ mcps=[webcite_server(api_key)],
43
+ )
44
+
45
+ if not os.environ.get("OPENAI_API_KEY") and not os.environ.get("MODEL"):
46
+ tools = agent.get_mcp_tools(agent.mcps or [])
47
+ print(f"Connected to {WEBCITE_MCP_URL}: {len(tools)} tools")
48
+ for tool in tools:
49
+ print(f"- {tool.name}")
50
+ print("Set OPENAI_API_KEY, or MODEL for another provider, to run the crew.")
51
+ return
52
+
53
+ task = Task(
54
+ description=f"Check this claim with Webcite and report the verdict: {CLAIM}",
55
+ expected_output="The verdict, a one-sentence reason and the cited URLs.",
56
+ agent=agent,
57
+ )
58
+ print(Crew(agents=[agent], tasks=[task]).kickoff())
59
+
60
+
61
+ if __name__ == "__main__":
62
+ main()
@@ -0,0 +1,44 @@
1
+ """Webcite tools in an ADK agent through the hosted MCP server.
2
+
3
+ Install: pip install "google-adk[mcp]"
4
+
5
+ Run `python google_adk_mcp.py` to list the tools the agent receives (no model call).
6
+ Run `adk web` from the parent folder to chat with `root_agent` (needs GOOGLE_API_KEY).
7
+ """
8
+
9
+ import asyncio
10
+ import os
11
+
12
+ from google.adk.agents import Agent
13
+ from google.adk.tools.mcp_tool import McpToolset, StreamableHTTPConnectionParams
14
+
15
+ webcite_tools = McpToolset(
16
+ connection_params=StreamableHTTPConnectionParams(
17
+ url="https://api.webcite.co/mcp?profile=core",
18
+ headers={"Authorization": f"Bearer {os.environ['WEBCITE_API_KEY']}"},
19
+ timeout=30.0,
20
+ sse_read_timeout=300.0,
21
+ ),
22
+ )
23
+
24
+ root_agent = Agent(
25
+ model="gemini-flash-latest",
26
+ name="webcite_agent",
27
+ instruction=(
28
+ "Check factual claims with verify_claim and report the verdict with its citations. "
29
+ "To read a document, call upload_url and then extract_document."
30
+ ),
31
+ tools=[webcite_tools],
32
+ )
33
+
34
+
35
+ async def main() -> None:
36
+ try:
37
+ tools = await webcite_tools.get_tools()
38
+ print(len(tools), "tools:", ", ".join(t.name for t in tools))
39
+ finally:
40
+ await webcite_tools.close()
41
+
42
+
43
+ if __name__ == "__main__":
44
+ asyncio.run(main())
@@ -0,0 +1,26 @@
1
+ """Convert a PDF to Markdown, then check a claim from it, in one Haystack pipeline run.
2
+
3
+ Install: pip install "git+https://github.com/strategyconnect/webcite-python.git@v0.1.0" "git+https://github.com/strategyconnect/webcite-haystack.git@v0.1.0"
4
+ Run: WEBCITE_API_KEY=... python haystack_pipeline.py
5
+ """
6
+
7
+ from haystack import Pipeline
8
+ from haystack_integrations.components.converters.webcite import WebciteDocumentConverter
9
+ from haystack_integrations.components.verifiers.webcite import WebciteClaimVerifier
10
+ from haystack_integrations.components.websearch.webcite import WebciteWebSearch
11
+
12
+ pipe = Pipeline()
13
+ pipe.add_component("convert", WebciteDocumentConverter(mode="lite"))
14
+ pipe.add_component("search", WebciteWebSearch(top_k=3))
15
+ pipe.add_component("verify", WebciteClaimVerifier(max_citations=2))
16
+
17
+ result = pipe.run(
18
+ {
19
+ "convert": {"sources": ["https://www.irs.gov/pub/irs-pdf/fw9.pdf"]},
20
+ "search": {"query": "Apple total net sales fiscal 2024"},
21
+ "verify": {"claims": ["The Great Wall of China is visible from the Moon."]},
22
+ }
23
+ )
24
+ print(result["convert"]["documents"][0].meta)
25
+ print(result["search"]["links"])
26
+ print(result["verify"]["verdicts"][0]["result"])