Skip to content Skip to sidebar Skip to footer

Google Translate Api - Reading And Writing To Cloud Storage - Python

I'm using Google Translation API to translate a csv file with multiple columns and rows. The target language is english and the file has text in multiple languages. The code posted

Solution 1:

You could download the file from GCS and run your logic against the local (downloaded file) and then upload to another GCS bucket. Example:

Download file from "my-bucket" to /tmp

from google.cloud import storage

client = storage.Client()

bucket = client.get_bucket("my-bucket")
source_blob = bucket.blob("blob/path/file.csv")
new_file = "/tmp/file.csv"
download_blob = source_blob.download_to_filename(new_file)

After translating/running your code logic, upload to a bucket:

bucket = client.get_bucket('my-other-bucket')
blob= bucket.blob('myfile.csv')
blob.upload_from_filename('myfile.csv')

Post a Comment for "Google Translate Api - Reading And Writing To Cloud Storage - Python"