Skip to main content

langchain-serpex-python

PyPI - Version PyPI - License Twitter

This package contains the LangChain integration with Serpex (Python).

Installation

pip install langchain-serpex-python

What is Serpex?

Serpex is the web search API and extract API for AI agents. Search returns ranked web results (title, URL, snippet), optionally with page content as markdown; Extract turns known URLs into clean markdown. It's built for AI agents, LLM tools and RAG pipelines.

Features

  • Web search: ranked results for any query, optionally with page content as markdown
  • Nothing to configure: every search is routed automatically
  • LangChain-native: a drop-in BaseTool for agents and chains
  • Easy integration: API key via argument or SERPEX_API_KEY

Quick Start

Get Your API Key

Sign up at SERPEX to get your API key.

Basic Usage

from langchain_serpex_python import SerpexSearchResults

# Initialize the tool
tool = SerpexSearchResults(api_key="your-serpex-api-key")

# Perform a search
results = tool.invoke("latest AI developments")
print(results)

With Agents

from langchain_serpex_python import SerpexSearchResults
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, AgentType

# Initialize the search tool
search_tool = SerpexSearchResults(api_key="your-serpex-api-key")

# Initialize the LLM
llm = ChatOpenAI(temperature=0)

# Create an agent with the search tool
agent = initialize_agent(
    tools=[search_tool],
    llm=llm,
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True
)

# Run the agent
result = agent.run("What are the latest developments in quantum computing?")
print(result)

Advanced Configuration

from langchain_serpex_python import SerpexSearchResults

# Also fetch page content (markdown) for the top 5 or 10 results
tool = SerpexSearchResults(
    api_key="your-serpex-api-key",
    include_content=True,
    content_results=5,
)

results = tool.invoke("best restaurants")
print(results)

Deprecated parameters

Every search is routed automatically, so there is nothing to select. engine, category and time_range are deprecated and ignored by the Serpex API; they are still accepted so existing code keeps working, emit a DeprecationWarning, and are not sent. They will be removed in 0.4.0. For a date filter, put after:YYYY-MM-DD / before:YYYY-MM-DD in the query; site: and -site: work the same way.

Configuration

Environment Variables

You can set your SERPEX API key as an environment variable:

export SERPEX_API_KEY="your-serpex-api-key"

Then use the tool without passing the API key:

from langchain_serpex_python import SerpexSearchResults

tool = SerpexSearchResults()  # Will use SERPEX_API_KEY from environment

Parameters

  • api_key (str): Your Serpex API key (required)
  • include_content (bool): Also fetch page content (markdown) for the top results (default: False). Best-effort: a page that can't be extracted shows its content_error instead.
  • content_results (int): How many top results get content, 5 or 10 (default: 5)
  • timeout (float): Request timeout in seconds (default: 60, or 100 with include_content)
  • base_url (str): API base URL (default https://api.serpex.dev)
  • engine, category, time_range: Deprecated — ignored by the Serpex API and not sent; removed in 0.4.0

The tool sends only q, plus include_content / content_results when page content is on.

Output

A numbered list: title, URL and snippet per result, then Content: (page markdown) or Content unavailable: <reason> for the top content_results results when include_content is on. An empty search returns the API's explanation, including whether it was charged.

Errors

Errors are returned as text the agent can act on (the tool does not raise): Error searching with Serpex: ... with one sentence per HTTP status — 400 (bad argument), 401 (check SERPEX_API_KEY), 402 (out of credits), 429 (rate limit: 5, 25 or 50 requests per second by plan, with the wait), 5xx (temporary, not charged).

Credits

1 per search. With include_content: 1 when no page came back, 3 for 1-5 pages, 6 for 6-10 pages. An empty result is charged only when it was confirmed as genuinely empty.

How it calls the API

Through the official serpex SDK (>=2.12.0), so request parameters, timeouts and error parsing follow the SDK. ainvoke runs the same call in LangChain's thread executor. Requests carry User-Agent: serpex-python/<sdk version> langchain-serpex-python/<version>.

Documentation

For more detailed documentation, visit:

Support

For issues and questions:

License

This package is licensed under the MIT License.

CI / Publishing

A GitHub Actions workflow is provided to publish the package to PyPI when a tag like v* is pushed or when a release is published.

Required repository secret:

  • PYPI_API_TOKEN — a PyPI API token with permission to upload the package. Set this in the repository's Settings → Secrets → Actions.

To publish a new release, create a tag vMAJOR.MINOR.PATCH and push it or create a release in GitHub; the workflow will build sdist and wheel and upload them to PyPI.

Metadata

Release files for langchain-serpex-python 0.3.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-serpex-python 0.3.0
File Size Uploaded Provenance Actions
langchain_serpex_python-0.3.0.tar.gz 190.7 kB Without provenance Details for langchain_serpex_python-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-serpex-python 0.3.0
File Interpreter ABI Platform Actions
langchain_serpex_python-0.3.0-py3-none-any.whl Python 3 none any Details for langchain_serpex_python-0.3.0-py3-none-any.whl

Total release size: 199.5 kB

Release files / langchain_serpex_python-0.3.0.tar.gz

Download URL langchain_serpex_python-0.3.0.tar.gz
Size 190.7 kB
Tags Source
SHA-256 checksum
How to use checksums
85175f7ac5198c1b2aad634fa78dea2ec56bc76d6c72b4589c1976a7fcce1693
BLAKE2b-256 checksum
How to use checksums
b7ab59638916605bc314864b8e33fc5e6d51c41fa897141f9f6c58bca36eb2cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / langchain_serpex_python-0.3.0-py3-none-any.whl

Download URL langchain_serpex_python-0.3.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3dd434c3937aa9d44d6de523987e4c1f640409a626109fb7c48eb317d97fb4e
BLAKE2b-256 checksum
How to use checksums
f54d43e72f73be6451dc912b53b21eb5d31f636b928ecd5c876d4ae7a4d40784
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Security for langchain-serpex-python 0.3.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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