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, and custom_search (Google's Custom Search JSON API, drop-in). 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.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 serpbit 0.3.0
File Size Uploaded Provenance Actions
serpbit-0.3.0.tar.gz 14.6 kB Without provenance Details for serpbit-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 25.7 kB

Release files / serpbit-0.3.0.tar.gz

Download URL serpbit-0.3.0.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ce439b694f70c08822de87fec7a014a35bbc96d73aaf5c4c3bf77e0dd00c5daa
BLAKE2b-256 checksum
How to use checksums
bf966c36d7b97afc2972f9cfacd7899bf0ac1d1b26e619f47a28b21eecd92bb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.13

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

Download URL serpbit-0.3.0-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61be18b387190c2bdcbd0b00da1607eb15fdb36d1abf80ecc759ce3331da2786
BLAKE2b-256 checksum
How to use checksums
908b2a4cedc70ca957adf12121b31551e8fb3580ecbc4fa868480389e641d721
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.13

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