Simple Google Custom Search Engine (CSE) wrapper.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file google_cse-0.1.2.tar.gz.
File metadata
- Download URL: google_cse-0.1.2.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d400a0e79cc31f4113df0e15caa92c3ff7ffeabb1aaf51cb8b45c9a9bbab82b
|
|
| MD5 |
74de095b13f915dd81c2601b286d9a93
|
|
| BLAKE2b-256 |
88b6f8531db60f286b3a616791a99bebefe53b812de93771e2d3e8d1ad66ce97
|
File details
Details for the file google_cse-0.1.2-py3-none-any.whl.
File metadata
- Download URL: google_cse-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13f9dc1611a7829673e3d4a9cb089048918de48c48faa2e5656ee90df8904977
|
|
| MD5 |
1a7abf6f3a6dab65b748cb22fce84ae0
|
|
| BLAKE2b-256 |
e0bba2f6520d2d142bbfa9a812f8cd85af9fc5e870b8de622467b0003618e15b
|