Skip to main content

tsd2gspread

A tool to write Time Series Data to Google Sheets, using gspread.

Requirement

  • Python 3.9 or later

Installation

$ pip install tsd2gspread

Preparation

Service account

Get a service account file (json) for Google APIs following Authentication — gspread 3.7.0 documentation.

Google Sheets

Tsd2Gspread can create new Google Sheets if you want.

Otherwise, you can use prepared Google Sheets.

To allow the service account to access the Sheet, go to the Sheet and share it with client_email from the above service account file.

Example

Use Tsd2Gspread directly

import tsd2gspread

tg = tsd2gspread.get(
    service_account='~/service_account.json',
    sheet_name='MySheet',
    create=1,
    worksheet_name='MyWork',
    columns='foo,bar,
    share='rcmdnk@gmail.com')

# Make function to get data
def get_data():
    foo = 1
    bar = 2
    return (foo, bar)

# Set data getter
tg.get_data = get_data

# Write Time Series Data to Google Sheets
tg.write()

This will make Google Sheets like:

Datetime foo bar
2021-04-30 12:34:56 1 2

Options for get:

Option Mean Default
config_file Configuration file of Tsd2Gspread. None
service_account Path for the service_account.json (Google API service_account file).
If None, tsd2gspread(gspread) will use ~/.config/gspread/service_account.json.
None
sheet_name If set, Sheet is searched by name. None
create If set to 1, new Sheet is created if it is not found by name.
Only works if sheet_name is not None
None
sheet_url If set, Sheet is searched by URL. None
sheet_key If set, Sheet is searched by key. None
worksheet_name Work sheet name. Tsd2Gspread
columns Column names separated by ,.
If set, the title like will be inserted when the sheet is created.
None
share Email address of your Google account.
If it is not set, only the service account can access to the Sheet and you can not see the Sheet from your account.
None
perm_type Ref API Reference - gspread: client.insert_permission user
perm_type Ref API Reference - gspread: client.insert_permission owner
add_datetime If set to 1, current time is added to the data as the first column. 1
timedelta The time offset from UTC. 0
timeformat The time format to be written. %Y-%m-%d %H:%M:%S
value_input_option USER_ENTERED or RAW. If add_datetime is 1, use USER_ENTERED to fill datetime value as datetime.
Ref API Reference - gspread:Wworksheet.append_row
USER_ENTERED

If you set options by the configuration file, write options as

OPTION=VALUE

and give the file name as config_file.

Make new inherited class from Tsd2Gspread

from tsd2gspread import Tsd2Gspread

class MyClass(Tsd2Gspread):
    def get_data(self):
        foo = 1
        bar = 2
        return (foo, bar)

tg = MyClass(
    service_account='~/service_account.json',
    sheet_name='MySheet',
    create=1,
    worksheet_name='MyWork',
    columns='foo,bar,
    share='rcmdnk@gmail.com')

# Write Time Series Data to Google Sheets
tg.write()

Metadata

Release files for tsd2gspread 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tsd2gspread 0.3.0
File Size Uploaded Provenance
tsd2gspread-0.3.0.tar.gz 73.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for tsd2gspread 0.3.0
File Interpreter ABI Platform
tsd2gspread-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 82.1 kB

Release files / tsd2gspread-0.3.0.tar.gz

Download URL tsd2gspread-0.3.0.tar.gz
Size 73.3 kB
Tags Source
SHA-256 checksum
How to use checksums
70a3f656fe48ea57b7d388a97d0f647ebbb0536260216418c4678e6c8b3486d6
BLAKE2b-256 checksum
How to use checksums
5eab5581ce477f64acb0e21bb0ce095a09a549ca80f002b131b31b46fbfe4db5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.14

Release files / tsd2gspread-0.3.0-py3-none-any.whl

Download URL tsd2gspread-0.3.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cfc8a74db39d779c6403dd4bdb30277c2b3390334f247355225c7ef61c1ed267
BLAKE2b-256 checksum
How to use checksums
bc9dec912b315940b684e321a83bae4cc30c5ffedf791c370f3976cc3629824b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.14

Security for tsd2gspread 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page