tsd2gspread


Nametsd2gspread JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/rcmdnk/tsd2gspread
SummaryTime Series Data to Google Sheets
upload_time2024-01-28 05:15:49
maintainer
docs_urlNone
authorrcmdnk
requires_python>=3.7,<4.0
licenseApache-2.0
keywords api data google sheets spreadsheets
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # tsd2gspread
A tool to write Time Series Data to Google Sheets,
using [gspread](https://github.com/burnash/gspread).

# Requirement

* Python 3.6 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](https://gspread.readthedocs.io/en/latest/oauth2.html#for-bots-using-service-account).

## 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).<br> 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.<br>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.|`None`
columns|Column names separated by `,`.<br>If set, the title like will be inserted when the sheet is created.|`None`
share|Email address of your Google account. <br>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](https://gspread.readthedocs.io/en/latest/api.html): client.insert_permission |`user`
perm_type|Ref [API Reference - gspread](https://gspread.readthedocs.io/en/latest/api.html): 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|If `add_datetime` is 1, use `USER_ENTERED` to fill datetime value as datetime.<br>Ref [API Reference - gspread](https://gspread.readthedocs.io/en/latest/api.html):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()

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rcmdnk/tsd2gspread",
    "name": "tsd2gspread",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "API,Data,Google,Sheets,Spreadsheets",
    "author": "rcmdnk",
    "author_email": "rcmdnk@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b1/f7/60784d62a8e4d8ab616d510eae32d51849d3b6986c9bb627716aa9585d3a/tsd2gspread-0.2.0.tar.gz",
    "platform": null,
    "description": "# tsd2gspread\nA tool to write Time Series Data to Google Sheets,\nusing [gspread](https://github.com/burnash/gspread).\n\n# Requirement\n\n* Python 3.6 or later\n\n# Installation\n\n    $ pip install tsd2gspread\n\n# Preparation\n\n## Service account\n\nGet a service account file (json) for Google APIs following [Authentication \u2014 gspread 3.7.0 documentation](https://gspread.readthedocs.io/en/latest/oauth2.html#for-bots-using-service-account).\n\n## Google Sheets\n\nTsd2Gspread can create new Google Sheets if you want.\n\nOtherwise, you can use prepared Google Sheets.\n\nTo allow the service account to access the Sheet,\ngo to the Sheet and share it with `client_email` from the above service account file.\n\n# Example\n\n## Use Tsd2Gspread directly\n\n    import tsd2gspread\n\n    tg = tsd2gspread.get(\n        service_account='~/service_account.json',\n        sheet_name='MySheet',\n        create=1,\n        worksheet_name='MyWork',\n        columns='foo,bar,\n        share='rcmdnk@gmail.com')\n\n    # Make function to get data\n    def get_data():\n        foo = 1\n        bar = 2\n        return (foo, bar)\n\n    # Set data getter\n    tg.get_data = get_data\n\n    # Write Time Series Data to Google Sheets\n    tg.write()\n\nThis will make Google Sheets like:\n\nDatetime|foo|bar\n-|-|-\n2021-04-30 12:34:56|1|2\n\nOptions for `get`:\n\nOption|Mean|Default\n:-|:-|:-\nconfig_file|Configuration file of Tsd2Gspread.|None\nservice_account|Path for the **service_account.json** (Google API service_account file).<br> If  `None`, tsd2gspread(gspread) will use **~/.config/gspread/service_account.json**.|`None`\nsheet_name|If set, Sheet is searched by name.|`None`\ncreate|If set to 1, new Sheet is created if it is not found by name.<br>Only works if **sheet_name** is not `None`|`None`\nsheet_url|If set, Sheet is searched by URL.|`None`\nsheet_key|If set, Sheet is searched by key.|`None`\nworksheet_name|Work sheet name.|`None`\ncolumns|Column names separated by `,`.<br>If set, the title like will be inserted when the sheet is created.|`None`\nshare|Email address of your Google account. <br>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`\nperm_type|Ref [API Reference - gspread](https://gspread.readthedocs.io/en/latest/api.html): client.insert_permission |`user`\nperm_type|Ref [API Reference - gspread](https://gspread.readthedocs.io/en/latest/api.html): client.insert_permission|`owner`\nadd_datetime|If set to 1, current time is added to the data as the first column.|1\ntimedelta|The time offset from UTC.|0\ntimeformat|The time format to be written.|`%Y-%m-%d %H:%M:%S`\nvalue_input_option|If `add_datetime` is 1, use `USER_ENTERED` to fill datetime value as datetime.<br>Ref [API Reference - gspread](https://gspread.readthedocs.io/en/latest/api.html):Wworksheet.append_row|`USER_ENTERED`\n\n\nIf you set options by the configuration file, write options as\n\n    OPTION=VALUE\n\nand give the file name as `config_file`.\n\n## Make new inherited class from Tsd2Gspread\n\n    from tsd2gspread import Tsd2Gspread\n\n    class MyClass(Tsd2Gspread):\n        def get_data(self):\n            foo = 1\n            bar = 2\n            return (foo, bar)\n\n    tg = MyClass(\n        service_account='~/service_account.json',\n        sheet_name='MySheet',\n        create=1,\n        worksheet_name='MyWork',\n        columns='foo,bar,\n        share='rcmdnk@gmail.com')\n\n    # Write Time Series Data to Google Sheets\n    tg.write()\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Time Series Data to Google Sheets",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/rcmdnk/tsd2gspread",
        "Repository": "https://github.com/rcmdnk/tsd2gspread"
    },
    "split_keywords": [
        "api",
        "data",
        "google",
        "sheets",
        "spreadsheets"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1cbbff93a949259b478121e594f51e1b76bd27013528f10b4114f7419ced92ec",
                "md5": "27440c41843a40455cbfb24ccba4e79f",
                "sha256": "3bab8a5a86edb63d05d5075a93d585105fdae6ec8a1ed044f4a42bfe1f9ed9b2"
            },
            "downloads": -1,
            "filename": "tsd2gspread-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "27440c41843a40455cbfb24ccba4e79f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 8118,
            "upload_time": "2024-01-28T05:15:47",
            "upload_time_iso_8601": "2024-01-28T05:15:47.736526Z",
            "url": "https://files.pythonhosted.org/packages/1c/bb/ff93a949259b478121e594f51e1b76bd27013528f10b4114f7419ced92ec/tsd2gspread-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b1f760784d62a8e4d8ab616d510eae32d51849d3b6986c9bb627716aa9585d3a",
                "md5": "be1f86a46f100e0370c07dd387f27cde",
                "sha256": "fd01bf84a9ce11f569a730258e05d978bfe55e799e9db3989f74a5d585cb364d"
            },
            "downloads": -1,
            "filename": "tsd2gspread-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "be1f86a46f100e0370c07dd387f27cde",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 7624,
            "upload_time": "2024-01-28T05:15:49",
            "upload_time_iso_8601": "2024-01-28T05:15:49.610743Z",
            "url": "https://files.pythonhosted.org/packages/b1/f7/60784d62a8e4d8ab616d510eae32d51849d3b6986c9bb627716aa9585d3a/tsd2gspread-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-28 05:15:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rcmdnk",
    "github_project": "tsd2gspread",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "tsd2gspread"
}
        
Elapsed time: 0.18927s