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.image_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.1.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.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file google_cse-0.1.1.tar.gz.

File metadata

  • Download URL: google_cse-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 ec8c371e7ecbdac8c27d19110fec1250ac3608b39e551910b6da2fa37b019c76
MD5 c0865664356fa27d55237660256cfee6
BLAKE2b-256 e04b7b9f94511731701af31dc9f8c48f9d8633abe13542a074e3e6e9b39693ad

See more details on using hashes here.

File details

Details for the file google_cse-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: google_cse-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c0de660a580cb29dcd45d84846ddf77690995c1e5e96f38627cd4445a33ba900
MD5 1127d130380e22aeaef9721ea54d5ca6
BLAKE2b-256 c1b012ddd3c8abd9f3e13b1924897e15da51609503fdb045116c1886f8a84653

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