Skip to main content

Simple framework to create Google Spreadsheet with python

Project description

1) Create client_secret.json in Google APIs Console:
- Create new project in Google APIs Console(https://console.developers.google.com/iam-admin/projects);
- Open the Credentials page (https://console.developers.google.com/apis/credentials) and create new credentials Add credentials > OAuth 2.0 client ID;
- In 'Type of application' select 'Other types' and enter the name of client(for example 'Spreedsheet client') and press 'Create';
- Select your created client and download it like a JSON file;
- Rename json file to 'client_secret.json' and put it to your project dir
- Activate Google Drive API and Google Sheets API in Google Dev. Console (https://console.developers.google.com/apis/library)

2) Create an instance of an object:
- Import SpreadsheetWorker and PERMISSION_TYPES to your project
- Сreate an instance of the class SpreadsheetWorker and pass to him a path to your client_secret.json file as first argument. Then you can pass title spreadsheet, that will be created

!!!REMARK!!!: when you run creating of spreadsheet for the first time and accept agreement in your browser, may happen, that your spreadsheet will not created. To solve this problem, just run script again. This problem is connected with the creation of .credentials directory.

3) Import package:
from PythonGoogleSpreadsheet.PythonGoogleSpreadsheet import SpreadsheetWorker, PERMISSION_TYPES

Methods of python-google-spreadsheet:
- spreadsheet_constructor(output_data):
Create new Google Spreadsheet
If output_data not define, spreadsheet generator create new empty spreadsheet with access permission only for user, who allowed using his data for app (in browser). Else create new spreadsheet with access permission only for user, who allowed using his data for app (in browser) and data from output_data

:param output_data(non-requirement): <list> - data for recording to Spreadsheet (if not specified, spreadsheet will be create empty)
example:
output_data = [
['Iron Man', 'Tony Stark'],
[43, 1.75, 80],
['Just like his costume;-]']
]
:return: new spreadsheet id

- record_data(output_data, spreadsheet_id):
Record data to spreadsheet

:param output_data: <list> - data for recording to Spreadsheet
:param spreadsheet_id: <str> - id of modifying spreadsheet
:return: <dict> - response from Google

- get_spreadsheet_data(spreadsheet_id, sheet_name, sheet_range):
Get data from spreadsheet by sheet name and sheet range
!!!REMARK!!!: sheet_name must be consist of letters of the Latin alphabet

:param spreadsheet_id: <str> - id of modifying spreadsheet
:param sheet_name: <str> - name of sheet from which the data will be taken
:param sheet_range: <str> - range of columns(Example - 'A3:B10').
:return: <list> - array of values from selected sheet in spreadsheet

- add_permission(spreadsheet_id, permission_type, user_email):
Add new permission to spreadsheet with id spreadsheet_id

:param spreadsheet_id: <str> - spreadsheet id
:param permission_type: <str> - type of permission, that apply to the spreadsheet
:param user_email(non-requirement): <str> - email of user, to which is added permission
:return: response or None

- show_permissions(spreadsheet_id):
Show all permissions of selected spreadsheet (with id spreadsheet_id)

:param spreadsheet_id: <str> - spreadsheet id
:return: <dict> - permissions

- remove_permission(spreadsheet_id, permission_id):
Remove permission by id of permission

:param spreadsheet_id: <str> - spreadsheet id
:param permission_id: <str> - id of permission to delete(can get in from response of show_permission-method)
:return: ''

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spreadsheet_maker-1.0.tar.gz (5.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page