Here is how you can integrate the SEMrush API with Python to track keyword rankings:
1. Install the python-semrush library, which provides a wrapper around the SEMrush API[1].
2. Obtain a SEMrush API key to authenticate API requests[1].
3. Use the SemrushClient class to make API calls, such as retrieving domain rankings or launching a site audit[1][2].
4. The SEMrush API supports endpoints for domain analytics and keyword research[2]. You can use the Position Tracking tool to monitor keyword rankings over time[3].
5. With the API, you can track rankings across different devices, locations, and search engines[3]. The Position Tracking tool allows you to compare against competitors and identify opportunities like featured snippets[3].
6. The results can be processed and analyzed using Python libraries like Pandas and Matplotlib[2].
Here's an example of how to use the SEMrush API with Python to retrieve domain rankings:
python
from python_semrush.semrush import SemrushClient
# Set your SEMrush API key
api_key = 'your_semrush_api_key'
# Create a SEMrushClient instance
client = SemrushClient(key=api_key)
# Get domain analytics for example.com
domain_analytics = client.domain_analytics(domain='example.com')
# Print the top 5 organic keywords
print("Top 5 Organic Keywords:")
for keyword in domain_analytics.organic_keywords[:5]:
print(f"- {keyword.keyword} (Position: {keyword.position})")
This code demonstrates how to use the `SemrushClient` class to retrieve domain analytics data, including the top organic keywords and their rankings[1].
By leveraging the SEMrush API with Python, you can build custom keyword tracking solutions and integrate SEMrush data into your existing workflows and applications.
Citations:[1] https://github.com/storerjeremy/python-semrush
[2] https://pipedream.com/apps/semrush/integrations/python
[3] https://www.semrush.com/blog/how-to-track-keywords/
[4] https://www.semrush.com/kb/1191-track-your-rankings
[5] https://apix-drive.com/en/semrush-api