Repository navigation
Add static typing support via optional extra - #51
adarshdigievo wants to merge 8 commits into
Conversation
Adds serpapi-stubs, a separate type-stub package built from stubs/ and installed with the serpapi[typing] extra. Engine parameter types are generated from the SerpApi Playground, with workflows to check, refresh and release the stubs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
ubuntu-latest is now Ubuntu 26.04, where actions/setup-python has no Python 3.8 or 3.9. uv downloads its own builds of every version in the matrix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Skip an older stub release only when a newer compatible stub snapshot has its own release run, so a multi-commit push no longer drops or duplicates a release. Keep a refresh branch that has a maintainer commit anywhere in its history. Require a mutable mapping for proxies, which requests updates in place. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Type a Playground choice list as str when an example list in its description mixes options with other values, as Walmart's sort does with new. Accept output="json_with_pixel_position" for google, google_ads and the Search Archive, where SerpApi documents it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved version-ordering defects can prevent upgrades from selecting the fix, while pagination and format-override annotations misrepresent runtime return types.
3 open issues
What changed in this PR
Adds a separately published serpapi-stubs package for engine-specific typing across synchronous and asynchronous SDK APIs, without changing runtime behavior.
Changes:
- Adds stub packaging, generation tools, and an optional
typingextra. - Introduces type-checking tests and workflows for validation, weekly refreshes, and independent stub releases.
- Documents installation, typed usage, and release procedures, and adjusts examples for compatibility.
| File | Description |
|---|---|
tests/test_typing_extra.py |
Checks that the stub pin matches the SDK version. |
stubs/tools/release_version.py |
Computes stub versions and checks published releases. |
stubs/tools/generate_stubs.py |
Generates engine parameter types and API overloads. |
stubs/tools/fetch_engines.py |
Fetches and normalizes Playground metadata. |
stubs/tests/typecheck/check_usage.py |
Checks valid synchronous calls and inferred types. |
stubs/tests/typecheck/check_errors.py |
Checks rejection of invalid calls. |
stubs/tests/typecheck/check_async.py |
Checks asynchronous APIs and transport types. |
stubs/tests/test_release_version.py |
Tests versioning and publication checks. |
stubs/tests/test_packaging.py |
Tests packaging and workflow safeguards. |
stubs/tests/test_generate_stubs.py |
Tests generated signatures and freshness. |
stubs/tests/test_fetch_engines.py |
Tests metadata extraction and normalization. |
stubs/tests/stubtest_allowlist.txt |
Allows the typing-only parameter module. |
stubs/tests/conftest.py |
Makes tooling modules available to tests. |
stubs/serpapi-stubs/utils.pyi |
Types the environment API-key helper. |
stubs/serpapi-stubs/textui.pyi |
Types JSON formatting utilities. |
stubs/serpapi-stubs/models.pyi |
Types result objects and pagination. |
stubs/serpapi-stubs/http.pyi |
Types clients and transport options. |
stubs/serpapi-stubs/exceptions.pyi |
Types SDK exceptions. |
stubs/serpapi-stubs/__version__.pyi |
Declares the SDK version type. |
stubs/serpapi-stubs/__init__.pyi |
Exposes typed public SDK exports. |
stubs/README.md |
Documents stub installation, usage, and limitations. |
stubs/pyproject.toml |
Configures packaging and type checkers. |
stubs/MANIFEST.in |
Controls source distribution contents. |
stubs/LICENSE |
Includes the SDK’s MIT license. |
stubs/.gitignore |
Excludes generated version and build artifacts. |
README.md |
Adds typing installation guidance. |
pyproject.toml |
Adds the version-matched typing extra. |
docs/user_guide/async-search-archive.md |
Passes the reserved async parameter through a dictionary. |
docs/examples/google-play-store-apps.md |
Uses a dictionary for dynamic search parameters. |
docs/examples/google-lens-image-upload.md |
Removes the product-search suggestion from prose. |
docs/examples/google-images-search.md |
Uses a dictionary for image-search parameters. |
CONTRIBUTING.md |
Documents stub checks, refreshes, releases, and hotfixes. |
.github/workflows/stubs.yml |
Validates generated and installed stubs. |
.github/workflows/stubs-release.yml |
Publishes compatible stub-only updates. |
.github/workflows/stubs-refresh.yml |
Opens or updates weekly metadata refresh PRs. |
.github/workflows/stubs-build.yml |
Builds versioned stub distributions. |
.github/workflows/release.yml |
Publishes matching stubs before SDK releases. |
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The maintainer-commit check can miss corrections pushed after the branch fetch, allowing the no-change path to close the PR and delete the updated branch without a branch-tip lease.
1 open issue
3 resolved since last review
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
SDK releases now depend on stub publishing, requiring maintainer verification of PyPI trusted-publisher and environment settings unavailable in the checkout, plus validation of the cross-workflow release sequence.
No open issues 🎉
1 resolved since last review
Review effort: Balanced

Summary
Add
serpapi-stubs, a separately published package that gives editors, mypy, and pyright engine-specific parameter and return types for 164 SerpApi engines. It covers bothClientandAsyncClient.This change does not affect the main
serpapilibrary. It adds a new dedicate type stub package for static type checkers, installable as an extra.A weekly workflow checks the SerpApi Playground for changes and opens or updates a refresh PR when the generated files differ. Stub updates can ship between SDK releases.
Type
Related issue
No separate tracking issue. This is an alternative to #34: the stubs are built from this repository but distributed separately from the runtime SDK.
Affected SDK functionality
serpapipackage version (if known): 1.3.0; matching stub series1.3.0.*.Client,AsyncClient, search, extract, archive, uploads, locations, account, and pagination. JSON searches return result objects; HTML and Markdown searches returnstr. Async calls preserve that distinction afterawait.typingextra alone.Testing
python -m pytest -q -p no:cacheprovider -o addopts= stubs/tests tests/test_typing_extra.py tests/test_async_client.py tests/test_exceptions.py— 247 passed.python -B stubs/tools/generate_stubs.py --check— generated files are up to date.bd5f459and installed them outside the checkout. Across all 164 engines, mypy 2.4.1 and pyright 1.1.414 each accepted 1,414 valid examples and rejected 604 invalid examples on the intended lines. Removing onlyserpapi-stubsmade both checkers stop catching the same misspelled keyword.AI disclosure
Model(s): Claude Fable 5.2 (xhigh) and Copilot Fusion Max for implementation. Review and validation also used Claude Opus 5.5, Gemini 4 Carbon and Neon, GPT-6.1 Sol, and GPT-6.2 Astra (extra high efforts).
Harness/app(s) (e.g., Codex, Claude Code, Cursor): GitHub Copilot Desktop, Copilot subagents, Claude Code.
Used for (e.g., coding, tests, review, documentation): Implementation, documentation, independent review, and test execution. Fable 5.2 Max and Gemini Neon Max independently reviewed the full change before the final fixes.
Evidence
The script below shows warnings on IDEs and on type checkers like Mypy.