Skip to main content

Python SDK for the OpenSERP self-hosted server and OpenSERP Cloud.

Project description

OpenSERP Python SDK

Alpha: API may change before 1.0.

Python SDK for the OpenSERP self-hosted server and OpenSERP Cloud. The same client works against both backends.

Install

pip install openserp

For DataFrame export:

pip install "openserp[pandas]"

OSS Mode

OSS mode is the default. Run the open source server locally, then point the SDK at it:

from openserp import OpenSERP

client = OpenSERP(base_url="http://localhost:7000")

resp = client.search(
    engine="google",
    text="openserp",
    limit=10,
    region="US",
)

print(resp.results[0].title, resp.results[0].url)

If you omit every option, the client uses http://localhost:7000.

Cloud Mode

Pass an API key and the client defaults to https://api.openserp.org/v1.

import os

from openserp import OpenSERP

client = OpenSERP(api_key=os.environ["OPENSERP_API_KEY"])
resp = client.search(engine="google", text="openserp")

print(resp.results[0].title)
print(client.last_response.credits)

Async

import asyncio
import os

from openserp import AsyncOpenSERP


async def main() -> None:
    async with AsyncOpenSERP(api_key=os.environ["OPENSERP_API_KEY"]) as client:
        resp = await client.search(engine="google", text="openserp")
        print(resp.results[0].title)


asyncio.run(main())

Mega Search

from openserp import OpenSERP

client = OpenSERP()

mega = client.mega_search(
    text="openserp",
    engines=["google", "bing", "yandex"],
    mode="balanced",
)

df = mega.to_pandas()
print(df[["rank", "title", "url", "engine"]])

Convenience helpers are also available:

client.fast_search(text="openserp", engines=["google", "bing"])
client.any_search(text="openserp", engines=["google", "bing"])
client.mega_image(text="golang logo", engines=["google", "bing"])

AI / RAG

from openserp import OpenSERP

client = OpenSERP()
resp = client.search(engine="google", text="latest postgres indexing guide", limit=5)

context = "\n\n".join(
    f"{item.title}\n{item.url}\n{item.snippet}"
    for item in resp.results
)

prompt = f"Use these web results as grounding:\n\n{context}\n\nSummarize the key points."

SEO Keyword Tracker

from openserp import OpenSERP

client = OpenSERP()
keywords = ["openserp", "serp api", "google search api"]
frames = []

for keyword in keywords:
    resp = client.search(engine="google", text=keyword, region="US", limit=10)
    frame = resp.to_pandas()
    frame["keyword"] = keyword
    frames.append(frame)

report = __import__("pandas").concat(frames, ignore_index=True)
report.to_csv("rank-report.csv", index=False)

Async Batch

import asyncio

from openserp import AsyncOpenSERP


async def main() -> None:
    sem = asyncio.Semaphore(20)
    queries = [f"keyword {i}" for i in range(500)]

    async with AsyncOpenSERP() as client:
        async def run(query: str):
            async with sem:
                return await client.search(engine="google", text=query, limit=10)

        responses = await asyncio.gather(*(run(query) for query in queries))
        print(len(responses))


asyncio.run(main())

Endpoint Availability

Search endpoints work in both modes. Operational OSS endpoints such as health(), stats(), parse_google(), and parse_bing() require a self-hosted server and raise OssOnlyError in Cloud mode.

Cloud account endpoints such as me(), pricing(), engines_status(), and engines_capabilities() require Cloud mode and raise CloudOnlyError in OSS mode.

Development

python -m pip install -e ".[dev,pandas]"
pytest
ruff check .
mypy src
python -m build

The project is scaffolded for uv too:

uv build

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openserp-0.1.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openserp-0.1.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file openserp-0.1.1.tar.gz.

File metadata

  • Download URL: openserp-0.1.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openserp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f5b9509e0c8b291ca5f1b9c587771313d7846266ae4fc82a6caf582f6d3dd0f2
MD5 506dcb150c8f8cbdf85ccfa057d545c4
BLAKE2b-256 a9255320dc62c8633d907d94d1c663265aa6b659cd21ecfee7f3f71e28ae97b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for openserp-0.1.1.tar.gz:

Publisher: sdk-python.yml on karust/openserp_project

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openserp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: openserp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openserp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a769b6a1b356579bb0f151e6f770613fe05dc0bbc339b215ae5bc8cd9c1d80bd
MD5 2452ac51111da8cd724047e0564fc5ba
BLAKE2b-256 50421426425542960e75134ba7211d99d031147c63df5c17866fca9fcec9e34f

See more details on using hashes here.

Provenance

The following attestation bundles were made for openserp-0.1.1-py3-none-any.whl:

Publisher: sdk-python.yml on karust/openserp_project

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page