langchain-gluedly 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,8 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .pytest_cache/
4
+ *.egg-info/
5
+ .venv/
6
+ dist/
7
+ build/
8
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Donatas Petrikauskas
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,54 @@
1
+ Metadata-Version: 2.5
2
+ Name: langchain-gluedly
3
+ Version: 0.1.0
4
+ Summary: LangChain document loader for Gluedly scrape snapshots
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: langchain-core>=0.3.0
9
+ Requires-Dist: requests>=2.31.0
10
+ Provides-Extra: dev
11
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
12
+ Requires-Dist: responses>=0.25.0; extra == 'dev'
13
+ Description-Content-Type: text/markdown
14
+
15
+ # langchain-gluedly
16
+
17
+ LangChain `BaseLoader` that turns Gluedly scrape snapshots into `Document` objects.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pip install -e ".[dev]"
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```python
28
+ from langchain_gluedly import GluedlyLoader
29
+
30
+ loader = GluedlyLoader(
31
+ api_key="YOUR_GLUEDLY_API_KEY",
32
+ page_id=12,
33
+ # snapshot_id=100, # optional; omit to use the latest snapshot
34
+ # base_url="https://gluedly.com/api/v1",
35
+ )
36
+ documents = loader.load()
37
+ ```
38
+
39
+ Each row becomes one document. Content preference: `markdown` → `summary` → `description` → `str(row)`.
40
+
41
+ ## Example
42
+
43
+ ```bash
44
+ export GLUEDLY_API_KEY=…
45
+ export GLUEDLY_PAGE_ID=12
46
+ python examples/load_documents.py
47
+ ```
48
+
49
+ ## Tests
50
+
51
+ ```bash
52
+ pip install -e ".[dev]"
53
+ pytest
54
+ ```
@@ -0,0 +1,40 @@
1
+ # langchain-gluedly
2
+
3
+ LangChain `BaseLoader` that turns Gluedly scrape snapshots into `Document` objects.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install -e ".[dev]"
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ from langchain_gluedly import GluedlyLoader
15
+
16
+ loader = GluedlyLoader(
17
+ api_key="YOUR_GLUEDLY_API_KEY",
18
+ page_id=12,
19
+ # snapshot_id=100, # optional; omit to use the latest snapshot
20
+ # base_url="https://gluedly.com/api/v1",
21
+ )
22
+ documents = loader.load()
23
+ ```
24
+
25
+ Each row becomes one document. Content preference: `markdown` → `summary` → `description` → `str(row)`.
26
+
27
+ ## Example
28
+
29
+ ```bash
30
+ export GLUEDLY_API_KEY=…
31
+ export GLUEDLY_PAGE_ID=12
32
+ python examples/load_documents.py
33
+ ```
34
+
35
+ ## Tests
36
+
37
+ ```bash
38
+ pip install -e ".[dev]"
39
+ pytest
40
+ ```
@@ -0,0 +1,30 @@
1
+ """Example: load Gluedly snapshot rows into LangChain Documents."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+
7
+ from langchain_gluedly import GluedlyLoader
8
+
9
+
10
+ def main() -> None:
11
+ api_key = os.environ["GLUEDLY_API_KEY"]
12
+ page_id = int(os.environ.get("GLUEDLY_PAGE_ID", "12"))
13
+ base_url = os.environ.get("GLUEDLY_BASE_URL", "https://gluedly.com/api/v1")
14
+
15
+ loader = GluedlyLoader(
16
+ api_key=api_key,
17
+ page_id=page_id,
18
+ base_url=base_url,
19
+ )
20
+ documents = loader.load()
21
+
22
+ print(f"Loaded {len(documents)} documents from page {page_id}")
23
+ for doc in documents[:3]:
24
+ print("---")
25
+ print(doc.metadata)
26
+ print(doc.page_content[:400])
27
+
28
+
29
+ if __name__ == "__main__":
30
+ main()
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "langchain-gluedly"
7
+ version = "0.1.0"
8
+ description = "LangChain document loader for Gluedly scrape snapshots"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ dependencies = [
14
+ "langchain-core>=0.3.0",
15
+ "requests>=2.31.0",
16
+ ]
17
+
18
+ [project.optional-dependencies]
19
+ dev = [
20
+ "pytest>=8.0.0",
21
+ "responses>=0.25.0",
22
+ ]
23
+
24
+ [tool.hatch.build.targets.wheel]
25
+ packages = ["src/langchain_gluedly"]
26
+
27
+ [tool.pytest.ini_options]
28
+ pythonpath = ["src"]
29
+ testpaths = ["tests"]
@@ -0,0 +1,5 @@
1
+ """LangChain integrations for Gluedly."""
2
+
3
+ from langchain_gluedly.loader import GluedlyLoader
4
+
5
+ __all__ = ["GluedlyLoader"]
@@ -0,0 +1,82 @@
1
+ """Load web data snapshots from Gluedly into LangChain Document objects."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, List, Optional
6
+
7
+ import requests
8
+ from langchain_core.document_loaders import BaseLoader
9
+ from langchain_core.documents import Document
10
+
11
+ DEFAULT_BASE_URL = "https://gluedly.com/api/v1"
12
+
13
+
14
+ class GluedlyLoader(BaseLoader):
15
+ """Load web data snapshots from Gluedly into LangChain Document objects."""
16
+
17
+ def __init__(
18
+ self,
19
+ api_key: str,
20
+ page_id: int,
21
+ snapshot_id: Optional[int] = None,
22
+ base_url: str = DEFAULT_BASE_URL,
23
+ session: Optional[requests.Session] = None,
24
+ timeout: float = 30,
25
+ ) -> None:
26
+ if not api_key:
27
+ raise ValueError("api_key is required")
28
+
29
+ self.api_key = api_key
30
+ self.page_id = page_id
31
+ self.snapshot_id = snapshot_id
32
+ self.base_url = base_url.rstrip("/")
33
+ self.headers = {"Authorization": f"Bearer {self.api_key}"}
34
+ self.session = session or requests.Session()
35
+ self.timeout = timeout
36
+
37
+ def load(self) -> List[Document]:
38
+ target_snapshot_id = self.snapshot_id
39
+ if not target_snapshot_id:
40
+ res = self.session.get(
41
+ f"{self.base_url}/pages/{self.page_id}/data",
42
+ headers=self.headers,
43
+ timeout=self.timeout,
44
+ )
45
+ res.raise_for_status()
46
+ snapshots = res.json().get("data", [])
47
+ if not snapshots:
48
+ return []
49
+ target_snapshot_id = int(snapshots[0]["id"])
50
+
51
+ payload_res = self.session.get(
52
+ f"{self.base_url}/pages/{self.page_id}/data/{target_snapshot_id}",
53
+ headers=self.headers,
54
+ timeout=self.timeout,
55
+ )
56
+ payload_res.raise_for_status()
57
+ payload: dict[str, Any] = payload_res.json()
58
+
59
+ documents: List[Document] = []
60
+ rows = payload.get("data", {}).get("rows", [])
61
+ for idx, row in enumerate(rows):
62
+ if not isinstance(row, dict):
63
+ page_content = str(row)
64
+ source = f"page_{self.page_id}"
65
+ else:
66
+ page_content = (
67
+ row.get("markdown")
68
+ or row.get("summary")
69
+ or row.get("description")
70
+ or str(row)
71
+ )
72
+ source = row.get("url") or f"page_{self.page_id}"
73
+
74
+ metadata = {
75
+ "source": source,
76
+ "page_id": self.page_id,
77
+ "snapshot_id": target_snapshot_id,
78
+ "row_index": idx,
79
+ }
80
+ documents.append(Document(page_content=str(page_content), metadata=metadata))
81
+
82
+ return documents
@@ -0,0 +1,94 @@
1
+ from __future__ import annotations
2
+
3
+ import responses
4
+
5
+ from langchain_gluedly import GluedlyLoader
6
+
7
+ BASE = "https://gluedly.com/api/v1"
8
+
9
+
10
+ @responses.activate
11
+ def test_load_resolves_latest_snapshot_and_maps_rows() -> None:
12
+ responses.add(
13
+ responses.GET,
14
+ f"{BASE}/pages/12/data",
15
+ json={"data": [{"id": 100}, {"id": 99}]},
16
+ status=200,
17
+ )
18
+ responses.add(
19
+ responses.GET,
20
+ f"{BASE}/pages/12/data/100",
21
+ json={
22
+ "id": 100,
23
+ "page_id": 12,
24
+ "data": {
25
+ "ok": True,
26
+ "rows": [
27
+ {
28
+ "url": "https://example.com/a",
29
+ "markdown": "# Product A",
30
+ "summary": "ignored when markdown present",
31
+ },
32
+ {
33
+ "url": "https://example.com/b",
34
+ "summary": "Summary only",
35
+ },
36
+ ],
37
+ "match_counts": {},
38
+ "warnings": [],
39
+ },
40
+ },
41
+ status=200,
42
+ )
43
+
44
+ docs = GluedlyLoader(api_key="test-key", page_id=12).load()
45
+
46
+ assert len(docs) == 2
47
+ assert docs[0].page_content == "# Product A"
48
+ assert docs[0].metadata == {
49
+ "source": "https://example.com/a",
50
+ "page_id": 12,
51
+ "snapshot_id": 100,
52
+ "row_index": 0,
53
+ }
54
+ assert docs[1].page_content == "Summary only"
55
+ assert docs[1].metadata["row_index"] == 1
56
+
57
+
58
+ @responses.activate
59
+ def test_load_returns_empty_when_no_snapshots() -> None:
60
+ responses.add(
61
+ responses.GET,
62
+ f"{BASE}/pages/12/data",
63
+ json={"data": []},
64
+ status=200,
65
+ )
66
+
67
+ docs = GluedlyLoader(api_key="test-key", page_id=12).load()
68
+ assert docs == []
69
+
70
+
71
+ @responses.activate
72
+ def test_load_uses_explicit_snapshot_id() -> None:
73
+ responses.add(
74
+ responses.GET,
75
+ f"{BASE}/pages/12/data/55",
76
+ json={
77
+ "id": 55,
78
+ "page_id": 12,
79
+ "data": {
80
+ "ok": True,
81
+ "rows": [{"description": "From description"}],
82
+ "match_counts": {},
83
+ "warnings": [],
84
+ },
85
+ },
86
+ status=200,
87
+ )
88
+
89
+ docs = GluedlyLoader(api_key="test-key", page_id=12, snapshot_id=55).load()
90
+
91
+ assert len(docs) == 1
92
+ assert docs[0].page_content == "From description"
93
+ assert docs[0].metadata["snapshot_id"] == 55
94
+ assert len(responses.calls) == 1