airflow.providers.google.cloud.hooks.vision

This module contains a Google Cloud Vision Hook.

Module Contents

Classes

NameDeterminer

Helper class to determine entity name.

CloudVisionHook

Hook for Google Cloud Vision APIs.

Attributes

ERR_DIFF_NAMES

ERR_UNABLE_TO_CREATE

airflow.providers.google.cloud.hooks.vision.ERR_DIFF_NAMES = Multiline-String[source]
Show Value
1The {label} name provided in the object ({explicit_name}) is different
2    than the name created from the input parameters ({constructed_name}). Please either:
3    1) Remove the {label} name,
4    2) Remove the location and {id_label} parameters,
5    3) Unify the {label} name and input parameters.
airflow.providers.google.cloud.hooks.vision.ERR_UNABLE_TO_CREATE = Multiline-String[source]
Show Value
1Unable to determine the {label} name. Please either set the name directly
2    in the {label} object or provide the `location` and `{id_label}` parameters.
class airflow.providers.google.cloud.hooks.vision.NameDeterminer(label: str, id_label: str, get_path: Callable[[str, str, str], str])[source]

Helper class to determine entity name.

get_entity_with_name(self, entity: Any, entity_id: Optional[str], location: Optional[str], project_id: str) Any[source]

Check if entity has the name attribute set: * If so, no action is taken.

  • If not, and the name can be constructed from other parameters provided, it is created and filled in

    the entity.

  • If both the entity's 'name' attribute is set and the name can be constructed from other parameters

    provided:

    • If they are the same - no action is taken

    • if they are different - an exception is thrown.

Parameters
  • entity (any) -- Entity

  • entity_id (str) -- Entity id

  • location (str) -- Location

  • project_id (str) -- The id of Google Cloud Vision project.

Returns

The same entity or entity with new name

Return type

str

Raises

AirflowException

class airflow.providers.google.cloud.hooks.vision.CloudVisionHook(gcp_conn_id: str = 'google_cloud_default', delegate_to: Optional[str] = None, impersonation_chain: Optional[Union[str, Sequence[str]]] = None)[source]

Bases: airflow.providers.google.common.hooks.base_google.GoogleBaseHook

Hook for Google Cloud Vision APIs.

All the methods in the hook where project_id is used must be called with keyword arguments rather than positional.

product_name_determiner[source]
product_set_name_determiner[source]
get_conn(self) google.cloud.vision_v1.ProductSearchClient[source]

Retrieves connection to Cloud Vision.

Returns

Google Cloud Vision client object.

Return type

google.cloud.vision_v1.ProductSearchClient

annotator_client(self) google.cloud.vision_v1.ImageAnnotatorClient[source]

Creates ImageAnnotatorClient.

Returns

Google Image Annotator client object.

Return type

google.cloud.vision_v1.ImageAnnotatorClient

create_product_set(self, location: str, product_set: Union[dict, google.cloud.vision_v1.types.ProductSet], project_id: str = PROVIDE_PROJECT_ID, product_set_id: Optional[str] = None, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ()) str[source]

For the documentation see: CloudVisionCreateProductSetOperator

get_product_set(self, location: str, product_set_id: str, project_id: str = PROVIDE_PROJECT_ID, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ()) dict[source]

For the documentation see: CloudVisionGetProductSetOperator

update_product_set(self, product_set: Union[dict, google.cloud.vision_v1.types.ProductSet], project_id: str = PROVIDE_PROJECT_ID, location: Optional[str] = None, product_set_id: Optional[str] = None, update_mask: Union[dict, google.cloud.vision_v1.types.FieldMask] = None, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ()) dict[source]

For the documentation see: CloudVisionUpdateProductSetOperator

delete_product_set(self, location: str, product_set_id: str, project_id: str = PROVIDE_PROJECT_ID, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ()) None[source]

For the documentation see: CloudVisionDeleteProductSetOperator

create_product(self, location: str, product: Union[dict, google.cloud.vision_v1.types.Product], project_id: str = PROVIDE_PROJECT_ID, product_id: Optional[str] = None, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())[source]

For the documentation see: CloudVisionCreateProductOperator

get_product(self, location: str, product_id: str, project_id: str = PROVIDE_PROJECT_ID, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())[source]

For the documentation see: CloudVisionGetProductOperator

update_product(self, product: Union[dict, google.cloud.vision_v1.types.Product], project_id: str = PROVIDE_PROJECT_ID, location: Optional[str] = None, product_id: Optional[str] = None, update_mask: Optional[Dict[str, google.cloud.vision_v1.types.FieldMask]] = None, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())[source]

For the documentation see: CloudVisionUpdateProductOperator

delete_product(self, location: str, product_id: str, project_id: str = PROVIDE_PROJECT_ID, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ()) None[source]

For the documentation see: CloudVisionDeleteProductOperator

create_reference_image(self, location: str, product_id: str, reference_image: Union[dict, google.cloud.vision_v1.types.ReferenceImage], project_id: str, reference_image_id: Optional[str] = None, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ()) str[source]

For the documentation see: CloudVisionCreateReferenceImageOperator

delete_reference_image(self, location: str, product_id: str, reference_image_id: str, project_id: str, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ()) dict[source]

For the documentation see: CloudVisionDeleteReferenceImageOperator

add_product_to_product_set(self, product_set_id: str, product_id: str, project_id: str, location: Optional[str] = None, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ()) None[source]

For the documentation see: CloudVisionAddProductToProductSetOperator

remove_product_from_product_set(self, product_set_id: str, product_id: str, project_id: str, location: Optional[str] = None, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ()) None[source]

For the documentation see: CloudVisionRemoveProductFromProductSetOperator

annotate_image(self, request: Union[dict, google.cloud.vision_v1.types.AnnotateImageRequest], retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None) Dict[source]

For the documentation see: CloudVisionImageAnnotateOperator

batch_annotate_images(self, requests: Union[List[dict], List[google.cloud.vision_v1.types.AnnotateImageRequest]], retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None) dict[source]

For the documentation see: CloudVisionImageAnnotateOperator

text_detection(self, image: Union[dict, google.cloud.vision_v1.types.Image], max_results: Optional[int] = None, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, additional_properties: Optional[Dict] = None) dict[source]

For the documentation see: CloudVisionDetectTextOperator

document_text_detection(self, image: Union[dict, google.cloud.vision_v1.types.Image], max_results: Optional[int] = None, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, additional_properties: Optional[dict] = None) dict[source]

For the documentation see: CloudVisionTextDetectOperator

label_detection(self, image: Union[dict, google.cloud.vision_v1.types.Image], max_results: Optional[int] = None, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, additional_properties: Optional[dict] = None) dict[source]

For the documentation see: CloudVisionDetectImageLabelsOperator

safe_search_detection(self, image: Union[dict, google.cloud.vision_v1.types.Image], max_results: Optional[int] = None, retry: Optional[google.api_core.retry.Retry] = None, timeout: Optional[float] = None, additional_properties: Optional[dict] = None) dict[source]

For the documentation see: CloudVisionDetectImageSafeSearchOperator

Was this entry helpful?