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 (Credentials) – (Optional) The OAuth2 Credentials to use for this client. If not passed (and if no http object is passed), falls back to the default inferred from the environment.
  • http (Http) – (Optional) HTTP object to make requests. Can be any object that defines request() with the same interface as request(). If not passed, an http object is created that is bound to the credentials for the current object.
SCOPE = ('https://www.googleapis.com/auth/cloud-platform',)#

The scopes required for authenticating as an API consumer.

document_from_gcs_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.

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(*args, **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.