A simple python wrapper for Google's Search API, enabling programatic web and image searches.
- 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.
Python 3.x
The following Python packages are required:
requests
: For making HTTP requests to the Google API.python-dotenv
: For loading environment variables from an.env
file.
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.txt
- 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.
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.
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.
- Once you've obtained your API key and CX id, add them to your
.env
file. - Create a new file named
.env
in the root directory, or rename theexample.env
file in the root directory of the project to.env
. - Add your API key and CX id to the
.env
file 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.
from google_search_api import GoogleSearchAPI
print(GoogleSearchAPI().response(method='text', max_results=5, query='Your text prompt'))
from google_search_api import GoogleSearchAPI
print(GoogleSearchAPI().response(method='image', max_results=5, query='Your image prompt'))
Contributions are welcome!
Please refer to CONTRIBUTING.md for detailed guidelines on how to contribute to this project.
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.
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.
Stay up-to-date with the latest changes and improvements in each version:
- CHANGELOG.md provides detailed descriptions of each release.
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.
Licensed under the MIT License. See LICENSE for details.