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.0.tar.gz (10.5 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.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openserp-0.1.0.tar.gz
  • Upload date:
  • Size: 10.5 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.0.tar.gz
Algorithm Hash digest
SHA256 19615e05fd24ec53d2dec6fe748fa9b85c69faeab9e899581b0aee5f16ffce1f
MD5 c54d9920be13b90a2f60c6231d4141ec
BLAKE2b-256 5188697b764f3b92bc4dcaf5f41f1d4fe51e98483b509de780ff81f76db2e8e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for openserp-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: openserp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 368ddc2756059296cd6323dc69fffa5dbc66e72e2bf077d29a0397f82f857911
MD5 8f7c1dac3f6500ea6419f613e6481651
BLAKE2b-256 9826ac80b55f262b4e0eab6e70d2c12aef9b33f214cc72d05acdcbf41d4a09be

See more details on using hashes here.

Provenance

The following attestation bundles were made for openserp-0.1.0-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