Accessing and using csv file from Cloud Storage in Cloud Run instance

I know how to download the file from cloud storage within the cloud run instance. But, I can’t find the syntax for reading the file in python. I’m looking to immediately convert the csv file into a pandas dataframe, just by using pd.read_csv('testing.csv'). So my personal code looks like,
download_blob(bucket_name, source_blob_name, 'testing.csv'). So shouldn’t I be able to do pd.read_csv('testing.csv') within the cloud run instance? When doing it this way, I keep getting an internal server when loading the page. It seems like a simple question, but I haven’t been able to find an example of it anywhere. Everything just downloads the file, I never see it used.



def download_blob(bucket_name, source_blob_name, destination_file_name):
    """Downloads a blob from the bucket."""
    # The ID of your GCS bucket
    # bucket_name = "your-bucket-name"

    # The ID of your GCS object
    # source_blob_name = "storage-object-name"

    # The path to which the file should be downloaded
    # destination_file_name = "local/path/to/file"

    storage_client = storage.Client()

    bucket = storage_client.bucket(bucket_name)

    # Construct a client side representation of a blob.
    # Note `Bucket.blob` differs from `Bucket.get_blob` as it doesn't retrieve
    # any content from Google Cloud Storage. As we don't need additional data,
    # using `Bucket.blob` is preferred here.
    blob = bucket.blob(source_blob_name)
    blob.download_to_filename(destination_file_name)

    print(
        "Downloaded storage object {} from bucket {} to local file {}.".format(
            source_blob_name, bucket_name, destination_file_name
        )
    )

Source: Python Questions

LEAVE A COMMENT