Skip to main content

LangChain Thordata for Python

Connect Thordata SERP to Python applications and LangChain agents for real-time search.

This package exposes Thordata search capabilities through a Python client and a LangChain search tool. Version 1 targets Thordata's synchronous SERP endpoint, exposes search-result APIs only, and does not expose Web Scraper APIs or the google_webpage engine.

Installation

pip install langchain-thordata

For local development:

python -m pip install -e ".[test]"

Configuration

Set a ThorData SERP API key:

export THORDATA_API_KEY="your-api-key"

THORDATA_API_TOKEN is accepted as a compatibility alias. The default API URL is https://scraperapi.thordata.com/request; override it for development with THORDATA_SERP_API_URL.

Python client

from langchain_thordata import ThorDataClient

with ThorDataClient() as client:
    results = client.search(
        q="latest AI agent research",
        engine="google_search",
        gl="us",
        hl="en",
        num=10,
    )
    print(results)

The client reuses its HTTP connection pool until close() or aclose() is called. Prefer a synchronous or asynchronous context manager. It also provides await client.asearch(...) for asynchronous callers. The current /request endpoint does not guarantee HTML, so the client intentionally exposes JSON search methods only.

The client accepts every form parameter supported by /request. Pass API-native parameters either as keyword arguments or in the first mapping argument:

flights = client.search(
    {
        "departure_id": "SFO",
        "arrival_id": "JFK",
        "outbound_date": "2026-10-01",
        "return_date": "2026-10-08",
    },
    engine="google_flights",
)

In either form, the convenience names query, country, and language map to q, gl, and hl. Explicit API-native names such as q, gl, hl, and text are preserved. For Yandex, query or q is sent as text.

LangChain tool

from langchain_thordata import ThorDataSearchTool

tool = ThorDataSearchTool()
result = tool.invoke(
    {
        "query": "latest AI agent research",
        "engine": "google_news",
        "country": "us",
        "language": "en",
        "num": 5,
    }
)
print(result)

Specialized parameters are available to the tool through params:

result = tool.invoke(
    {
        "engine": "google_scholar_author",
        "params": {"author_id": "EicYvbwAAAAJ", "sort": "pubdate"},
    }
)

The tool can be passed directly to a LangChain agent:

from langchain.agents import create_agent
from langchain_thordata import ThorDataSearchTool

agent = create_agent(model, tools=[ThorDataSearchTool()])

The agent example requires the separate langchain package; the integration's runtime dependency stays limited to langchain-core.

Supported engines

  • Google search: google, google_light, google_web, google_images, google_videos, google_news, google_shopping, google_local, google_product, google_lens, google_trends, google_maps, google_hotels, google_jobs, and google_ai_mode.
  • Google verticals: google_scholar, google_scholar_cite, google_scholar_author, google_play, google_play_product, google_play_games, google_play_movies, google_play_books, google_finance, google_finance_markets, google_flights, google_patents, and google_patents_details.
  • Bing: bing, bing_images, bing_videos, bing_news, bing_shopping, and bing_maps.
  • Other providers: yandex and duckduckgo. For Yandex, the LangChain query field is sent as the API's required text parameter.

For compatibility, google_search maps to google, and google_places maps to google_local before the request is sent.

Unsupported parameters are omitted from the request. Unsupported engines are rejected because silently switching a search source would change user intent.

Every request sends fixed integration metadata:

  • Platform: langchain
  • Source: python-sdk

These values are sent as both request headers and form metadata. The current ThorData service records the form metadata without forwarding it to the search provider.

The API key is never included in tool output or exception messages. Business code 300 raises ThorDataNotCollectedError; all API exceptions retain their numeric code for programmatic handling.

JSON-string response envelopes are normalized by the client before the LangChain tool serializes its result, so callers parse the tool output once.

Development

ruff check .
pytest
python -m build

Live integration tests should use a dedicated test account and API key. Unit tests use an in-memory HTTP transport and do not call Thordata services.

Learn more

Release files for langchain-thordata 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-thordata 0.2.0
File Size Uploaded
langchain_thordata-0.2.0.tar.gz 12.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-thordata 0.2.0
File Interpreter ABI Platform
langchain_thordata-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.7 kB

Release files / langchain_thordata-0.2.0.tar.gz

Download URL langchain_thordata-0.2.0.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ebfc7b67602bafc6e32fb06891715fe5a0257199bde42383930573df8be392e0
BLAKE2b-256 checksum
How to use checksums
760384b9c61ad8a7f39cf9d7bbf669361ac547ab119f243bc04ef52f93317ffb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / langchain_thordata-0.2.0-py3-none-any.whl

Download URL langchain_thordata-0.2.0-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3157acdbd4de400b9fe0b638ccdeef071d8556f0729d41d97b0a2e9a307b7db
BLAKE2b-256 checksum
How to use checksums
b04a0166cb11931f359ee8e9dee9720c98a270d565d4f9d3e2fd86b9e3b7516a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page