Skip to main content

Quarry Python SDK

The official Python SDK for the Quarry Google search results API. Requires Python 3.9 or newer. Uses httpx for synchronous and asynchronous requests.

pip install quarryserp
export QUARRY_API_KEY="your-api-key"
from quarryserp import Quarry

with Quarry() as client:
    search = client.search_and_wait("coffee", lang="en", country="us")
    for result in search.get("results", {}).get("organic", []):
        print(result["title"], result["url"])

Pass api_key="..." to override QUARRY_API_KEY. Unspecified search options use the API defaults: type web, mode sync, cache enabled, resolve_links organic, image_fallback none. All timeouts and backoff settings use seconds.

Async

import asyncio
from quarryserp import AsyncQuarry

async def main():
    async with AsyncQuarry() as client:
        images = await client.search_images("coffee", thumbnails=False)
        print(images)

asyncio.run(main())

AsyncQuarry has the same methods as Quarry; await each method, and use async for with paginate. Use close() / aclose() or context managers to release resources. If you supply an http_client, you own and close that client.

Searches and polling

with Quarry() as client:
    initial = client.submit("coffee", type="news")  # always mode=async
    search = client.wait_for(initial, timeout=180)
    saved = client.get(search["id"], thumbnails=False)
    raw_html = client.html(search["id"])
    usage = client.account()

search() can return pending even in sync mode. wait_for(search_or_id) follows pollUrl and retryAfterMs. Its optional timeout limits the polling period; the initial search or ID lookup has its own request timeout. search_and_wait() combines search and polling. Vertical helpers search_news, search_videos, search_images, search_shopping, and search_places accept a query and search keyword options and return only the corresponding result list (empty when absent).

Search options are type, lang, country, cursor, mode, cache, resolve_links, thumbnails, and image_fallback. The SDK maps snake_case options to the API's camelCase fields. Response dictionaries keep the original camelCase keys. Exported TypedDicts, GoogleLanguage / GoogleCountry literals, and GOOGLE_LANGUAGES / GOOGLE_COUNTRIES tuples provide editor support.

Pagination

with Quarry() as client:
    for page in client.paginate("coffee", max_pages=3, thumbnails=False):
        print(page.get("results", {}).get("organic", []))

Pages wait for completion. Later pages send only the next cursor and the thumbnail option, matching the TypeScript client. max_pages=0 makes no requests. When calling search(cursor=...) directly, only cursor, mode, cache, thumbnails, and image_fallback are sent; the cursor replaces the other search options.

Errors and retries

from quarryserp import Quarry, QuarryError

try:
    with Quarry(max_retries=2, backoff=0.5, timeout=120.0) as client:
        search = client.search_and_wait("coffee")
except QuarryError as error:
    print(error.code, error.message, error.status_code, error.retryable)
    print(error.retry_after)  # seconds from Retry-After, when present
    print(error.search)       # full failed search, when present

The default is no retries. Only retryable errors are retried, with linear delays of backoff * attempt; HTTP 429 retries wait at least Retry-After seconds. Connection and timeout errors use NETWORK_ERROR. Failed search envelopes raise QuarryError even with HTTP 200. A polling timeout also raises NETWORK_ERROR.

Constructor options: api_key=None, base_url="https://api.quarryserp.com", timeout=120.0, max_retries=0, backoff=0.5, user_agent=None, and http_client=None. The default User-Agent is quarryserp-python/0.1.0.

Documentation · Source · MIT licensed.

Development

uv run --with pytest --with pytest-asyncio pytest -q
uvx --with httpx mypy --strict src
uv build

Metadata

Release files for quarryserp 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 quarryserp 0.1.0
File Size Uploaded Provenance
quarryserp-0.1.0.tar.gz 15.2 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 31.0 kB

Release files / quarryserp-0.1.0.tar.gz

Download URL quarryserp-0.1.0.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
30056a46d04f6579f43374717bc973bafa9fa811573e7b1b9d234763bc31f85a
BLAKE2b-256 checksum
How to use checksums
2f77fdc855ddff27fe7355c9f4f01f6ba94a1aa62b3d7a4da2363c60422fb403
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / quarryserp-0.1.0-py3-none-any.whl

Download URL quarryserp-0.1.0-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
19394eecbbf806a8284d38947e591beb6525d40d6ae42948ac88187838705a4a
BLAKE2b-256 checksum
How to use checksums
1a92aec3e2d4bb9b90beb1ac915a6497b721903c8211d2c3110b90127cd259e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Security for quarryserp 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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