google api helper for vedavaapi project
Project description
helper package to interface with required google api services. It is completely independent package for generic usage.
Install
install it from PyPi
pip install google-services-helper
or run python setup.py install from project root
example-usage
from vedavaapi.google_helper.gsheets import GSheets
from vedavaapi.google_helper.gdrive import GDrive
credentials_file_path = 'path/to/credentials.json'
scopes = ['https://www.googleapis.com/auth/drive.readonly', 'https://www.googleapis.com/auth/spreadsheets.readonly']
#get instance of GSheets helper class, from our credentials.
gsheets_helper = GSheets.from_creds_file(credentials_file_path, scopes)
#now use it to access data in our required valuesFormat with header row mapping, etc.
#we can provide only desired customized parameters in 'pargs' dictionary parameter. if no custom 'fields' are choosen in pargs, then all fields will be returned. if no range mentioned, all sheet values will be returned.
vakyas_sheet_values, statuscode = gsheets_helper.sheet_values_for(spreadsheet_id='someGooGleSheetId',sheet_id='Vakyas', pargs={'idType':'title', 'valuesFormat':'maps', 'fields':['Vakya_id', 'Tantrayukti_tag', 'Vakya'], 'range':'1:27'} )
#get instance of GDrive helper class, from our credentials.
gdrive_helper = GDrive.from_creds_file(credentials_file, scopes)
#now use it to retrieve spreadsheet files details in a google drive folder
list_of_files_in_folder, status_code = gdrive_helper.list_of_files_in_folder(folder_id='bJUyfjaitxkzsl_jagkkahajru2acd', mime_types=['application/vnd.google-apps.spreadsheet'], additional_pargs={'orderBy':'recency'})
above code just passes a credentials.json file and, get a GSheets/GDrive object. with these helper objects we query sheets/drive, etc, with their methods. But if we don't have credentials.json file(it represents owner's authorisation grant to our application), then we have to generate one from our application's client_secret.json file we get from google api console.(this client_secret.json is like id of our app.). in this case resource user, and application owner is same. we have to grant our app permission to access our files. for that fallow below. once credentials.json is there, no need of this.
from vedavaapi.google_helper.oauth import Authorizer
authorizer = Authorizer(client_secret_path='path/to/client_secret.json', credentials_storage_path='path/to/credentials.json', scopes=['https://www.googleapis.com/auth/drive.readonly', 'https://www.googleapis.com/auth/spreadsheets.readonly'])
authorizer.authorize() #this will redirect us to web browser, and after completion of authorisation credentials will be stored at given path. we can use these credentials and start using helper packages like above.
and there is a factory class too, which creates and returns above helper objects from single credentials, and make interlinking them a lot simpler.
from vedavaapi.google_helper import GServices #our factory class
gservices = GServices.from_creds_file('/path/to/credentialsfile', scopes=scopes) #instantiate a wrapper factory.
#now get required helpers for those credentials from helper factory.
gsheets = gservices.gsheets(enable_drive_service_linking=True) #all arguments are optional.
gdrive = gservices.gdrive()
#then use above helper objects like before.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file google-services-helper-1.0.3.tar.gz
.
File metadata
- Download URL: google-services-helper-1.0.3.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11b1543b7c7294ab4161d4dc8ecaf3f8c8f2386a1e1a1746f2ef1361f9cfc275 |
|
MD5 | 1ed930466c82389ee01b91df140cb963 |
|
BLAKE2b-256 | c56fdb7511d33bb0a7ceed026dcdb73ff5822225ac142eedbf1a2db2fdb69606 |
File details
Details for the file google_services_helper-1.0.3-py3.6.egg
.
File metadata
- Download URL: google_services_helper-1.0.3-py3.6.egg
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b2a212dbd41b8d2ebfa53a613e81164e7a348ed613a2acd0ccb640616bd83c0 |
|
MD5 | 7ee94b14c3669e85283f351c4838d593 |
|
BLAKE2b-256 | 40ecff3c86bd1af85edd29f23ad74f6ffd85e88af8c9b5119fc47b0572e32811 |
File details
Details for the file google_services_helper-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: google_services_helper-1.0.3-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e8c37aefd5d278fb6853ce8090062efffa0951809d51deb14fe47d89197783d |
|
MD5 | 7d47008b16b83ff9bea1f4eb9be00df2 |
|
BLAKE2b-256 | b1e1ac638c4752db133e2311218c2e08b834d988073b22a5b36e46ab026e8c8f |
File details
Details for the file google_services_helper-1.0.3-py2-none-any.whl
.
File metadata
- Download URL: google_services_helper-1.0.3-py2-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00551dd5759f6ead33f1edabda5111533e60f2b58c7364af42465bb332cc2173 |
|
MD5 | a8d906643737422ec06b55f05fc9ef86 |
|
BLAKE2b-256 | 6257ffd53b96e31e500a1aca6277f88395e077e5b9729baf1b2951c04d9b1247 |