Vision Client#

Client#

Client for interacting with the Google Cloud Vision API.

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

Bases: google.cloud.client.JSONClient

Client to bundle configuration needed for API requests.

Parameters:
  • project (str) – the project which the client acts on behalf of. If not passed, falls back to the default inferred from the environment.
  • credentials (oauth2client.client.OAuth2Credentials or NoneType) – 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.
annotate(image, features)[source]#

Annotate an image to discover it’s attributes.

Parameters:
  • image (str) – A string which can be a URL, a Google Cloud Storage path, or a byte stream of the image.
  • features (list of Feature) –

    The type of detection that the Vision API should use to determine image attributes. Pricing is based on the number of Feature Types.

    See: https://cloud.google.com/vision/docs/pricing

Return type:

dict

Returns:

List of annotations.

image(content=None, source_uri=None)[source]#

Get instance of Image using current client.

Parameters:
  • content (bytes) – Byte stream of an image.
  • source_uri (str) – Google Cloud Storage URI of image.
Return type:

Image

Returns:

Image instance with the current client attached.

class google.cloud.vision.client.VisionRequest(image, features)[source]#

Bases: object

Request container with image and features information to annotate.

Parameters:
  • features (list of Feature.) – The features that dictate which annotations to run.
  • image (bytes) – Either Google Cloud Storage URI or raw byte stream of image.
as_dict()[source]#

Dictionary representation of Image.

features#

List of Feature objects.

image#

Image object containing image content.

Connection#

Create / interact with Google Cloud Vision connections.

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

Bases: google.cloud.connection.JSONConnection

A connection to Google Cloud Vision via the JSON REST API.

Parameters:
API_BASE_URL = 'https://vision.googleapis.com'#

The base of the API call URL.

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

A template for the URL of a particular API call.

API_VERSION = 'v1'#

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 a Cloud Vision consumer.