Registry / gcp / google-cloud-language

google-cloud-language

JSON →
library2.21.0pypypi✓ verified 25d ago

The `google-cloud-language` library provides a Python client for the Google Cloud Natural Language API. It enables developers to perform sentiment analysis, entity analysis, entity sentiment analysis, content classification, and syntax analysis on text. This library is part of the larger `google-cloud-python` monorepo, meaning it receives regular updates and patches as part of Google Cloud's client library ecosystem, with frequent releases for individual services.

pip install google-cloud-language
INSTALL
IMPORT
SIG · GOOGLE-CLOUD-LANGU
G
google-cloud-language
gcppythonv2.21.0
Install
6.1s avg
Import
1355ms
Disk
69MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.21.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.576s · 70.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 6.1s · import 1.134s · 69MB
69MB installed
● package 69MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LanguageServiceClient
from google.cloud import language_v1
from google.cloud import language_v1

This quickstart demonstrates how to perform sentiment analysis using the `google-cloud-language` library. It initializes the client and sends a text document for sentiment detection. Ensure your Google Cloud project has the Natural Language API enabled and that you've set up authentication, preferably using Application Default Credentials, for local development or deployed applications.

import os from google.cloud import language_v1 # Set up Application Default Credentials if running locally # This line is usually not needed when running on Google Cloud services (e.g., Compute Engine, Cloud Run) # For local development, ensure GOOGLE_APPLICATION_CREDENTIALS points to a service account key file # or run `gcloud auth application-default login` # os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', '') def analyze_sentiment(text_content): """Analyzes the sentiment of the provided text.""" client = language_v1.LanguageServiceClient() # Available document types: PLAIN_TEXT, HTML document = language_v1.types.Document( content=text_content, type_=language_v1.Document.Type.PLAIN_TEXT ) # Detects the sentiment of the document sentiment = client.analyze_sentiment(request={'document': document}).document_sentiment print(f"Text: {text_content}") print(f"Sentiment Score: {sentiment.score}") print(f"Sentiment Magnitude: {sentiment.magnitude}") # Example usage if __name__ == '__main__': analyze_sentiment("Hello, world! This is a great day.") analyze_sentiment("I am very unhappy with the service.")
Debug
Known issues
breakingThe Natural Language API v2 introduces breaking changes, including renaming the `language` field to `language_code` in responses and removing fields like `salience` and `wikipedia_url` for entity analysis. Ensure you use the correct client (`language_v1` or `language_v2`) and adapt your code accordingly.
fix
For new projects or if you need v2 features, explicitly import `language_v2` (e.g., `from google.cloud import language_v2`). Review the v2 API documentation for specific field changes.
affects: API v2 (client library versions supporting v2, e.g., from `google.cloud import language_v2`)
gotchaDirect API Key authentication is generally not supported for Google Cloud client libraries. Attempting to use an API key might result in authentication errors.
fix
Use Application Default Credentials (ADC). For local development, run `gcloud auth application-default login` in your terminal. For deployed applications on Google Cloud, a service account attached to the resource is the preferred method.
affects: All versions
deprecatedThe direct import `from google.cloud.language import enums` is deprecated. Enums are now nested under the versioned types module (e.g., `language_v1.types.Document.Type`).
fix
Update imports to access enums directly via the versioned module, for example, `language_v1.Document.Type.PLAIN_TEXT`.
affects: Older versions allowed this; newer versions (2.0.0+) strongly encourage direct access via versioned `types`.
gotchaNaming your Python script `google.py`, `language.py`, or similar names can lead to import conflicts (shadowing) with the installed `google.cloud.language` library, causing `ImportError`.
fix
Always use distinct names for your local Python files that do not conflict with installed package names.
affects: All versions (Python-specific issue)
Upgrade
Version history
2.21.0latest on PyPI · released Jun 22, 2026
Audit
Dependencies
google-api-corerequiredCore library for Google API clients, handling common functionality like retries and API versioning.
google-authrequiredManages authentication with Google Cloud, typically via Application Default Credentials (ADC).
protobufrequiredUsed for serializing and deserializing API request and response data.
Agent activity
34 hits · last 30 days
node
28
OpenAI (training)
1
Resources
google-cloud-language — pip install google-cloud-language · libregistry