langchain-enconvert 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,9 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-08-27
4
+
5
+ ### Added
6
+
7
+ - Initial release. `EnconvertLoader` loads web pages (`urls=`) into clean-markdown Documents with a
8
+ `render_quality` score, or ingests a whole site (`ingest_url=`) into RAG-ready chunk Documents.
9
+ - Depends on `langchain-core` only; the API key is read from `api_key=` or `$ENCONVERT_API_KEY`.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 EnConvert
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,51 @@
1
+ Metadata-Version: 2.5
2
+ Name: langchain-enconvert
3
+ Version: 0.1.0
4
+ Summary: EnConvert document loader for LangChain: perceive URLs or ingest a whole site into Documents, every read scored.
5
+ Project-URL: Homepage, https://www.enconvert.com
6
+ Project-URL: Repository, https://github.com/enconvert/langchain-enconvert
7
+ Author-email: EnConvert <support@enconvert.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: document-loader,enconvert,ingest,langchain,markdown,rag,web
11
+ Requires-Python: >=3.9
12
+ Requires-Dist: enconvert>=0.1
13
+ Requires-Dist: langchain-core>=0.3
14
+ Requires-Dist: requests>=2.28
15
+ Description-Content-Type: text/markdown
16
+
17
+ # EnConvert loader for LangChain
18
+
19
+ `langchain-enconvert` turns web pages and whole sites into LangChain `Document`s through
20
+ [EnConvert](https://www.enconvert.com). Every perceived page carries a `render_quality` score (0.0-1.0)
21
+ in its metadata, so a blocked or empty page comes back flagged rather than trusted.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install langchain-enconvert
27
+ ```
28
+
29
+ ## Use
30
+
31
+ ```python
32
+ from langchain_enconvert import EnconvertLoader
33
+
34
+ # A few URLs into clean-markdown Documents:
35
+ docs = EnconvertLoader(urls=["https://example.com", "https://example.com/pricing"]).load()
36
+
37
+ # Or a whole site into RAG-ready chunk Documents:
38
+ docs = EnconvertLoader(ingest_url="https://docs.example.com", mode="sitemap", max_pages=100).load()
39
+ ```
40
+
41
+ - **URLs** are perceived into markdown; metadata carries `source` and `render_quality`.
42
+ - **`ingest_url`** crawls the site (async; the loader polls to completion), then returns one Document per
43
+ chunk, each carrying the chunk's own metadata (`source`, title, etc.).
44
+ - `.lazy_load()` streams Documents one at a time.
45
+
46
+ Auth: a **private** key (`sk_...`) from your [dashboard](https://www.enconvert.com/dashboard/api-keys).
47
+ Public `pk_` keys are rejected. The key is read from `api_key=` or `$ENCONVERT_API_KEY`.
48
+
49
+ ## Licence
50
+
51
+ [MIT](LICENSE)
@@ -0,0 +1,35 @@
1
+ # EnConvert loader for LangChain
2
+
3
+ `langchain-enconvert` turns web pages and whole sites into LangChain `Document`s through
4
+ [EnConvert](https://www.enconvert.com). Every perceived page carries a `render_quality` score (0.0-1.0)
5
+ in its metadata, so a blocked or empty page comes back flagged rather than trusted.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install langchain-enconvert
11
+ ```
12
+
13
+ ## Use
14
+
15
+ ```python
16
+ from langchain_enconvert import EnconvertLoader
17
+
18
+ # A few URLs into clean-markdown Documents:
19
+ docs = EnconvertLoader(urls=["https://example.com", "https://example.com/pricing"]).load()
20
+
21
+ # Or a whole site into RAG-ready chunk Documents:
22
+ docs = EnconvertLoader(ingest_url="https://docs.example.com", mode="sitemap", max_pages=100).load()
23
+ ```
24
+
25
+ - **URLs** are perceived into markdown; metadata carries `source` and `render_quality`.
26
+ - **`ingest_url`** crawls the site (async; the loader polls to completion), then returns one Document per
27
+ chunk, each carrying the chunk's own metadata (`source`, title, etc.).
28
+ - `.lazy_load()` streams Documents one at a time.
29
+
30
+ Auth: a **private** key (`sk_...`) from your [dashboard](https://www.enconvert.com/dashboard/api-keys).
31
+ Public `pk_` keys are rejected. The key is read from `api_key=` or `$ENCONVERT_API_KEY`.
32
+
33
+ ## Licence
34
+
35
+ [MIT](LICENSE)
@@ -0,0 +1,3 @@
1
+ from langchain_enconvert.document_loaders import EnconvertLoader
2
+
3
+ __all__ = ["EnconvertLoader"]
@@ -0,0 +1,113 @@
1
+ """EnConvert document loader for LangChain."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ import time
8
+ from typing import Iterator, List, Optional
9
+
10
+ import requests
11
+ from enconvert import Enconvert
12
+ from langchain_core.document_loaders import BaseLoader
13
+ from langchain_core.documents import Document
14
+
15
+
16
+ class EnconvertLoader(BaseLoader):
17
+ """Load web pages or a whole site into LangChain Documents via EnConvert.
18
+
19
+ Pass ``urls=`` to perceive pages into clean-markdown Documents (each carrying
20
+ a ``render_quality`` score), or ``ingest_url=`` to crawl a site into
21
+ RAG-ready chunk Documents.
22
+ """
23
+
24
+ def __init__(
25
+ self,
26
+ urls: Optional[List[str]] = None,
27
+ *,
28
+ ingest_url: Optional[str] = None,
29
+ mode: str = "sitemap",
30
+ max_pages: int = 50,
31
+ api_key: Optional[str] = None,
32
+ base_url: str = "https://api.enconvert.com",
33
+ poll_interval: float = 5.0,
34
+ ) -> None:
35
+ self.urls = urls
36
+ self.ingest_url = ingest_url
37
+ self.mode = mode
38
+ self.max_pages = max_pages
39
+ self.base_url = base_url
40
+ self.poll_interval = poll_interval
41
+ self._api_key = api_key or os.environ.get("ENCONVERT_API_KEY", "")
42
+
43
+ def lazy_load(self) -> Iterator[Document]:
44
+ if not self._api_key:
45
+ raise ValueError(
46
+ "EnConvert api_key is missing. Pass api_key= or set $ENCONVERT_API_KEY "
47
+ "(a private key starting with sk_)."
48
+ )
49
+ client = Enconvert(api_key=self._api_key, base_url=self.base_url)
50
+ if self.urls:
51
+ for url in self.urls:
52
+ op = client.v2.perceive_direct(url, outputs=["markdown"])
53
+ yield Document(
54
+ page_content=op.content.decode("utf-8", "replace"),
55
+ metadata={"source": url, "render_quality": op.render_quality},
56
+ )
57
+ elif self.ingest_url:
58
+ yield from _ingest(
59
+ client, self.ingest_url, self.mode, self.max_pages, self.poll_interval
60
+ )
61
+ else:
62
+ raise ValueError("Provide urls=[...] or ingest_url=...")
63
+
64
+
65
+ def _ingest(
66
+ client: Enconvert,
67
+ url: str,
68
+ mode: str,
69
+ max_pages: int,
70
+ poll_interval: float,
71
+ ) -> Iterator[Document]:
72
+ job = client.v2.ingest(mode=mode, url=url, max_pages=max_pages)
73
+ while True:
74
+ status = client.v2.get_ingest_job(job.job_id)
75
+ if status.status in ("completed", "failed", "cancelled"):
76
+ break
77
+ time.sleep(poll_interval)
78
+ if status.status != "completed":
79
+ raise RuntimeError(f"EnConvert ingest job {job.job_id} ended: {status.status}")
80
+ resp = requests.get(status.output_url, timeout=120)
81
+ resp.raise_for_status()
82
+ yield from _chunks_to_documents(resp.text)
83
+
84
+
85
+ def _chunks_to_documents(jsonl_text: str) -> Iterator[Document]:
86
+ """Map an EnConvert ingest JSONL (one chunk per line) to LangChain Documents.
87
+
88
+ Schema-agnostic: text comes from ``content`` (or ``text``); the rest becomes
89
+ metadata, with ``source`` set from the chunk's URL for LangChain provenance.
90
+ """
91
+ for line in jsonl_text.splitlines():
92
+ line = line.strip()
93
+ if not line:
94
+ continue
95
+ chunk = json.loads(line)
96
+ text = chunk.pop("content", None) or chunk.pop("text", "")
97
+ src = chunk.get("source_url") or chunk.get("url")
98
+ if src and "source" not in chunk:
99
+ chunk["source"] = src
100
+ yield Document(page_content=text, metadata=chunk)
101
+
102
+
103
+ if __name__ == "__main__":
104
+ sample = (
105
+ '{"content": "hello", "source_url": "https://x.com", "chunk_index": 0}\n'
106
+ "\n"
107
+ '{"text": "world", "title": "W"}'
108
+ )
109
+ out = list(_chunks_to_documents(sample))
110
+ assert len(out) == 2, out
111
+ assert out[0].page_content == "hello" and out[0].metadata["source"] == "https://x.com"
112
+ assert out[1].page_content == "world" and out[1].metadata["title"] == "W"
113
+ print("ok")
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "langchain-enconvert"
7
+ version = "0.1.0"
8
+ description = "EnConvert document loader for LangChain: perceive URLs or ingest a whole site into Documents, every read scored."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.9"
12
+ authors = [{ name = "EnConvert", email = "support@enconvert.com" }]
13
+ keywords = ["langchain", "enconvert", "rag", "document-loader", "markdown", "web", "ingest"]
14
+ dependencies = [
15
+ "langchain-core>=0.3",
16
+ "enconvert>=0.1",
17
+ "requests>=2.28",
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://www.enconvert.com"
22
+ Repository = "https://github.com/enconvert/langchain-enconvert"
23
+
24
+ [tool.hatch.build.targets.wheel]
25
+ packages = ["langchain_enconvert"]