Giter VIP home page Giter VIP logo

datasheets's Introduction

datasheets

pip_versions travis_ci coveralls

datasheets is a library for interfacing with Google Sheets, including reading data from, writing data to, and modifying the formatting of Google Sheets. It is built on top of Google's google-api-python-client, google_auth, and google_auth_oauthlib libraries using the Google Drive v3 and Google Sheets v4 REST APIs.

It can be installed with pip via pip install datasheets.

Detailed information can be found in the documentation.

Basic Usage

Get the necessary OAuth credentials from the Google Developer Console as described in Getting OAuth Credentials.

After that, using datasheets looks like:

For further information, see the documentation.

License

Copyright 2018 Squarespace, INC.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

datasheets's People

Contributors

sl33t avatar zcmarine avatar zmarine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

datasheets's Issues

Switch to google-auth

The oauth2client library was deprecated by Google a bit over a year ago (see here). While the library still works fine within datasheets, it would be good to upgrade to Google's replacement, google-auth.

My expectation is that this transition shouldn't be too hard as we don't do anything very advanced with the oauth2client library, and a quick look at google-auth looks like the APIs will be very similar for the functionality that we do use.

cannot share sheet and transfer ownership

returned "The transferOwnership parameter must be enabled when the permission role is 'owner'.">

I would like to transfer ownership using the workbook.share method: workbook.share(email=email, role='owner', notify=True)

InvalidClientSecretsError for OAuth Client ID Access

Hi fellows,

I have been using datasheets with a Service Account for a while and it really works like a charm. For a different project, I was planning to use it differently, with a connection to my personal account directly. I thought that datasheets.Client() would prompt me to the Google Authentication page but I constantly ran into to the same error.

In [1]: import sys

In [2]: print(sys.version)
3.6.6 | packaged by conda-forge | (default, Jul 26 2018, 09:55:02)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]

In [3]: import datasheets

In [4]: datasheets.__version__
Out[4]: '0.1.3'

In [5]: datasheets.Client()
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
~/miniconda3/envs/deTech/lib/python3.6/site-packages/oauth2client/clientsecrets.py in _loadfile(filename)
    120     try:
--> 121         with open(filename, 'r') as fp:
    122             obj = json.load(fp)

FileNotFoundError: [Errno 2] No such file or directory: '/Users/PetitLepton/.datasheets/client_secrets.json'

During handling of the above exception, another exception occurred:

InvalidClientSecretsError                 Traceback (most recent call last)
<ipython-input-4-889d7823daf3> in <module>
----> 1 datasheets.Client()

~/miniconda3/envs/deTech/lib/python3.6/site-packages/datasheets/client.py in __init__(self, service, storage, user_agent)
     51         self.user_agent = user_agent
     52
---> 53         self.http = self._authenticate()
     54         self.drive_svc = apiclient.discovery.build('drive', 'v3', http=self.http)
     55         # Bind sheets_svc directly to .spreadsheets() as the API exposes no other functionality

~/miniconda3/envs/deTech/lib/python3.6/site-packages/datasheets/client.py in _authenticate(self)
     87             self.credentials = self._get_service_credentials()
     88         else:
---> 89             self.credentials = self._retrieve_client_credentials()
     90         return self.credentials.authorize(httplib2.Http())
     91

~/miniconda3/envs/deTech/lib/python3.6/site-packages/datasheets/client.py in _retrieve_client_credentials(self)
    123
    124         if not credentials or credentials.invalid:
--> 125             credentials = self._fetch_new_client_credentials(store)
    126
    127         self.email = credentials.id_token['email']

~/miniconda3/envs/deTech/lib/python3.6/site-packages/datasheets/client.py in _fetch_new_client_credentials(self, store)
    138         client_secrets_path = os.path.expanduser(unexpanded_client_secrets_path)
    139         scope = ('https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/userinfo.email')
--> 140         flow = oauth2client.client.flow_from_clientsecrets(client_secrets_path, scope=scope)
    141         flow.params['access_type'] = 'offline'  # Allow refreshing expired access tokens
    142         flow.user_agent = self.user_agent

~/miniconda3/envs/deTech/lib/python3.6/site-packages/oauth2client/_helpers.py in positional_wrapper(*args, **kwargs)
    131                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    132                     logger.warning(message)
--> 133             return wrapped(*args, **kwargs)
    134         return positional_wrapper
    135

~/miniconda3/envs/deTech/lib/python3.6/site-packages/oauth2client/client.py in flow_from_clientsecrets(filename, scope, redirect_uri, message, cache, login_hint, device_uri, pkce, code_verifier, prompt)
   2133     try:
   2134         client_type, client_info = clientsecrets.loadfile(filename,
-> 2135                                                           cache=cache)
   2136         if client_type in (clientsecrets.TYPE_WEB,
   2137                            clientsecrets.TYPE_INSTALLED):

~/miniconda3/envs/deTech/lib/python3.6/site-packages/oauth2client/clientsecrets.py in loadfile(filename, cache)
    163
    164     if not cache:
--> 165         return _loadfile(filename)
    166
    167     obj = cache.get(filename, namespace=_SECRET_NAMESPACE)

~/miniconda3/envs/deTech/lib/python3.6/site-packages/oauth2client/clientsecrets.py in _loadfile(filename)
    123     except IOError as exc:
    124         raise InvalidClientSecretsError('Error opening file', exc.filename,
--> 125                                         exc.strerror, exc.errno)
    126     return _validate_clientsecrets(obj)
    127

InvalidClientSecretsError: ('Error opening file', '/Users/PetitLepton/.datasheets/client_secrets.json', 'No such file or directory', 2)

I apparently misunderstood the behaviour since it is trying to open a secret file which, obviously does not exist.

Best regards,
Flavien.

client_credentials not downloading

Trying to use the OAuth Credentials. Have created the client_secrets.json and have both local hosts 8080 and 8888 set up, however it was throwing an error looking for 8081, so I added that one, but now is saying it can't find the client_credentials.json which the documentation says will be downloaded upon the first pass through. any insights on this issue would be greatly appreciated

Raspberry Pi module installation

I'm use datasheets on my Mac and have found it incredibly useful (thank you). I have a Raspberry Pi data collection project and just naturally turned to the datasheets module. After installing pandas, I tried installing (sudo pip install datasheets) datasheets but came across this error:

From pyans1.type import opentype
ImportError: Can not import name opentype

Opentype doesn't appear to be a python module on my Mac (i.e. pip list) so I wasn't clear what this dependency was implying. Any help you could shed would be appreciated!

Cannot import datasets

ImportError Traceback (most recent call last)

in ()
----> 1 import datasheets

/usr/local/lib/python3.5/dist-packages/datasheets/init.py in ()
11 """
12 from datasheets import exceptions
---> 13 from datasheets.client import Client
14 from datasheets.convenience import create_tab_in_new_workbook, create_tab_in_existing_workbook
15 from datasheets.helpers import convert_cell_index_to_label, convert_cell_label_to_index

/usr/local/lib/python3.5/dist-packages/datasheets/client.py in ()
8 import apiclient
9 import oauth2client
---> 10 from oauth2client.service_account import ServiceAccountCredentials
11 import pandas as pd
12

/usr/local/lib/python3.5/dist-packages/oauth2client/service_account.py in ()
24 from oauth2client import _helpers
25 from oauth2client import client
---> 26 from oauth2client import crypt
27 from oauth2client import transport
28

/usr/local/lib/python3.5/dist-packages/oauth2client/crypt.py in ()
21
22 from oauth2client import _helpers
---> 23 from oauth2client import _pure_python_crypt
24
25

/usr/local/lib/python3.5/dist-packages/oauth2client/_pure_python_crypt.py in ()
22 from pyasn1.codec.der import decoder
23 from pyasn1_modules import pem
---> 24 from pyasn1_modules.rfc2459 import Certificate
25 from pyasn1_modules.rfc5208 import PrivateKeyInfo
26 import rsa

/usr/local/lib/python3.5/dist-packages/pyasn1_modules/rfc2459.py in ()
18 from pyasn1.type import namedtype
19 from pyasn1.type import namedval
---> 20 from pyasn1.type import opentype
21 from pyasn1.type import tag
22 from pyasn1.type import univ

ImportError: cannot import name 'opentype'

I have tried upgrading the pyasn and pyasn1_modules library, but to no avail.

pip list | grep "google"

google-api-core (1.2.1)
google-api-python-client (1.7.4)
google-auth (1.5.0)
google-auth-httplib2 (0.0.3)
google-cloud-bigquery (1.3.0)
google-cloud-core (0.28.1)
google-resumable-media (0.3.1)
googleapis-common-protos (1.5.3)

pip list | grep "pyasn"

pyasn (1.6.0b1)
pyasn1 (0.4.3)
pyasn1-modules (0.2.2)

fetch_data error

Receiving KeyError message of 'errorValue' when fetching data from a worksheet tab and can't figure out what is causing this.
`---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
in ()
1 worksheet = workbook.fetch_tab(sheets[0])
----> 2 df = worksheet.fetch_data()
3 df.head()

~\AppData\Local\Continuum\anaconda3\lib\site-packages\datasheets\tab.py in fetch_data(self, headers, fmt)
444 raw_data = self.sheets_svc.get(spreadsheetId=self.workbook.file_id, ranges=self.tabname,
445 includeGridData=True, fields=fields).execute()
--> 446 processed_rows = self._process_rows(raw_data)
447
448 # filter out empty rows

~\AppData\Local\Continuum\anaconda3\lib\site-packages\datasheets\tab.py in _process_rows(raw_data)
89 cell_format = base_fmt
90
---> 91 formatting_fn = helpers._TYPE_CONVERSIONS[cell_format]
92 if cell_value:
93 try:

KeyError: 'errorValue'`

Add exponential backoff as an option when creating the client.

If you fire off a lot of requests at one time it is possible to go over the 100 requests in 100 seconds limit. Once it hits that limit datasheets throws an error. It should be possible to have datasheets retry by default using something like exponential backoff.

No files or workbooks found

I've set up a Google service account for a Google Drive folder and I'm able to instantiate the datasheets client using service=True. However, running fetch_workbooks_info and fetch_folders both return empty dataframes.

import datasheets
client = datasheets.Client(service=True)
client.fetch_workbooks_info()

Using Google's Drive API Explorer (linked from my datasheets Google project Dashboard), I'm able to see plenty of files in this Drive, so it shouldn't be an issue with the Drive. Somehow, datasheets isn't finding those files.

TypeError for `tab.fetch_data(headers=True)`

Hi there,

Thanks for the great library. I'm having an issue pulling tab data for a column with a header which is formatted as Date. The data looks like this:

day col1 col2
9/5/1976 1.23 2.34
12/3/1978 3.45 4.56
1/16/2020 5.67 6.78

The entire day column is formatted as Date. When I use the following command, I get the following error:

df = tab.fetch_data(headers=True)

TypeError: Mismatch exists in expected and actual data types for cell with value 'day'. Cell format is 'DATE' but cell value type is '<class 'str'>'. To correct this, in Google Sheets set the appropriate cell format or set it to Automatic

If I change the cell A1 to be a string, the dataframe loads, but the dtype is Object.

I would expect the headers=True flag to ignore the format of the value in the first row. Am I missing something?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.