Package: omni-reports
Omni ReportsOmni Reports is a client to request, normalize and consolidate reports
from several platforms using a simple, declarative and concise request structure.
Behind the scenes, theOmni Report Clientwill convert the report definition into platform-specific
report requests.TheOmni Report Definitionis a json-like data structure based onGoogle Ads Report Definition,
accepting several elements to query and segment a report.InstallationTo installOmni Reports, usepip:pipinstallgit+https://github.com/paretogroup/omni-reports#egg=omni_reportsUsageCreate aReportTypeResolverto resolve report types of each platform (like Google Ads).
Then, create aReportClientand execute your report definition.fromomni_reports.clientimportReportClient,ReportTypeResolverBuilderfromomni_reports.google_reportsimportGoogleAdsReportTypeResolverresolver=ReportTypeResolverBuilder()\.extend(GoogleAdsReportTypeResolver)\.build()client=ReportClient(resolver)result=client.execute_report({'report_type':'GOOGLE_ADS_ACCOUNT_PERFORMANCE_REPORT','report_name':'my_report','selector':{'fields':['account_id','cost','conversions','cost_per_conversion'],'predicates':[{'field':'cost','operator':'greater_than','values':['0']}]}})print(result)Additionally, you can pass a context toReportClientso that aReportTypeResolvercan be configured.fromomni_reports.clientimportReportClientfromomni_reports.google_reportsimportGoogleAdsReportTypeResolverclient=ReportClient(GoogleAdsReportTypeResolver,{'GOOGLE_ADS_CLIENT_ID':'MY_CLIENT_ID','GOOGLE_ADS_CLIENT_SECRET':'MY_CLIENT_SECRET',})# or via `execute_report`report_definition={...}client.execute_report(report_definition,{'GOOGLE_ADS_CUSTOMER_ID':'MY_CUSTOMER_ID',})Creating a ReportTypeCreate aReportTypeinOmni Reportsis simple. Just create a new class extendingReportType, declare
the fields of your report type and implement the resolve method. TheReportClientwill validate all definitions of
your report type and call the resolver.To create your report type, you must declare all fields of report with its behaviors and metadata. There is three types
of behaviors: attribute, metric and segment.Attribute: The attribute fields must always reflect the current state of your data, ignoring the timespan of the report;Metric: The metric fields reflect the data over the timespan of the report;Segment: The segment field contains dimension data that is used to group metrics. Including a metric field into your
report definition may split a single row into multiple rows. The value of metric fields reflect the data over the timespan
of the report.After the identification of the behavior for each report type field, you can start declaring the report type class:fromomni_reports.clientimportReportClient,ReportTypeResolverBuilderfromomni_reports.client.typesimportReportTypefromomni_reports.client.fieldsimportAttributeReportField,MetricReportField,SegmentReportFieldclassMyAdReportType(ReportType):"""Example of ReportType to query perfomance of all accounts in platform"""account_id=SegmentReportField()campaign_id=SegmentReportField()ad_group_id=SegmentReportField()ad_id=SegmentReportField()cost=MetricReportField()conversions=MetricReportField()cost_per_conversion=MetricReportField()campaign_status=AttributeReportField()ad_group_status=AttributeReportField()ad_status=AttributeReportField()defresolve(self,fields,predicates,report_definition,context,client):# logic to apply predicates and filter fieldsreturn[]resolver=ReportTypeResolverBuilder()\.add_type("MY_AD_REPORT",MyAdReportType())\.build()client=ReportClient(resolver)client.execute_report({'report_type':'MY_AD_REPORT','report_name':'report_name_here','selector':{'fields':['ad_group_id','cost','conversions','cost_per_conversion'],'predicates':[{'field':'campaign_id','operator':'equals','values':['1234']}]}})ContributingTo contribute, see theCONTRIBUTINGguides.LicenseMIT