example/background_cloud_function.py
def demo_background_cloud_function(event, context):
    """
    This background cloud function counts the number of letters in a file.
    A cloud bucket event is expected as input.
    See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/functions/helloworld/main.py#L89

    Returns:
        None; the output is written to Stackdriver Logging
    """
    storage_client = storage.Client()

    file_name = event["name"]
    bucket_name = event["bucket"]

    with tempfile.TemporaryDirectory() as tmpdirname:
        # generate a random filename in tmpdirname
        local_file = Path(tmpdirname) / str(uuid.uuid4().hex)

        # retrieve the blob object from the bucket, and store it into the local_file
        blob = storage_client.bucket(bucket_name).get_blob(file_name)
        blob.download_to_filename(local_file.as_posix())

        # process the file
        number_of_letters = len(local_file.read_text())
        print(f"{file_name} contains {number_of_letters} letters")

    This background cloud function counts the number of letters in a file.
    A cloud bucket event is expected as input.
    See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/functions/helloworld/main.py#L89

    Returns:
        None; the output is written to Stackdriver Logging
    
This background cloud function counts the number of letters in a file.
A cloud bucket event is expected as input.
This background cloud function counts the number of letters in a file . A cloud bucket event is expected as input .
def demo_background_cloud_function(event, context):
    storage_client = storage.Client()
    file_name = event["name"]
    bucket_name = event["bucket"]
    with tempfile.TemporaryDirectory() as tmpdirname:
        local_file = Path(tmpdirname) / str(uuid.uuid4().hex)
        blob = storage_client.bucket(bucket_name).get_blob(file_name)
        blob.download_to_filename(local_file.as_posix())
        number_of_letters = len(local_file.read_text())
        print(f"{file_name} contains {number_of_letters} letters")
def demo_background_cloud_function ( event , context ) : storage_client = storage . Client ( ) file_name = event [ "name" ] bucket_name = event [ "bucket" ] with tempfile . TemporaryDirectory ( ) as tmpdirname : local_file = Path ( tmpdirname ) / str ( uuid . uuid4 ( ) . hex ) blob = storage_client . bucket ( bucket_name ) . get_blob ( file_name ) blob . download_to_filename ( local_file . as_posix ( ) ) number_of_letters = len ( local_file . read_text ( ) ) print ( f"{file_name} contains {number_of_letters} letters" )
This background cloud function counts the number of letters in a file.
This background cloud function counts the number of letters in a file .
"""
    This background cloud function counts the number of letters in a file.
    A cloud bucket event is expected as input.
    See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/functions/helloworld/main.py#L89

    Returns:
        None; the output is written to Stackdriver Logging
    """ # generate a random filename in tmpdirname # retrieve the blob object from the bucket, and store it into the local_file # process the file
None; the output is written to Stackdriver Logging
None ; the output is written to Stackdriver Logging
event
context