Skip to main content

serpbit

Google Search, News, Shopping, Images, Videos, Maps, Autocomplete and AI Mode as data, from Serpbit. No dependencies: the standard library only, Python 3.9+.

pip install serpbit
from serpbit import Serpbit

sb = Serpbit()  # reads SERPBIT_API_KEY; make a key at https://app.serpbit.com/keys

answer = sb.search("espresso grinder", gl="de", hl="de", pages=2)
for r in answer["organic"]:
    print(r["position"], r["title"], r["url"])

# The first three results' pages, as Markdown text: 1 credit a page read.
answer = sb.search("how to descale an espresso machine", content=3)
print(answer["organic"][0]["content"]["text"][:500])

# Markdown instead of JSON, for a language model's context.
print(sb.news("wildfire", sort="date", output="md"))

Every door of the API has a method: search, news, shopping, shopping_product, images, videos, maps, autocomplete, ai_mode. Keyword arguments are the door's parameters, as the docs name them:

  • True is sent as true;
  • None and False are left out;
  • a list is joined with commas.

A method returns the API's JSON as a dict, or a str with output="md". sb.last_request_id and sb.last_credits give the last answer's id and the credits it spent.

Browser API

Real browsers on residential connections, billed by the traffic they move (your browser plan's GB). The connect URL opens a session when a client connects and ends it when the client goes:

from playwright.sync_api import sync_playwright
from serpbit import Serpbit

sb = Serpbit()
with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(sb.browser_connect_url(country="de"))
    page = browser.contexts[0].pages[0]
    page.goto("https://example.com")

Or open one yourself and keep it: s = sb.create_browser_session(country="us", engine="auto", site="hermes.com") gives s["ws_url"] for Playwright or Puppeteer and s["live_url"] for a person to watch or take over; end it with sb.end_browser_session(s["id"]). engine="auto" picks the engine measured to pass the site. Saved profiles keep cookies and logins between sessions: create_browser_profile, then profile= on a session.

Errors and retries

A failed call raises a SerpbitError. The subclasses are:

  • BadRequestError (400);
  • AuthenticationError (401);
  • InsufficientCreditsError (402: no credits, or for the browser out_of_traffic);
  • PermissionDeniedError (403);
  • NotFoundError (404);
  • UnprocessableEntityError (422, such as a CAPTCHA call with no widget on the page);
  • RateLimitError (429, with retry_after);
  • APIError (5xx);
  • APIConnectionError.

Each carries status, code and request_id. Quote the request_id to support.

Calls are retried twice on 429 and 5xx (set with max_retries), waiting as Retry-After says. Every attempt of one call carries the same Idempotency-Key, so an answer lost on the way is given back free instead of being billed twice. You can pass your own with idempotency_key=.

Batches

b = sb.batch([{"path": "/v1/search", "params": {"q": kw, "gl": "us"}, "id": kw} for kw in keywords],
             webhook="https://example.com/serpbit")
sb.get_batch(b["id"])                     # status, and each call's
sb.batch_results(b["id"], offset=0)       # the answers, 100 at a time, for a day after it ends

# In your webhook: check the event is Serpbit's before you trust it.
from serpbit import verify_webhook
ok = verify_webhook(request.body, request.headers["Serpbit-Signature"], api_key)

Metadata

Release files for serpbit 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 serpbit 0.2.0
File Size Uploaded Provenance Actions
serpbit-0.2.0.tar.gz 13.6 kB Without provenance Details for serpbit-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 24.3 kB

Release files / serpbit-0.2.0.tar.gz

Download URL serpbit-0.2.0.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
da6036791838f7e54237f6962268517bbbd6546227fb3a55e8545565b8ef6f0f
BLAKE2b-256 checksum
How to use checksums
9d9ffdda7b9fc60518f6c8589f08fc840eb0d734f48a14d8911dca8ac198f9d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.16

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

Download URL serpbit-0.2.0-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a994e8fa3d9999d140cda43d093157fc3a759b01ea8a9840e5cb4b96a6412574
BLAKE2b-256 checksum
How to use checksums
221ff92d0843ba68d55b0533a5505126814aa1baa2eccd9e88e0d5d6803f988c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.16

Security for serpbit 0.2.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