Google CSE
A clean, type-safe Python client for the Google Custom Search JSON API. This wrapper provides simple methods for web and image searches, with full type safety powered by Pydantic models.
🔧 Installation
pip install google-cse
🚀 Quick Start
from google_cse import GoogleCSE, WebSearchParameters, ImageSearchParameters
# Initialize client
client = GoogleCSE(api_key="YOUR_API_KEY", search_engine_id="YOUR_SEARCH_ENGINE_ID")
# Web search
results = client.web_search("OpenAI GPT-5", num_results=5)
for r in results:
print(r.title, "-", r.link)
# Image search
images = client.image_search("puppies", num_results=3)
for img in images:
print(img.title, "-", img.link)
📦 Features
- ✅ Simple and clean API for Google Custom Search Engine
- ✅ Type-safe with Pydantic models
- ✅ Supports web search and image search
- ✅ Easy-to-use parameters for advanced queries
⚙️ API Reference
GoogleCSE(api_key: str, search_engine_id: str)
Create a client for Google Custom Search.
- api_key → Your Google API key
- search_engine_id → Your Programmable Search Engine ID
Methods
🔍 web_search(query: str, start_index: int = 1, num_results: int = 10, parameters: Optional[WebSearchParameters] = None) -> List[WebSearchResult]
Perform a web search.
Returns a list of simplified WebSearchResult objects.
🖼️ image_search(query: str, start_index: int = 1, num_results: int = 10, parameters: Optional[ImageSearchParameters] = None) -> List[ImageSearchResult]
Perform an image search.
Returns a list of simplified ImageSearchResult objects.
⚡ raw_search(query: str, start_index: int = 1, num_results: int = 10, search_type: Optional[Literal["image"]] = None, parameters: Optional[SearchParameters] = None) -> GoogleSearchResponse
Perform a raw search and return the full API response (typed).
📋 Example with Parameters
# Web search with filtering
params = WebSearchParameters(
exact_terms="OpenAI",
site_search="openai.com",
safe="active"
)
results = client.web_search("GPT", num_results=5, parameters=params)
for r in results:
print(r.title, "-", r.snippet)
# Image search with filters
img_params = ImageSearchParameters(
img_size="large",
img_type="clipart"
)
images = client.image_search("cat", num_results=3, parameters=img_params)
for img in images:
print(img.title, "-", img.context_link)
🔑 Authentication
- Get an API key from Google Cloud Console.
- Create a Programmable Search Engine (CSE) at programmablesearchengine.google.com.
- Enable Custom Search API in your project.
- Pass your credentials to the client:
client = GoogleCSE(api_key="YOUR_API_KEY", search_engine_id="YOUR_SEARCH_ENGINE_ID")
⚠️ Notes
num_resultsmust be between 1 and 10 (Google API limit).start_index + num_resultsmust not exceed 100.- The package raises Python exceptions on network or API errors.
📜 License
Apache License 2.0 © 2025
Metadata
Release files for google-cse 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| google_cse-0.1.2.tar.gz | 12.5 kB | Without provenance | Details for google_cse-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| google_cse-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for google_cse-0.1.2-py3-none-any.whl |
Total release size: 24.9 kB
Release files / google_cse-0.1.2.tar.gz
| Download URL | google_cse-0.1.2.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d400a0e79cc31f4113df0e15caa92c3ff7ffeabb1aaf51cb8b45c9a9bbab82b
|
|
BLAKE2b-256 checksum How to use checksums |
88b6f8531db60f286b3a616791a99bebefe53b812de93771e2d3e8d1ad66ce97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.19
|
Release files / google_cse-0.1.2-py3-none-any.whl
| Download URL | google_cse-0.1.2-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
13f9dc1611a7829673e3d4a9cb089048918de48c48faa2e5656ee90df8904977
|
|
BLAKE2b-256 checksum How to use checksums |
e0bba2f6520d2d142bbfa9a812f8cd85af9fc5e870b8de622467b0003618e15b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.19
|
Security for google-cse 0.1.2
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.