llama-index-readers-contextfetch 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.
@@ -0,0 +1,20 @@
1
+ .venv/
2
+ node_modules/
3
+ .next/
4
+ dist/
5
+ engine/.model_cache/
6
+ engine/.data/
7
+ .env
8
+ .env.npm
9
+ .env.webshare
10
+ .venv
11
+ engine/.model_cache
12
+ growth-sniper/leads.csv
13
+ __pycache__/
14
+ .pytest_cache/
15
+ .env.hetzner
16
+ .next-*/
17
+ .vercel/
18
+ benchmarks/data/
19
+ *.tsbuildinfo
20
+ next-env.d.ts
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2026 ContextFetch
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.5
2
+ Name: llama-index-readers-contextfetch
3
+ Version: 0.1.0
4
+ Summary: llama-index readers contextfetch integration
5
+ Project-URL: Homepage, https://contextfetch.dev
6
+ Project-URL: Documentation, https://contextfetch.dev/docs/reference
7
+ Author: ContextFetch
8
+ Maintainer: lachy3433
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: contextfetch,markdown,web,web search
12
+ Requires-Python: <4.0,>=3.10
13
+ Requires-Dist: contextfetch>=0.1.0
14
+ Requires-Dist: llama-index-core<0.15,>=0.13.0
15
+ Description-Content-Type: text/markdown
16
+
17
+ # LlamaIndex Readers Integration: ContextFetch
18
+
19
+ ```bash
20
+ pip install llama-index-readers-contextfetch
21
+ ```
22
+
23
+ The ContextFetch reader loads web pages as LlamaIndex Documents with the page's
24
+ Markdown as text, using the [ContextFetch](https://contextfetch.dev) API. Give it
25
+ URLs, a web search query, or both.
26
+
27
+ Pass `api_key`, or set the `CONTEXTFETCH_API_KEY` environment variable. With
28
+ neither, requests use ContextFetch's keyless tier, a small daily allowance per IP.
29
+ The `contextfetch` package can request a free starter key:
30
+ `from contextfetch import ContextFetch; ContextFetch().free_key()`.
31
+
32
+ ## Usage
33
+
34
+ ```python
35
+ from llama_index.core import VectorStoreIndex
36
+ from llama_index.readers.contextfetch import ContextFetchReader
37
+
38
+ reader = ContextFetchReader() # or ContextFetchReader(api_key="...")
39
+
40
+ # Pages by URL
41
+ documents = reader.load_data(
42
+ urls=["https://docs.python.org/3/library/asyncio-task.html"]
43
+ )
44
+
45
+ # The pages a web search finds
46
+ documents = reader.load_data(query="asyncio task groups", num_results=5)
47
+
48
+ index = VectorStoreIndex.from_documents(documents)
49
+ ```
50
+
51
+ Each Document has `id_` set to its URL and metadata `url`, `title` and, when the
52
+ page provides them, `published_date` and `author`. A URL that fails to load is
53
+ skipped and logged as a warning.
54
+
55
+ This loader is designed to be used as a way to load data into [LlamaIndex](https://github.com/run-llama/llama_index/).
56
+ For an agent tool, see `llama-index-tools-contextfetch`.
@@ -0,0 +1,40 @@
1
+ # LlamaIndex Readers Integration: ContextFetch
2
+
3
+ ```bash
4
+ pip install llama-index-readers-contextfetch
5
+ ```
6
+
7
+ The ContextFetch reader loads web pages as LlamaIndex Documents with the page's
8
+ Markdown as text, using the [ContextFetch](https://contextfetch.dev) API. Give it
9
+ URLs, a web search query, or both.
10
+
11
+ Pass `api_key`, or set the `CONTEXTFETCH_API_KEY` environment variable. With
12
+ neither, requests use ContextFetch's keyless tier, a small daily allowance per IP.
13
+ The `contextfetch` package can request a free starter key:
14
+ `from contextfetch import ContextFetch; ContextFetch().free_key()`.
15
+
16
+ ## Usage
17
+
18
+ ```python
19
+ from llama_index.core import VectorStoreIndex
20
+ from llama_index.readers.contextfetch import ContextFetchReader
21
+
22
+ reader = ContextFetchReader() # or ContextFetchReader(api_key="...")
23
+
24
+ # Pages by URL
25
+ documents = reader.load_data(
26
+ urls=["https://docs.python.org/3/library/asyncio-task.html"]
27
+ )
28
+
29
+ # The pages a web search finds
30
+ documents = reader.load_data(query="asyncio task groups", num_results=5)
31
+
32
+ index = VectorStoreIndex.from_documents(documents)
33
+ ```
34
+
35
+ Each Document has `id_` set to its URL and metadata `url`, `title` and, when the
36
+ page provides them, `published_date` and `author`. A URL that fails to load is
37
+ skipped and logged as a warning.
38
+
39
+ This loader is designed to be used as a way to load data into [LlamaIndex](https://github.com/run-llama/llama_index/).
40
+ For an agent tool, see `llama-index-tools-contextfetch`.
@@ -0,0 +1,3 @@
1
+ from llama_index.readers.contextfetch.base import ContextFetchReader
2
+
3
+ __all__ = ["ContextFetchReader"]
@@ -0,0 +1,91 @@
1
+ """ContextFetch reader."""
2
+
3
+ import logging
4
+ from typing import List, Optional
5
+
6
+ from contextfetch import ContextFetch, Result
7
+ from llama_index.core.readers.base import BaseReader
8
+ from llama_index.core.schema import Document
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+ # POST /v1/contents accepts at most this many URLs per call.
13
+ MAX_URLS_PER_CALL = 10
14
+
15
+
16
+ class ContextFetchReader(BaseReader):
17
+ """
18
+ Load web pages, or the pages a web search finds, as Markdown Documents.
19
+
20
+ Args:
21
+ api_key: ContextFetch API key. Defaults to the CONTEXTFETCH_API_KEY
22
+ environment variable; with neither, requests use the keyless tier.
23
+
24
+ Example:
25
+ .. code-block:: python
26
+
27
+ from llama_index.readers.contextfetch import ContextFetchReader
28
+
29
+ reader = ContextFetchReader()
30
+ documents = reader.load_data(
31
+ urls=["https://docs.python.org/3/library/asyncio-task.html"]
32
+ )
33
+ documents = reader.load_data(query="asyncio task groups", num_results=5)
34
+
35
+ """
36
+
37
+ def __init__(self, api_key: Optional[str] = None) -> None:
38
+ """Initialize with parameters."""
39
+ self.client = ContextFetch(api_key=api_key)
40
+
41
+ def load_data(
42
+ self,
43
+ urls: Optional[List[str]] = None,
44
+ query: Optional[str] = None,
45
+ num_results: Optional[int] = None,
46
+ ) -> List[Document]:
47
+ """
48
+ Load pages as Documents, one per page, with the page's Markdown as text.
49
+
50
+ Args:
51
+ urls: Pages to load. A URL that fails to load is skipped with a warning.
52
+ query: A web search; the pages it finds are loaded.
53
+ num_results: How many search results to load (the API default is 10).
54
+
55
+ Returns:
56
+ Documents with id_ set to the URL and metadata url, title and, when
57
+ known, published_date and author.
58
+
59
+ """
60
+ if not urls and not query:
61
+ raise ValueError("Pass urls, query, or both.")
62
+ urls = urls or []
63
+ results: List[Result] = []
64
+ for i in range(0, len(urls), MAX_URLS_PER_CALL):
65
+ contents = self.client.contents(urls[i : i + MAX_URLS_PER_CALL])
66
+ results += contents.get("results", [])
67
+ for status in contents.get("statuses", []):
68
+ if status.get("status") == "error":
69
+ logger.warning(
70
+ "ContextFetch could not load %s: %s",
71
+ status.get("id"),
72
+ status.get("error"),
73
+ )
74
+ if query:
75
+ search = self.client.search(query, num_results=num_results, text=True)
76
+ results += search.get("results", [])
77
+ return [_to_document(result) for result in results]
78
+
79
+
80
+ def _to_document(result: Result) -> Document:
81
+ metadata = {
82
+ "url": result.get("url"),
83
+ "title": result.get("title"),
84
+ "published_date": result.get("publishedDate"),
85
+ "author": result.get("author"),
86
+ }
87
+ return Document(
88
+ id_=result.get("url"),
89
+ text=result.get("text") or "",
90
+ metadata={k: v for k, v in metadata.items() if v is not None},
91
+ )
@@ -0,0 +1,73 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [dependency-groups]
6
+ dev = [
7
+ "black[jupyter]>=23.7.0,<=26.5.1",
8
+ "codespell[toml]>=v2.2.6",
9
+ "diff-cover>=9.2.0",
10
+ "ipython==8.10.0",
11
+ "jupyter>=1.0.0,<2",
12
+ "mypy==0.991",
13
+ "pre-commit==3.2.0",
14
+ "pylint==2.15.10",
15
+ "pytest",
16
+ "pytest-cov>=6.1.1",
17
+ "pytest-mock==3.11.1",
18
+ "ruff==0.11.11",
19
+ "types-Deprecated>=0.1.0",
20
+ "types-PyYAML>=6.0.12.12,<7",
21
+ "types-protobuf>=4.24.0.4,<5",
22
+ "types-redis==4.5.5.0",
23
+ "types-requests==2.28.11.8",
24
+ "types-setuptools==67.1.0.0",
25
+ ]
26
+
27
+ [project]
28
+ name = "llama-index-readers-contextfetch"
29
+ version = "0.1.0"
30
+ description = "llama-index readers contextfetch integration"
31
+ authors = [{name = "ContextFetch"}]
32
+ requires-python = ">=3.10,<4.0"
33
+ readme = "README.md"
34
+ license = "MIT"
35
+ maintainers = [{name = "lachy3433"}]
36
+ keywords = [
37
+ "contextfetch",
38
+ "markdown",
39
+ "web",
40
+ "web search",
41
+ ]
42
+ dependencies = [
43
+ "contextfetch>=0.1.0",
44
+ "llama-index-core>=0.13.0,<0.15",
45
+ ]
46
+
47
+ [project.urls]
48
+ Homepage = "https://contextfetch.dev"
49
+ Documentation = "https://contextfetch.dev/docs/reference"
50
+
51
+ [tool.codespell]
52
+ check-filenames = true
53
+ check-hidden = true
54
+ skip = "*.csv,*.html,*.json,*.jsonl,*.pdf,*.txt,*.ipynb"
55
+
56
+ [tool.hatch.build.targets.sdist]
57
+ include = ["llama_index/"]
58
+
59
+ [tool.hatch.build.targets.wheel]
60
+ include = ["llama_index/"]
61
+
62
+ [tool.llamahub]
63
+ contains_example = false
64
+ import_path = "llama_index.readers.contextfetch"
65
+
66
+ [tool.llamahub.class_authors]
67
+ ContextFetchReader = "lachy3433"
68
+
69
+ [tool.mypy]
70
+ disallow_untyped_defs = true
71
+ exclude = ["_static", "build", "examples", "notebooks", "venv"]
72
+ ignore_missing_imports = true
73
+ python_version = "3.8"