Overview
A simple python wrapper for Google's Search API, enabling programatic web and image searches.
Key Features
- Web and image search functionality using Google Custom Search JSON API.
- Customizable search queries and result limits.
- Formatted search results including titles, links, snippets, and images.
- Error handling for missing credentials or invalid queries.
Prerequisites
Python 3.x
Dependencies
The following Python packages are required:
requests: For making HTTP requests to the Google API.python-dotenv: For loading environment variables from an.envfile.
Installation
To use this wrapper, clone the repository and install dependencies:
git clone https://github.com/RMNCLDYO/Google-Search-API-Wrapper.git
cd Google-Search-API-Wrapper
pip install -r requirements.txtObtaining Google Custom Search API Credentials
Obtaining an API Key
- Visit the Programmable Search Engine introduction page.
- Scroll down to the middle of the page and click on 'Get a Key' to generate your API key.
What is a Programmable Search Engine?
A Programmable Search Engine allows you to search google via the API, using Google's core search technology. You can customize it extensively, including the look and feel, search features, and even link it with Google Analytics for user behavior insights.
Creating a Programmable Search Engine
Before using the Google Custom Search API, you need to create a Programmable Search Engine. Follow these steps:
- Visit the Programmable Search Engine Control Panel.
- Name your search engine and specify what to search:
- Choose specific sites or the entire web.
- Set your search settings, such as enabling image search and/or SafeSearch.
- Complete the reCAPTCHA verification and create your search engine.
- Once created, find your Search Engine ID (cx parameter) in the Overview page's Basic section.
Configuration
- Once you've obtained your API key and CX id, add them to your
.envfile. - Create a new file named
.envin the root directory, or rename theexample.envfile in the root directory of the project to.env. - Add your API key and CX id to the
.envfile as follows:api_key=your_api_key_here cx=your_cx_id_here - The application will automatically load and use the API key and CX id when making API requests.
Usage
Text Search Example
from google_search_api import GoogleSearchAPI print(GoogleSearchAPI().response(method='text', max_results=5, query='Your text prompt'))
Image Search Example
from google_search_api import GoogleSearchAPI print(GoogleSearchAPI().response(method='image', max_results=5, query='Your image prompt'))
Contributing
Contributions are welcome!
Please refer to CONTRIBUTING.md for detailed guidelines on how to contribute to this project.
Reporting Issues
Encountered a bug? We'd love to hear about it. Please follow these steps to report any issues:
- Check if the issue has already been reported.
- Use the Bug Report template to create a detailed report.
- Submit the report here.
Your report will help us make the project better for everyone.
Feature Requests
Got an idea for a new feature? Feel free to suggest it. Here's how:
- Check if the feature has already been suggested or implemented.
- Use the Feature Request template to create a detailed request.
- Submit the request here.
Your suggestions for improvements are always welcome.
Versioning and Changelog
Stay up-to-date with the latest changes and improvements in each version:
- CHANGELOG.md provides detailed descriptions of each release.
Security
Your security is important to us. If you discover a security vulnerability, please follow our responsible disclosure guidelines found in SECURITY.md. Please refrain from disclosing any vulnerabilities publicly until said vulnerability has been reported and addressed.
License
Licensed under the MIT License. See LICENSE for details.
