Skip to main content

Simple Google Custom Search Engine (CSE) wrapper.

Project description

Google CSE

PyPI version Python versions License Downloads

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

  1. Get an API key from Google Cloud Console.
  2. Create a Programmable Search Engine (CSE) at programmablesearchengine.google.com.
  3. Enable Custom Search API in your project.
  4. Pass your credentials to the client:
client = GoogleCSE(api_key="YOUR_API_KEY", search_engine_id="YOUR_SEARCH_ENGINE_ID")

⚠️ Notes

  • num_results must be between 1 and 10 (Google API limit).
  • start_index + num_results must not exceed 100.
  • The package raises Python exceptions on network or API errors.

📜 License

Apache License 2.0 © 2025

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

google_cse-0.1.2.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

google_cse-0.1.2-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

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

Hashes for google_cse-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3d400a0e79cc31f4113df0e15caa92c3ff7ffeabb1aaf51cb8b45c9a9bbab82b
MD5 74de095b13f915dd81c2601b286d9a93
BLAKE2b-256 88b6f8531db60f286b3a616791a99bebefe53b812de93771e2d3e8d1ad66ce97

See more details on using hashes here.

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

Hashes for google_cse-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 13f9dc1611a7829673e3d4a9cb089048918de48c48faa2e5656ee90df8904977
MD5 1a7abf6f3a6dab65b748cb22fce84ae0
BLAKE2b-256 e0bba2f6520d2d142bbfa9a812f8cd85af9fc5e870b8de622467b0003618e15b

See more details on using hashes here.

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