Metadata-Version: 2.4
Name: langchain-serpbit
Version: 0.2.0
Summary: Serpbit for LangChain: Google Search tools that outlive Google's Custom Search API, and a stealth cloud browser for agents.
Author-email: Serpbit <support@serpbit.com>
License-Expression: MIT
Project-URL: Homepage, https://serpbit.com/custom-search-api-alternative/
Project-URL: Documentation, https://serpbit.com/docs/#sdks
Keywords: langchain,google search,custom search api,serp api,web search,ai agents,cloud browser,web scraping
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: langchain-core<2,>=0.3
Requires-Dist: serpbit<1,>=0.3.0
Dynamic: license-file

# langchain-serpbit

[Serpbit](https://serpbit.com/) for LangChain, in two parts:

- **Browser tools.** A real Chrome or Firefox on a home connection in the country you pick opens the pages that block
  plain requests or need JavaScript. Your agent gets them as Markdown with numbered elements to click and type into.
- **Google Search.** Google's Custom Search JSON API stops searching the whole web on January 1, 2027. These are the
  Google Search tools of `langchain-google-community`, with the same calls, names and answers, served from Google's own
  results pages.

```sh
pip install langchain-serpbit
```

## Browser tools

```python
from langchain.agents import create_agent
from langchain_serpbit import SerpbitBrowserToolkit

tools = SerpbitBrowserToolkit().get_tools()  # SERPBIT_API_KEY
agent = create_agent("google_genai:gemini-3.5-flash", tools)  # or any model with tool calling
agent.invoke({"messages": [{"role": "user", "content":
    "What is the price of the first product in walmart.com's search results for running shoes?"}]})
```

The tools are the `browser_*` tools of Serpbit's MCP server, with its names, descriptions and arguments, read from the
server when you call `get_tools()`:

- `browser_fetch`: one page in a browser of its own, returned as Markdown with its links. The simplest one to give an
  agent: `SerpbitBrowserToolkit(tools=["browser_fetch"])`.
- `browser_open`, then `browser_navigate`, `browser_click`, `browser_type`, `browser_snapshot`, `browser_screenshot`,
  `browser_solve_captcha` and `browser_close`: a session that stays open for several steps. `browser_open` returns a
  live view link that a person can open to watch, or to take over for a sign-in or a CAPTCHA.

`browser_fetch` and `browser_open` take `country` (a two-letter code) and `engine`: `auto` picks Firefox for DataDome
and Akamai sites and Chrome for Cloudflare, from our measurements. A screenshot comes back as the tool call's artifact,
an MCP `image` block in base64. A refusal, such as an ended session, goes back to the model as the tool's answer. The
browser is billed by the traffic it moves, about 1 to 3 MB a page. See [the Browser API](https://serpbit.com/browser-api/)
for plans, and [the docs](https://serpbit.com/docs/#browser-recipes) to use the same browser from Playwright,
Puppeteer, browser-use or Stagehand.

## Google Search

Moving is two lines: the import and the key. Make a key at https://app.serpbit.com/keys and set `SERPBIT_API_KEY`.
The search engine id is gone, because the results come from the whole web.

```python
# Before
from langchain_google_community import GoogleSearchAPIWrapper, GoogleSearchResults, GoogleSearchRun
search = GoogleSearchAPIWrapper(k=5)  # GOOGLE_API_KEY, GOOGLE_CSE_ID

# After
from langchain_serpbit import SerpbitSearchAPIWrapper, SerpbitSearchResults, SerpbitSearchRun
search = SerpbitSearchAPIWrapper(k=5)  # SERPBIT_API_KEY

search.run("espresso grinder")  # the results' snippets
search.results("espresso grinder", 3, search_params={"gl": "de", "dateRestrict": "m1"})

tools = [SerpbitSearchRun(api_wrapper=search), SerpbitSearchResults(api_wrapper=search, num_results=4)]
```

The tools keep Google's names, `google_search` and `google_search_results_json`, and Google's descriptions, so
prompts, traces and evaluations stay as they are. `search_params` are Custom Search's own: `gl`, `hl`, `lr`, `safe`,
`dateRestrict`, `siteSearch`, `fileType`, `start`, `exactTerms` and the rest
([the full list](https://serpbit.com/docs/#cse)).

What differs from Google's:
- `siterestrict=True` is refused, because a Custom Search engine's own list of sites does not carry over. To search one
  site, pass `search_params={"siteSearch": "example.com"}`.
- `results()` has no `image` or `thumbnail`, because Serpbit's answer has no `pagemap`.
- A failed call raises the [`serpbit`](https://pypi.org/project/serpbit/) client's errors, such as
  `serpbit.InsufficientCreditsError` when the credits run out.
- A search takes about 2 seconds, against under 1 on Google's API.

Each search costs 1 credit. The free plan gives 1,000 credits a month, with no card.
