Extracting Entities with Google Cloud Natural Language API in Python (Tutorial)
Processing customer reviews, feedback, or content at scale requires more than manual analysis—this production-ready Google Colab notebook provides working Python code to extract entities with sentiment scores from CSV files using Google Cloud’s Natural Language API. Created by Lazarina Stoy for MLforSEO.com, this isn’t just example code—it includes real-world considerations like API rate limiting (600 calls per minute), error handling for unsupported languages, and automated CSV export, making it immediately deployable for actual marketing and SEO projects that need to process hundreds or thousands of text documents.
The notebook walks through a complete batch processing workflow: upload a CSV file containing text content (reviews, articles, social media posts), authenticate with your Google Cloud API key, and let the script automatically process each row while respecting rate limits to avoid quota errors. For each piece of text, the API returns detected entities (people, places, organizations, products, etc.) along with their type, salience (importance to the text), sentiment scores (positive/negative), sentiment magnitude (strength of emotion), mention counts, and metadata. The code flattens this nested JSON response into a clean CSV with columns for every entity attribute, automatically handles rate limiting by tracking API calls and sleeping when necessary, and includes error handling that logs issues (like unsupported languages) without crashing the entire batch job.
Use this for:
‧ Batch processing customer reviews or feedback to extract mentioned products, features, or competitors with associated sentiment
‧ Analyzing large content libraries to identify frequently mentioned entities and understand how they’re perceived
‧ Building entity-based sentiment dashboards by extracting structured data from unstructured text at scale
‧ Creating topic authority maps by identifying which entities are most salient across your content corpus
‧ Competitive intelligence by extracting and analyzing entity mentions and sentiment from competitor content or industry discussions
‧ Quality control for content analysis by including mention counts and salience scores to filter noise from meaningful entity references
This is perfect for marketing analysts and SEO professionals who need to process large volumes of text data through Google Cloud Natural Language API with production-ready code that handles real-world constraints like rate limits, error cases, and data export—without building the infrastructure from scratch.
What’s Included
- Production-ready rate limiting logic automatically tracks API calls and enforces the 600 requests per minute quota to prevent failures during large batch jobs
- Comprehensive error handling gracefully manages issues like unsupported languages while continuing to process remaining rows
- Complete data extraction captures all entity attributes including type, salience, sentiment score/magnitude, mention counts, metadata, and specific mention text—all exported to analysis-ready CSV format
Created by
Introduction to Machine Learning for SEOs
This resource is part of a comprehensive course. Access the full curriculum and learning path.
View Full CourseRelated Concepts
Get Instant Access
Enter your email and we’ll send you the download link immediately.
