自以为是的轻量级ETL管道框架

mara-google-sheet-downloader的Python项目详细描述


谷歌表格下载器

Build StatusPyPI - LicensePyPI versionSlack Status

此软件包包含一个google sheet downloader,用于mara ETL框架:

  • 将Google工作表下载到数据库表中
  • 可以在下载期间验证和格式化单元格

安装

要直接使用库,请使用pip:

pip install mara-google-sheet-downloader

或者

^{pr2}$

示例

这里有一个管道“gs_demo”,可以下载到一个表中。这假设您在 网址https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/edit。此工作表必须与 为其配置凭据的电子邮件地址(请参阅下文)。在

电子表格包含一个工作表“test”,其中包含以下列:

citysome_dateamountalready paid?pricecomments
Berlin01.01.20203ja2.3added by JK on 2020-03-12

请注意,它的开头不包含id列!在

frommara_pipelines.pipelinesimportPipeline,Taskfrommara_pipelines.commands.sqlimportExecuteSQLfrommara_google_sheet_downloader.mara_integrationimportDownloadGoogleSpreadsheetpipeline=Pipeline(id='gs_demo',description='A small pipeline that demonstrates the a google sheet download')pipeline.add(Task(id='download_',description='Download a google sheet',commands=[ExecuteSQL(sql_statement=f"""-- Creates the table where the google sheet data should end up inDROP TABLE IF EXISTS public.gs_test;CREATE TABLE public.gs_test (id BIGINT PRIMARY KEY,city TEXT,some_date DATE,amount INTEGER,is_paid BOOLEAN,price DOUBLE PRECISION,comments TEXT)""",echo_queries=False,),DownloadGoogleSpreadsheet(spreadsheet_key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',# from the URLworksheet_name='test',# worksheet# Validators:# c: counter (additional column, will start at 1 and count each row),# s: string,# d(in_fmt=%d.%m.%Y): date in YYYY.mm.dd format,# i: integer,# b(true:ja,false=nein): boolean with ja/nein interpreted as True/False,# f: float,# s: string# any cell which does not confirm to this spec will fail the import!columns_definition='csd(in_fmt=%d.%m.%Y)ib(true:ja,false=nein)fs',target_table_name='public.gs_test',# table where the data should end uptarget_db_alias='dwh',# alias of the DB where the data should end upskip_rows=1),# how many rows at the top should be skipped]),)

配置

下载程序需要OAuth2凭据,可以使用服务帐户或用户帐户。在

凭据将需要作用域'https://www.googleapis.com/auth/spreadsheets.readonly', 'https://www.googleapis.com/auth/drive.readonly'。在

用户帐户的OAuth2凭据示例:

frommara_app.monkey_patchimportpatchimportmara_google_sheet_downloader.configpatch(mara_google_sheet_downloader.config.gs_user_account_client_id)(lambda:"....client_id...")patch(mara_google_sheet_downloader.config.gs_user_account_client_secret)(lambda:"...client_secret...")patch(mara_google_sheet_downloader.config.gs_user_account_refresh_token)(lambda:"...initial_refresh_token...")

设置对要下载的图纸的访问权限

下载程序应该访问的所有工作表必须与与这些表相关联的电子邮件地址共享 资格证书。此电子邮件地址是:

  • 对于用户帐户凭据:创建凭据的用户的电子邮件地址。在
  • 对于服务帐户:服务帐户本身的电子邮件地址(例如“@”。iamcea.com网站"). 例如,该电子邮件地址包含在您可以下载的json文件中。在

命令行接口

这个软件包包含一个小型的cli应用程序,可以下载google工作表并将其输出为csv。在

您可以单独使用它,请参见python -m mara_google_sheet_downloader --help 了解如何使用它。在

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

推荐PyPI第三方库


热门话题
java数据未插入SQLite数据库   Java中内存有效的对象创建   java在方法内部使用“this”(不用于调用方法、构造函数或变量)   java为什么这里会出现NullPointerException?   在REST中使用HATEOAS导致的java循环依赖   java如何定制spring boot横幅?   Java数字基数计算器(即基数10到基数5)   如果在Kotlin vs Java中声明,用作全局上下文的安卓 MainApplication类将崩溃   用于过滤对象的Java lambda函数   java从字符串数组中获取整数列表   java为什么Maven找不到org。json JPMS自动模块?   java将字符串数组转换为int   仅当与阈值字节匹配时,java才会在映射中填充字符串值