Extracting Entities with Google Cloud Natural Language API in Python (Tutorial)
ForEntity SEO
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
Where this resource is used on MLforSEO
Used in the course
Walkthroughs on the blog
More entity SEO resources
- No-Code TemplateEntity Analysis with Google Cloud Natural Language API (No-Code Template)
- Coding Script or NotebookIBM Watson NLU Complete API Implementation Template for Multi-Feature Text Analysis (Notebook)
- Coding Script or NotebookAdvanced Entity Analysis with Multiple ML Techniques for Semantic Keyword Research
- GuideEntity & Sentiment Analysis APIs: Comparative Review
- Coding Script or NotebookEntity Analysis & Relationship Mapping with IBM Watson NLU in Google Colab
- GuideComplete Guide to Entity Extraction & Sentiment Analysis: Marketing and SEO Use Cases
See all 18 entity SEO resources →See all 42 coding script or notebook resources →
