Natural Language Client#

Basic client for Google Cloud Natural Language API.

class google.cloud.language.client.Client(credentials=None, http=None)[source]#

Bases: google.cloud.client.Client

Client to bundle configuration needed for API requests.

Parameters:
  • credentials (OAuth2Credentials) – (Optional) The OAuth2 Credentials to use for the connection owned by this client. If not passed (and if no http object is passed), falls back to the default inferred from the environment.
  • http (httplib2.Http or class that defines request().) – An optional HTTP object to make requests. If not passed, an http object is created that is bound to the credentials for the current object.
document_from_html(content, **kwargs)[source]#

Create an HTML document bound to this client.

Parameters:
  • content (str) – The document HTML text content.
  • kwargs (dict) – Remaining keyword arguments to be passed along to the Document constructor.
Return type:

Document

Returns:

An HTML document bound to this client.

Raises:

TypeError if doc_type is passed as a keyword argument.

document_from_text(content, **kwargs)[source]#

Create a plain text document bound to this client.

Parameters:
  • content (str) – The document plain text content.
  • kwargs (dict) – Remaining keyword arguments to be passed along to the Document constructor.
Return type:

Document

Returns:

A plain-text document bound to this client.

Raises:

TypeError if doc_type is passed as a keyword argument.

document_from_url(gcs_url, doc_type='PLAIN_TEXT', **kwargs)[source]#

Create a Cloud Storage document bound to this client.

Parameters:
  • gcs_url (str) – The URL of the Google Cloud Storage object holding the content. Of the form gs://{bucket}/{blob-name}.
  • doc_type (str) – (Optional) The type of text in the document. Defaults to plain text. Can also be specified as HTML via HTML.
  • kwargs (dict) – Remaining keyword arguments to be passed along to the Document constructor.
Return type:

Document

Returns:

A document bound to this client.

Connection#

Basic connection for Google Cloud Natural Language API.

class google.cloud.language.connection.Connection(credentials=None, http=None)[source]#

Bases: google.cloud.connection.JSONConnection

A connection to Google Cloud Natural Language JSON REST API.

API_BASE_URL = 'https://language.googleapis.com'#

The base of the API call URL.

API_URL_TEMPLATE = '{api_base_url}/{api_version}/documents:{path}'#

A template for the URL of a particular API call.

API_VERSION = 'v1beta1'#

The version of the API, used in building the API call’s URL.

SCOPE = ('https://www.googleapis.com/auth/cloud-platform',)#

The scopes required for authenticating as an API consumer.