airflow.providers.google.cloud.hooks.vision

This module contains a Google Cloud Vision Hook.

Module Contents

airflow.providers.google.cloud.hooks.vision.ERR_DIFF_NAMES = The {label} name provided in the object ({explicit_name}) is different than the name created from the input parameters ({constructed_name}). Please either: 1) Remove the {label} name, 2) Remove the location and {id_label} parameters, 3) Unify the {label} name and input parameters.[source]
airflow.providers.google.cloud.hooks.vision.ERR_UNABLE_TO_CREATE = Unable to determine the {label} name. Please either set the name directly in the {label} object or provide the `location` and `{id_label}` parameters.[source]
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)[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)[source]

Retrieves connection to Cloud Vision.

Returns

Google Cloud Vision client object.

Return type

google.cloud.vision_v1.ProductSearchClient

annotator_client(self)[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, ProductSet], project_id: str, product_set_id: Optional[str] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]

For the documentation see: CloudVisionCreateProductSetOperator

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

For the documentation see: CloudVisionGetProductSetOperator

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

For the documentation see: CloudVisionUpdateProductSetOperator

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

For the documentation see: CloudVisionDeleteProductSetOperator

create_product(self, location: str, product: Union[dict, Product], project_id: str, product_id: Optional[str] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]

For the documentation see: CloudVisionCreateProductOperator

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

For the documentation see: CloudVisionGetProductOperator

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

For the documentation see: CloudVisionUpdateProductOperator

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

For the documentation see: CloudVisionDeleteProductOperator

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

For the documentation see: CloudVisionCreateReferenceImageOperator

delete_reference_image(self, location: str, product_id: str, reference_image_id: str, project_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[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[Retry] = None, timeout: Optional[float] = None, metadata: Optional[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[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]

For the documentation see: CloudVisionRemoveProductFromProductSetOperator

annotate_image(self, request: Union[dict, AnnotateImageRequest], retry: Optional[Retry] = None, timeout: Optional[float] = None)[source]

For the documentation see: CloudVisionImageAnnotateOperator

batch_annotate_images(self, requests: Union[List[dict], List[AnnotateImageRequest]], retry: Optional[Retry] = None, timeout: Optional[float] = None)[source]

For the documentation see: CloudVisionImageAnnotateOperator

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

For the documentation see: CloudVisionDetectTextOperator

document_text_detection(self, image: Union[dict, Image], max_results: Optional[int] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, additional_properties: Optional[dict] = None)[source]

For the documentation see: CloudVisionTextDetectOperator

label_detection(self, image: Union[dict, Image], max_results: Optional[int] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, additional_properties: Optional[dict] = None)[source]

For the documentation see: CloudVisionDetectImageLabelsOperator

safe_search_detection(self, image: Union[dict, Image], max_results: Optional[int] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, additional_properties: Optional[dict] = None)[source]

For the documentation see: CloudVisionDetectImageSafeSearchOperator

Was this entry helpful?