langchain-olostep 0.2.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,25 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Olostep
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.
22
+
23
+
24
+
25
+
@@ -0,0 +1,11 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ recursive-include langchain_olostep *.py
5
+ recursive-include tests *.py
6
+ global-exclude *.pyc
7
+ global-exclude __pycache__
8
+
9
+
10
+
11
+
@@ -0,0 +1,503 @@
1
+ Metadata-Version: 2.4
2
+ Name: langchain-olostep
3
+ Version: 0.2.0
4
+ Summary: LangChain/LangGraph integration for Olostep - Powerful web scraping tools for AI agents
5
+ Home-page: https://github.com/olostep/langchain-olostep
6
+ Author: Olostep
7
+ Author-email: Olostep <support@olostep.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/olostep/langchain-olostep
10
+ Project-URL: Repository, https://github.com/olostep/langchain-olostep
11
+ Project-URL: Documentation, https://docs.olostep.com/integrations/langchain
12
+ Project-URL: Issues, https://github.com/olostep/langchain-olostep/issues
13
+ Keywords: langchain,web-scraping,olostep,ai,llm
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
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: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
25
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
26
+ Requires-Python: >=3.9
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: langchain-core>=0.3.0
30
+ Requires-Dist: requests>=2.31.0
31
+ Requires-Dist: pydantic>=2.0.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
34
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
35
+ Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
36
+ Requires-Dist: black>=23.0.0; extra == "dev"
37
+ Requires-Dist: isort>=5.12.0; extra == "dev"
38
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
39
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
40
+ Provides-Extra: test
41
+ Requires-Dist: pytest>=7.0.0; extra == "test"
42
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
43
+ Requires-Dist: pytest-mock>=3.10.0; extra == "test"
44
+ Requires-Dist: httpx>=0.24.0; extra == "test"
45
+ Dynamic: author
46
+ Dynamic: home-page
47
+ Dynamic: license-file
48
+ Dynamic: requires-python
49
+
50
+ # LangChain Olostep Integration
51
+
52
+ A powerful LangChain/LangGraph integration for the Olostep web scraping API. Build intelligent agents that can scrape, analyze, and extract data from any website.
53
+
54
+ ## Features
55
+
56
+ - **Web Scraping**: Extract content from any website with JavaScript rendering support
57
+ - **Batch Processing**: Scrape up to 100,000 URLs in parallel
58
+ - **AI-Powered Q&A**: Ask questions about websites and get intelligent answers
59
+ - **Data Extraction**: Extract specific fields using AI-powered mapping
60
+ - **Multiple Formats**: Support for Markdown, HTML, JSON, and plain text
61
+ - **Specialized Parsers**: Use custom parsers for specific websites (e.g., Amazon, LinkedIn)
62
+ - **Location-Specific**: Scrape with country-specific settings
63
+ - **LangGraph Ready**: Perfect for building complex AI agent workflows
64
+
65
+ ## Installation
66
+
67
+ ```bash
68
+ pip install langchain-olostep
69
+ ```
70
+
71
+ ## Setup
72
+
73
+ Set your Olostep API key:
74
+
75
+ ```bash
76
+ export OLOSTEP_API_KEY="your_olostep_api_key_here"
77
+ ```
78
+
79
+ Get your API key from https://olostep.com/dashboard
80
+
81
+ ## Quick Start
82
+
83
+ ### Basic Web Scraping
84
+
85
+ ```python
86
+ from langchain_olostep import scrape_website
87
+ import asyncio
88
+
89
+ # Scrape a website
90
+ content = asyncio.run(scrape_website.ainvoke({
91
+ "url": "https://example.com",
92
+ "format": "markdown"
93
+ }))
94
+
95
+ print(content)
96
+ ```
97
+
98
+ ### With LangChain Agent
99
+
100
+ ```python
101
+ from langchain.agents import initialize_agent, AgentType
102
+ from langchain_openai import ChatOpenAI
103
+ from langchain_olostep import scrape_website, scrape_with_answer
104
+
105
+ # Create agent with Olostep tools
106
+ tools = [scrape_website, scrape_with_answer]
107
+ llm = ChatOpenAI(model="gpt-4o-mini")
108
+
109
+ agent = initialize_agent(
110
+ tools=tools,
111
+ llm=llm,
112
+ agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
113
+ verbose=True
114
+ )
115
+
116
+ # Use the agent
117
+ result = agent.run("""
118
+ Scrape https://example.com and tell me:
119
+ 1. What is the main content about?
120
+ 2. Extract any contact information
121
+ """)
122
+
123
+ print(result)
124
+ ```
125
+
126
+ ### With LangGraph
127
+
128
+ ```python
129
+ from langgraph.graph import StateGraph
130
+ from langchain_olostep import scrape_website, scrape_batch
131
+ from langchain_openai import ChatOpenAI
132
+
133
+ # Build a research agent workflow
134
+ workflow = StateGraph(dict)
135
+
136
+ def scrape_node(state):
137
+ urls = state["urls"]
138
+ result = scrape_batch.invoke({"urls": urls})
139
+ return {"scraped_data": result}
140
+
141
+ workflow.add_node("scrape", scrape_node)
142
+ # ... add more nodes
143
+ ```
144
+
145
+ ## Available Tools
146
+
147
+ ### 1. scrape_website
148
+
149
+ Scrape content from any website.
150
+
151
+ ```python
152
+ from langchain_olostep import scrape_website
153
+
154
+ result = await scrape_website.ainvoke({
155
+ "url": "https://example.com",
156
+ "format": "markdown", # markdown, html, json, or text
157
+ "country": "US", # Optional: country code for location-specific content
158
+ "wait_before_scraping": 2000, # Optional: wait time in ms for JS rendering
159
+ "parser": "@olostep/amazon-product" # Optional: specialized parser
160
+ })
161
+ ```
162
+
163
+ **Perfect for:**
164
+ - Extracting article content
165
+ - Scraping dynamic websites
166
+ - Bypassing anti-scraping measures
167
+ - Getting clean, formatted content
168
+
169
+ ### 2. scrape_batch
170
+
171
+ Scrape multiple URLs in parallel.
172
+
173
+ ```python
174
+ from langchain_olostep import scrape_batch
175
+
176
+ urls = [
177
+ "https://example1.com",
178
+ "https://example2.com",
179
+ "https://example3.com"
180
+ ]
181
+
182
+ result = await scrape_batch.ainvoke({
183
+ "urls": urls,
184
+ "format": "markdown"
185
+ })
186
+ ```
187
+
188
+ **Perfect for:**
189
+ - Competitive analysis
190
+ - Large-scale data collection
191
+ - Building datasets
192
+ - Monitoring multiple sources
193
+
194
+ ### 3. scrape_with_answer
195
+
196
+ Ask questions about website content and get AI-powered answers.
197
+
198
+ ```python
199
+ from langchain_olostep import scrape_with_answer
200
+
201
+ result = await scrape_with_answer.ainvoke({
202
+ "url": "https://company.com",
203
+ "question": "What is the company's main product and its pricing?"
204
+ })
205
+ ```
206
+
207
+ **Perfect for:**
208
+ - Research and information extraction
209
+ - Competitive intelligence
210
+ - Lead generation
211
+ - Content analysis
212
+
213
+ ### 4. scrape_with_map
214
+
215
+ Extract specific fields using AI-powered mapping.
216
+
217
+ ```python
218
+ from langchain_olostep import scrape_with_map
219
+
220
+ result = await scrape_with_map.ainvoke({
221
+ "url": "https://store.com/product/123",
222
+ "fields": ["product_name", "price", "rating", "description"]
223
+ })
224
+ ```
225
+
226
+ **Perfect for:**
227
+ - Structured data extraction
228
+ - Product information gathering
229
+ - Contact details extraction
230
+ - E-commerce data collection
231
+
232
+ ## Examples
233
+
234
+ ### Example 1: Research Agent
235
+
236
+ ```python
237
+ from langchain_olostep import scrape_website, scrape_with_answer
238
+ from langchain.agents import initialize_agent
239
+ from langchain_openai import ChatOpenAI
240
+
241
+ tools = [scrape_website, scrape_with_answer]
242
+ llm = ChatOpenAI(model="gpt-4o-mini")
243
+
244
+ agent = initialize_agent(
245
+ tools=tools,
246
+ llm=llm,
247
+ agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION
248
+ )
249
+
250
+ # Research a topic
251
+ result = agent.run("""
252
+ Research the latest developments in AI by:
253
+ 1. Scraping https://openai.com/blog
254
+ 2. Extracting key announcements
255
+ 3. Summarizing the findings
256
+ """)
257
+ ```
258
+
259
+ ### Example 2: Competitive Analysis
260
+
261
+ ```python
262
+ from langchain_olostep import scrape_batch, scrape_with_map
263
+
264
+ # Scrape competitor websites
265
+ competitors = [
266
+ "https://competitor1.com/pricing",
267
+ "https://competitor2.com/pricing",
268
+ "https://competitor3.com/pricing"
269
+ ]
270
+
271
+ batch_result = await scrape_batch.ainvoke({"urls": competitors})
272
+
273
+ # Extract pricing information
274
+ for url in competitors:
275
+ pricing = await scrape_with_map.ainvoke({
276
+ "url": url,
277
+ "fields": ["pricing_tiers", "features", "prices"]
278
+ })
279
+ print(f"Competitor: {url}")
280
+ print(f"Pricing: {pricing}")
281
+ ```
282
+
283
+ ### Example 3: Content Monitoring
284
+
285
+ ```python
286
+ from langchain_olostep import scrape_website
287
+ import schedule
288
+ import time
289
+
290
+ def monitor_website():
291
+ content = await scrape_website.ainvoke({
292
+ "url": "https://important-site.com",
293
+ "format": "markdown"
294
+ })
295
+
296
+ # Check for changes, send alerts, etc.
297
+ # ... your logic here
298
+
299
+ # Run every hour
300
+ schedule.every().hour.do(monitor_website)
301
+
302
+ while True:
303
+ schedule.run_pending()
304
+ time.sleep(1)
305
+ ```
306
+
307
+ ### Example 4: LangGraph Research Workflow
308
+
309
+ See the complete example in the examples directory.
310
+
311
+ ```python
312
+ from langgraph.graph import StateGraph, END
313
+ from langchain_olostep import scrape_website, scrape_with_answer
314
+
315
+ # Define your research workflow
316
+ workflow = StateGraph(dict)
317
+
318
+ # Add nodes for different stages
319
+ workflow.add_node("plan", plan_research)
320
+ workflow.add_node("scrape", scrape_content)
321
+ workflow.add_node("analyze", analyze_data)
322
+ workflow.add_node("report", generate_report)
323
+
324
+ # Connect the nodes
325
+ workflow.set_entry_point("plan")
326
+ workflow.add_edge("plan", "scrape")
327
+ workflow.add_edge("scrape", "analyze")
328
+ workflow.add_edge("analyze", "report")
329
+ workflow.add_edge("report", END)
330
+
331
+ # Compile and run
332
+ agent = workflow.compile()
333
+ result = agent.invoke({"query": "Research AI developments"})
334
+ ```
335
+
336
+ ## Advanced Features
337
+
338
+ ### JavaScript Rendering
339
+
340
+ Handle dynamic websites that load content via JavaScript:
341
+
342
+ ```python
343
+ result = await scrape_website.ainvoke({
344
+ "url": "https://dynamic-site.com",
345
+ "wait_before_scraping": 3000 # Wait 3 seconds
346
+ })
347
+ ```
348
+
349
+ ### Location-Specific Scraping
350
+
351
+ Get content as it appears in different countries:
352
+
353
+ ```python
354
+ result = await scrape_website.ainvoke({
355
+ "url": "https://example.com",
356
+ "country": "GB" # Scrape as viewed from UK
357
+ })
358
+ ```
359
+
360
+ ### Specialized Parsers
361
+
362
+ Use pre-built parsers for specific websites:
363
+
364
+ ```python
365
+ # Amazon product parser
366
+ product = await scrape_website.ainvoke({
367
+ "url": "https://amazon.com/product/xyz",
368
+ "parser": "@olostep/amazon-product"
369
+ })
370
+
371
+ # LinkedIn profile parser
372
+ profile = await scrape_website.ainvoke({
373
+ "url": "https://linkedin.com/in/username",
374
+ "parser": "@olostep/linkedin-profile"
375
+ })
376
+ ```
377
+
378
+ ### Multiple Output Formats
379
+
380
+ Get content in different formats:
381
+
382
+ ```python
383
+ # Get markdown for readability
384
+ markdown = await scrape_website.ainvoke({
385
+ "url": "https://example.com",
386
+ "format": "markdown"
387
+ })
388
+
389
+ # Get JSON for structured data
390
+ json_data = await scrape_website.ainvoke({
391
+ "url": "https://example.com",
392
+ "format": "json"
393
+ })
394
+
395
+ # Get HTML for full page structure
396
+ html = await scrape_website.ainvoke({
397
+ "url": "https://example.com",
398
+ "format": "html"
399
+ })
400
+ ```
401
+
402
+ ## Configuration
403
+
404
+ ### Environment Variables
405
+
406
+ - `OLOSTEP_API_KEY`: Your Olostep API key (required)
407
+
408
+ ### Tool Parameters
409
+
410
+ All tools accept an optional `api_key` parameter:
411
+
412
+ ```python
413
+ result = await scrape_website.ainvoke({
414
+ "url": "https://example.com",
415
+ "api_key": "your_api_key_here" # Override environment variable
416
+ })
417
+ ```
418
+
419
+ ## Use Cases
420
+
421
+ ### Research & Analysis
422
+ - Market research
423
+ - Competitive intelligence
424
+ - Academic research
425
+ - News monitoring
426
+
427
+ ### Data Collection
428
+ - Building datasets
429
+ - Product information gathering
430
+ - Price monitoring
431
+ - Contact information extraction
432
+
433
+ ### AI Agents
434
+ - Research assistants
435
+ - Data extraction bots
436
+ - Content analyzers
437
+ - Web automation agents
438
+
439
+ ### Business Intelligence
440
+ - Competitor tracking
441
+ - Lead generation
442
+ - Market analysis
443
+ - Trend monitoring
444
+
445
+ ## Getting Started
446
+
447
+ 1. **Install the package**
448
+ ```bash
449
+ pip install langchain-olostep
450
+ ```
451
+
452
+ 2. **Get your API key**
453
+ - Sign up at olostep.com
454
+ - Get your API key from the dashboard
455
+
456
+ 3. **Set your API key**
457
+ ```bash
458
+ export OLOSTEP_API_KEY="your_key_here"
459
+ ```
460
+
461
+ 4. **Try the examples**
462
+ Check out the examples in the repository
463
+
464
+ ## Documentation
465
+
466
+ - Olostep API Documentation: https://docs.olostep.com
467
+ - LangChain Documentation: https://python.langchain.com
468
+ - LangGraph Documentation: https://langchain-ai.github.io/langgraph/
469
+
470
+ ## Contributing
471
+
472
+ Contributions are welcome! Please feel free to submit a Pull Request.
473
+
474
+ ## License
475
+
476
+ MIT License - see LICENSE file for details.
477
+
478
+ ## Support
479
+
480
+ - **Documentation**: docs.olostep.com
481
+ - **Issues**: GitHub Issues
482
+ - **Email**: support@olostep.com
483
+
484
+ ## Why Olostep?
485
+
486
+ - **Reliable**: Handle JavaScript rendering, anti-scraping measures, and dynamic content
487
+ - **Fast**: Parallel processing for batch operations
488
+ - **Accurate**: AI-powered extraction for precise data gathering
489
+ - **Flexible**: Multiple formats, parsers, and configuration options
490
+ - **Scalable**: From single URLs to 100,000+ URLs in batch
491
+
492
+ ## Changelog
493
+
494
+ ### 0.2.0
495
+ - Complete redesign focusing on Olostep's core features
496
+ - Added scrape_with_answer for AI-powered Q&A
497
+ - Added scrape_with_map for structured data extraction
498
+ - Removed confusing document loader terminology
499
+ - Improved tool descriptions and examples
500
+ - Added comprehensive LangGraph example
501
+
502
+ ### 0.1.0
503
+ - Initial release