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.

Errors and retries

A failed call raises a SerpbitError. The subclasses are:

  • BadRequestError (400);
  • AuthenticationError (401);
  • InsufficientCreditsError (402);
  • 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.1.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.1.0
File Size Uploaded Provenance Actions
serpbit-0.1.0.tar.gz 10.7 kB Without provenance Details for serpbit-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 19.4 kB

Release files / serpbit-0.1.0.tar.gz

Download URL serpbit-0.1.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fa384c171d167f03fdc503bfc8e6a07bed0add08338cb6dddf5e3007243e72c6
BLAKE2b-256 checksum
How to use checksums
46b7ab0971b1adfcf1b0aabc0e7c1580ae88d7e2d75b83982c1e4f5fa9deef6c
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.1.0-py3-none-any.whl

Download URL serpbit-0.1.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2fb8ba3abcbad20068f8f5475bc42afa921e6bb9bf877b3ba8ca46a0d588b28
BLAKE2b-256 checksum
How to use checksums
02265d54bce04c8e31ca2264c4caf154d5bd75efe8643b4fd2817a0ea4d2f9d9
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.1.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