Google Drive
Connect your Google account to browse and read files directly in Fused UDFs using gdrive:// paths. No credentials are stored client-side — Fused manages the OAuth token on your behalf.
Setup
1. Connect Google Drive
Open Integrations & Secrets in Workbench and click Connect Google Drive.
Complete the Google OAuth consent screen. Once connected, the panel shows your account name and a Connected status.
2. Grant file and folder access via the Picker
Fused uses the drive.file scope — it can only access files and folders you explicitly grant through the Choose files and folders picker in Workbench. Files added to Drive after the initial grant will not appear until re-granted via the Picker.
gdrive:// path format
gdrive://root/ # all Picker-granted files at root
gdrive://<folder_id>/<folder_name>/ # a specific folder (trailing slash)
gdrive://<file_id>/<filename> # a specific file
The first segment after gdrive:// is always the Drive object ID. The name that follows is decorative and ignored at read time. To find file and folder IDs, use the List files example below — it returns each item's full gdrive://<id>/<name> path so IDs are always visible.
Examples
List files in a UDF
@fused.udf
def udf():
import pandas as pd
items = fused.api.list("gdrive://root/")
rows = []
for item in items:
stripped = item.replace("gdrive://", "").rstrip("/")
item_id, item_name = stripped.split("/", 1)
rows.append({"id": item_id, "name": item_name, "is_dir": item.endswith("/")})
return pd.DataFrame(rows)
Read a CSV or Excel file
Use pandas directly with the gdrive:// path — no manual download needed:
@fused.udf
def udf():
import pandas as pd
return pd.read_csv("gdrive://<file_id>/<name>.csv")
@fused.udf
def udf():
import pandas as pd
return pd.read_excel("gdrive://<file_id>/<name>.xlsx")
Read binary files
Use fused.api.get() which returns raw bytes:
@fused.udf
def udf():
import io
data = fused.api.get("gdrive://<file_id>/<name>.png")
# wrap in io.BytesIO for libraries that need a file-like object
Read Google-native formats
Google Docs, Sheets, and Slides are automatically exported on read:
| Google format | Exported as |
|---|---|
| Google Sheets | .xlsx |
| Google Docs | .docx |
| Google Slides | .pptx |
| Google Drawings | .png |
Upload a file to Google Drive from a URL
@fused.udf
def udf(url: str = "https://example.com/data.csv", folder_id: str = "root"):
import io, urllib.request, requests, pandas as pd
file_name = url.split("?")[0].rstrip("/").split("/")[-1] or "upload.csv"
with urllib.request.urlopen(url) as resp:
data = resp.read()
api = fused.api.api
creds = api.AUTHORIZATION.credentials
r = requests.put(
f"{api.OPTIONS.base_url}/files/upload",
params={"path": f"gdrive://{folder_id}/{file_name}"},
data=data,
headers={
"Authorization": f"Bearer {creds.access_token}",
"Content-Type": "application/octet-stream",
},
)
r.raise_for_status()
buf = io.BytesIO(data)
return pd.read_csv(buf) if file_name.lower().endswith(".csv") else pd.read_excel(buf)
Download a file
Fetch a file's raw bytes and encode it as a data URI to use directly in a widget:
@fused.udf
def udf(gdrive_path: str = "gdrive://<file_id>/<name>.jpg"):
import base64, mimetypes, pandas as pd
data = fused.api.get(gdrive_path)
file_name = gdrive_path.split("/")[-1]
mime, _ = mimetypes.guess_type(file_name)
data_uri = f"data:{mime or 'application/octet-stream'};base64,{base64.b64encode(data).decode()}"
return pd.DataFrame([{"file": file_name, "data_uri": data_uri}])