谷歌套件应用程序的数据科学家工具箱

pysuite的Python项目详细描述


pysuite:googlesuite应用程序的数据科学家工具箱

PyPi versionPyPi downloads

一个用于googlesuiteapi的python包装器。这为一些类提供了用户友好的api,以便与googlesuite一起操作 谷歌硬盘和谷歌电子表格等应用程序。在

获取凭据

你需要从 Google API Console。凭证看起来像:

{"installed":{"client_id":"xxxxxxxxxxxxxxxxx.apps.googleusercontent.com","project_id":"xxxxxxxxxxxxx-xxxxxxxxxxxx","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"xxxxxxxxxxxxxxxx","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}

如果可能,您还可以提供一个令牌json文件,令牌文件如下所示:

^{pr2}$

如果令牌文件不存在,则需要在浏览器提示下进行确认。然后将创建令牌文件。在

frompysuiteimportAuthenticationcredential_json_file="/tmp/credential.json"token_path_file="/tmp/token.json"client=Authentication(credential=credential_json_file,token=token_path_file,services="sheets")

认证

Authenticationblass可以帮助验证您的凭据并为API提供服务客户端。例如“驾驶”和 “床单”。在

frompysuiteimportAuthenticationcredential_file="./credentials/credentials.json"token_file="./credentials/token.json"drive_auth=Authentication(credential=credential_file,token=token_file,services="drive")sheets_auth=Authentication(credential=credential_file,token=token_file,services="sheets")

现在可以从身份验证对象生成gdrive客户端。在

service=drive_auth.get_service_client()# 'service' needed if not provided when initiating Authenciation object 

美国石油学会

API类的目的是提供对Google套件应用程序(如googledrive和Google电子表格)的快速简单访问。在

驱动

frompysuiteimportDrivedrive=Drive(service=drive_auth.get_service_client())# drive_auth is an Authenticaion class with `service='drive'`

如果您喜欢使用不同的方法来创建gdrive客户机,可以使用gdrive服务切换drive_auth.get_service() (详见Google Drive API V3):

service=build('drive','v3',credentials=creds)

一些示例API如下所示:

下载文件

drive.download(id="google drive object id",to_file="/tmp/test_file")

上传文件

drive.upload(from_file="path/to/your/file/to/be/uploaded",name="google_drive_file_name",parent_ids=["google drive folder id 1","google drive folder id 2"])

列出文件夹中的文件

list_of_objects=drive.list(id="google drive folder id")

frompysuiteimportSheetssheets=Sheets(service=sheets_auth.get_service_client())# sheets_auth is an Authenticaion class with `service='sheets'`

如果您喜欢使用不同的方法来创建gdrive客户机,可以使用gsheet服务切换sheets_auth.get_service() (详见Google Sheet API V4):

service=build('sheets','v4',credentials=creds,cache_discovery=True)

以下是一些例子:

上传熊猫数据帧

importpandasaspddf=pd.DataFrame({"col1":[1,2],"col2":['a','b']})sheets.to_sheet(df,id="your_sheet_id",sheet_range="yourtab!A1:B")

将工作表下载到dataframe

此api需要熊猫。在

df=sheets.read_sheet(id="your_sheet_id",sheet_range="yourtab!A1:D")

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaEclipseMars没有保存首选项   java梯度同步失败:原因:启动失败:   java如何从嵌套的JSON获取数据?   java如何判断可观察对象中的任何对象满足一个条件?   java将字符串转换为保持相同值的byte[]数组   java有没有办法绕过AuditingEntityListener为测试设置数据?   从/usr/share/java中解析linux JAR依赖关系   安卓 My java函数抛出nullpointerexception?   java Gradle使用正确版本的依赖项   JBoss和Java6中带注释的WebService中的web服务ClassCastException   java如何修复codename one中的简单逻辑错误?   java如何迭代矩阵的索引?   java如何在JPanel不可见时将其保存为图像?   java HashMap如何在Kotlin中实现MutableMap接口?   javascript如何在单击后加载特定片段?   EclipseJava为纳什均衡获取所有玩家/策略组合   JavaSpring:Web服务REST在JSON上产生双反斜杠   java为什么ServletContext#getRealPath(“/”)返回相对路径?   java当我的游戏应该重新启动时,我应该如何处理重置SurfaceView和线程?