This Python project uses the Google Search Console API to automatically index or reindex URLs listed in a sitemap. The script is designed with error handling, retry mechanisms, and a beautiful terminal UI for professional indexing.
- Automated URL Indexing/Reindexing: Automatically submits URLs for indexing based on your sitemap.
- Rich Terminal UI: Displays status and progress of indexing in a professional, colorful, and easy-to-read format.
- Error Handling: Gracefully handles indexing failures and retries with appropriate logging.
- Google API Authentication: Uses service account credentials for secure API access.
Before running the script, ensure you have the following:
- Python 3.7+ installed
- A Google Cloud project with Google Search Console Indexing API enabled
- Service account credentials in a
key.json
file - Sitemap URL containing the URLs to be indexed
First, clone this repository to your local machine:
git clone https://github.com/theriturajps/gsc-url-indexer.git
cd gsc-url-indexer
- Go to the Google Cloud Console.
- Enable the Indexing API for your project.
- Create a Service Account and download the JSON key file (
key.json
). - Add the service account email to your Google Search Console property with full permissions.
To run this project, you'll need to install the required Python libraries. You can do this by running:
pip install -r requirements.txt
Alternatively, install them manually:
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client requests xmltodict rich
Ensure the following project structure:
gsc-url-indexer/
│
├── key.json # Your Google Cloud credentials file
├── indexer.py # Main script file
├── README.md # Project documentation
├── requirements.txt # Python dependencies
└── LICENSE # License for the project
Run the indexer.py
script with:
python indexer.py
The script will:
- Authenticate with the Google Search Console API.
- Fetch all URLs from your sitemap.
- Index or reindex each URL.
- Display progress, status, and a summary in the terminal.
The script requires a valid service account credential file (key.json
). Ensure your service account is added as a user with permissions in your Google Search Console property.
By default, the script is set to use https://www.riturajps.in/sitemap.xml
. You can replace this URL in the script if you're using a different sitemap.
# Sitemap URL to fetch the URLs
sitemap_url = 'https://www.riturajps.in/sitemap.xml'
The script provides professional output in the terminal, like the example below:
🚀 Google Search Console Indexer 🚀
Authenticated successfully with Google Search Console.
Fetched 10 URLs from the sitemap.
Indexing URLs...
----------------------------------------------------------------
| URL | Status | Details |
----------------------------------------------------------------
| https://example.com/page1 | Success | Indexed successfully |
| https://example.com/page2 | Success | Indexed successfully |
| https://example.com/page3 | Failed | Error occurred |
----------------------------------------------------------------
📊 Indexing Summary 📊
----------------------------------------------------------------
Total URLs Processed: 10
Successful: 8
Failed: 2
- Authentication Errors: Ensure your
key.json
is valid and your service account has proper permissions. - Failed URL Indexing: Check if the URLs are properly formatted and accessible via Google Search Console.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to submit a PR or open an issue if you find a bug or have a suggestion for improvement.
If you have any issues or questions, feel free to reach out by opening an issue on the GitHub repository.
- GitHub Sponsor (Global): Click Here
- UPI (India): Support Using UPI
- Thanks to Google for providing the Indexing API.