Easy wrapper for the Google Sheets API
Project description
Google Sheets Tools
G Sheets Tools
is a wrapper for the Google Sheets API that streamlines the process of moving data in and out of Sheets, especially for Pandas users. (I built this because I got tired of exporting and uploading .csv files.)
Before you install...
This package allows you to interface with your Google Sheets docs, but you still need to make a dummy Google App that runs the Sheets API to use it. It's easy! Here's how.
- Go to the Google Developers Console. Create a new app.
- Go to the Google API Library and find the Google Sheets API.
- Click "Enable"
- Go to the Credentials page, either through the provided link or the in the console sidebar.
- Follow the prompt to open the OAuth Consent Screen and name your app. (This is the only thing you need to do on this page!)
- Click "+ Create Credentials" at the top of the screen and select "OAuth client ID".
- Select "Desktop app" from the "Application type" menu and put whatever you like in "Name".
- You should now see your OAuth Client ID on the Credentials page.
- Click the arrow on the right side of the menu to download your credentials.
- Save them in your home directory!
Installation
To install with pip, run
pip install g_sheets_tools
You can also clone this repository and run python setup.py install
.
Basic Usage
Make a gSheet object:
Duplicate names are OK, Sheets automatically assigns unique ID's.
# pass a sheet id (the alphanumerical code from the sheet url) to load an existing spreadsheet
g = gSheet(sheet_id='1pMvgod2nteAIIRJbplMqkllLaXpK15_046Zz_82b4zg')
# pass a name to create a new spreadsheet
g = gSheet(name='new spreadsheet')
# pass nothing to create a new spreadsheet called 'Untitled"
g = gSheet()
Download data with a gSheet object:
Data ranges are formatted "Sheet Name!first cell:last cell".
# pass a data range
data = g.loadDataFromSheet('cities!A:Z')
Upload data with a gSheet object:
This overwrites data by default. Pass write_setting='append'
to preserve existing data.
# pass a dataframe and a destination
new_cities_df = pd.read_csv('new_cities.csv)
g.writeDataToSheet(new_cities_df, 'cities!A:Z')
Other Functions
# create a new sheet within the spreadsheet
g.createNewSheet('new sheet name')
# rename an existing sheet
g.renameSheet('current sheet name', 'new sheet name')
# delete a sheet
g.deleteSheet('sheet to delete')
Standalone Functions
There are standalone functions that allow you to quickly load and write data to a sheet without creating a gSheet
object
# create a new spreadsheet and write data to it
# this is flexible -- try passing it a dictionary of sheet name/data pairs!
quickSheet(data, new_spreadsheet_name, new_sheet_name)
# load data from a sheet
data = quickLoad(sheet_id, data_range)
# write data to a sheet
quickWrite(data, sheet_id, data_range)
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
Hashes for g_sheets_tools-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99fc2fd5012f38e083a8b4a6d8a58790756ea5e6713a8eeb48da3e15566c31f0 |
|
MD5 | 5c2100389aa015a51ec665a5ec2fcd12 |
|
BLAKE2b-256 | e3d3b5565a686bc33eb483db6bcf6c1908752ea630d7c71e891125ff5e60fe75 |