Drive API itself does not offer a way to export a specific worksheet, but with a valid bearer token you can just download it in the desired format via its Google Drive url. The pattern is https://docs.google.com/spreadsheets/d/{{document_id}}/export?format=tsv&gid={{gid}}
. The document_id
and gid
are visiable in the browser URL bar when you open the sheet in Google Drive. Replace tsv
with whatever format you need.
I'm not good enough in Python, but I created a demo app in Node.js: git@github.com:joerx/drive-exporter.git. The general flow is:
- Obtain an access token via the Google APIs OAuth2 flow
- Figure out
sheet_id
and gid
- Construct download url
- Make a regular HTTP request passing the token as
Authorization: Bearer {{token}}
For public sheets you can skip the authorisation part.
General documentation for using Drive API and OAuth2 (with examples in Python) is here
If you need to programmatically determine the gid
, this might help: How to convert Google spreadsheet's worksheet string id to integer index (GID)?