Skip to main content

An integration package connecting SERPEX and LangChain (Python)

Project description

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 a powerful multi-engine search API that provides access to search results from Google, Bing, DuckDuckGo, Baidu, Yandex, and other search engines in JSON format. It's designed for developers building AI applications, SEO tools, market research platforms, and data aggregation services.

Features

  • Multi-Engine Support: Search across Google, Bing, DuckDuckGo, Baidu, and Yandex
  • Rich Results: Get organic results, answer boxes, knowledge graphs, news, images, videos, and shopping results
  • Localization: Support for location-based and language-specific searches
  • Real-time Data: Access to current search results
  • Easy Integration: Simple API with comprehensive documentation

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",
    engine="google",
    num_results=10
)

# 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",
    engine="google",
    num_results=5
)

# 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

# Configure with advanced parameters
tool = SerpexSearchResults(
    api_key="your-serpex-api-key",
    engine="google",
    num_results=20,
    gl="us",  # Country code
    hl="en",  # Language code
    location="New York",  # Specific location
    time_period="m",  # Results from past month
    safe_search="moderate"
)

# Search for location-specific results
results = tool.invoke("best restaurants")
print(results)

Different Search Engines

from langchain_serpex_python import SerpexSearchResults

# Google Search
google_tool = SerpexSearchResults(api_key="your-key", engine="google")
google_results = google_tool.invoke("Python programming")

# Bing Search
bing_tool = SerpexSearchResults(api_key="your-key", engine="bing")
bing_results = bing_tool.invoke("Python programming")

# DuckDuckGo Search
ddg_tool = SerpexSearchResults(api_key="your-key", engine="duckduckgo")
ddg_results = ddg_tool.invoke("Python programming")

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)
  • engine (str): Search engine to use - "google", "bing", "duckduckgo", "baidu", "yandex" (default: "google")
  • num_results (int): Number of results to return, 1-100 (default: 10)
  • gl (str): Country code for localized results (e.g., "us", "uk", "ca")
  • hl (str): Language code (e.g., "en", "es", "fr")
  • location (str): Specific location for localized results
  • time_period (str): Time filter - "d" (day), "w" (week), "m" (month), "y" (year)
  • safe_search (str): Safe search filter - "off", "moderate", "strict"

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_serpex_python-0.1.4.tar.gz (134.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_serpex_python-0.1.4-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file langchain_serpex_python-0.1.4.tar.gz.

File metadata

  • Download URL: langchain_serpex_python-0.1.4.tar.gz
  • Upload date:
  • Size: 134.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for langchain_serpex_python-0.1.4.tar.gz
Algorithm Hash digest
SHA256 be23b7a3b3bbb8e8ef1e4e475b8acaa8ef2b732ebf43fb7b53da85d0223e75d7
MD5 263c9fd6030f180cabb0bc2b2028eb4f
BLAKE2b-256 71fc0f83bb146648cde7da7e9908c8482b62434f4f2db24564580cacdd69c323

See more details on using hashes here.

File details

Details for the file langchain_serpex_python-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_serpex_python-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cef794bc9a641776dac0075e5455089f1fea178698f0591f8405c34f2a0b4d09
MD5 9c9161ce2deea159fdb7e42179beb3f9
BLAKE2b-256 6d3cba4d2317d5dc32da6d01a5ece085fa386b48675b94f989d1c63204a8bf2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page