Convert Google SpreadSheet document to CSV files
Project description
Google sheets to csv
An utility tool to download google sheets to csv files.
Install
As common python library you can use pip to get the latest stable release
pip install google-sheets-to-csv
Usage
The most accurate information will be available using gs-to-csv --help
::
gs-to-csv --help
usage: gs-to-csv [-h] [--service-account-credential-file SERVICE_ACCOUNT] [-f]
[-b BUFFER_LINES] [--logging-file LOGGING_FILE]
[--logging-level LOGGING_LEVEL]
[--logging-format LOGGING_FORMAT]
spreadsheet selector directory
Convert google spreadsheet sheets to csv
optional arguments:
-h, --help show this help message and exit
Converter options:
--service-account-credential-file SERVICE_ACCOUNT
If you want to use this command in a script without
user interractions, you can create a service account
from google console:
https://developers.google.com/workspace/guides/create-
credentials#create_a_service_account and share read
access sheets you want to export. (default: None)
-f, --force Tell this app tp overwrite existing files if present.
(default: False)
-b BUFFER_LINES, --buffer-lines BUFFER_LINES
Maximum number of lines to retreive by http calls.
(default: 500)
spreadsheet Id of the spreadsheet you want to export to csv.
Spreadsheet id is the weird data present in the uri
just after `d/`:
https://docs.google.com/spreadsheets/d/<the
spreadsheet id is here>/
selector Sheet selector is a regex expression to match sheets
titles. Some examples: - `.*`: would export all sheets
- `(abcd)|(efgh)`: would export abcd and efgh sheets
directory Output directory with write access where csv files
will bewritten.
Logging params:
--logging-file LOGGING_FILE
Logging configuration file, (logging-level and
logging-format are ignored if provide) (default: None)
--logging-level LOGGING_LEVEL
--logging-format LOGGING_FORMAT
This will create a .csv file per sheet with title match with the regex
expression.
Authentication
There are two ways to let this program access to your google sheets:
-
You can provide google service account credentials with
--service-account-credential-file
option. -
By default script will open your browser that let you authorize (or not) readonly access to all your Google Sheets documents to this application which is running on your computer. An authorization token will be saved in your home directory:
.gs-to-csv-token.json
(You can control that path usingGS_TO_CSV_TOKEN_FILE_PATH
env variable). You can watch following howto on youtube:
Behavior (limitations)
-
Google sheets API give a
columnCount
value which is a bit useless as we get extra cells. So for convenience this return, for each row, the same number of cells as the first line (expected header line!) which can result with empty lines or truncated data. -
lines without any values do not return blank line even in the middle of the sheet.
-
Using user account (with auth flow) has http call rate limit using an highest
--buffer-lines
option can counter part a bit this limitation.
Other solutions
using wget
- Share your spreadsheet using "Anyone with link can view".
- Then do a wget (or curl) with the download url, you'll find the
document_id
andsheet_id
in the url in your browser
$ wget --output-file="logs.csv" "https://docs.google.com/spreadsheets/d/<document_id>/export?format=csv&gid=<sheet_id>" -O "downloaded_content.csv"
The data will be in the file: downloaded_content.csv
-
pros:
- nothing special to install
-
cons:
- enable share link access on each spreadsheet
- get
sheet_id
for any sheets you want to download - use one command per sheet to export
Credits
Logo is derived from CSV File by Milinda Courey from the Noun Project
Changelog
- Major version introduce API change
- Minor version change behaviour
- Patch version are about released documentation or refactor or hotifx that do not meant to change previous numbers
Version 0.2
- The
.gs-to-csv-token.json
token file is create in read/write only for the current user.
Version 0.1
- Initial implementation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file google-sheets-to-csv-0.2.0.tar.gz
.
File metadata
- Download URL: google-sheets-to-csv-0.2.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1000f425873f26d84b5d2ff4fdbf829d0df51d1649442130a089f3a985c8d84 |
|
MD5 | e30e366bc736443b85cab57e79bc00d0 |
|
BLAKE2b-256 | cc764514c4f76c321efe848d9119ee7d28cddacd691edae4faebb98464cf9568 |
File details
Details for the file google_sheets_to_csv-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: google_sheets_to_csv-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfdc79f3b1e4a7bccbd5cf54fd0e8fa7341bae10432502ee25c5a8f32826ebd7 |
|
MD5 | ec1322949585a3f5756f285e8fe22380 |
|
BLAKE2b-256 | 687173c4012ceaa8c07647b8a93ad62abc931cedeac518b7ff9592a45a9d7ae8 |