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
- An API Key for Google's Custom Search JSON API
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.txtThe following Python packages are required:
requestspython-dotenv
Set your Google Custom Search JSON API credentials (API key and CX) as environment variables api_key and cx.
- Visit the Google Developers Introduction page for the Custom Search JSON API.
- Scroll down to the middle of the page and click on 'Get a Key' to obtain your API key.
- Use this key in your application by appending the query parameter
api_key=yourAPIKeyto all request URLs.
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 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
.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.
from google_search_api import GoogleSearchAPI # Initialize the GoogleSearchAPI class request = GoogleSearchAPI() # Perform a text search and retrieve results response = request.response(method='text', max_results=5, query='Python') # Print the formatted search results print(response)from google_search_api import GoogleSearchAPI # Initialize the GoogleSearchAPI class request = GoogleSearchAPI() # Perform an image search and retrieve results response = request.response(method='image', max_results=5, query='Nature') # Print the formatted search results print(response)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.
