Skip to main content

Omni Reports

Omni Reports is a client to request, normalize and consolidate reports from several platforms using a simple, declarative and concise request structure. Behind the scenes, the Omni Report Client will convert the report definition into platform-specific report requests.

The Omni Report Definition is a json-like data structure based on Google Ads Report Definition, accepting several elements to query and segment a report.

Installation

To install Omni Reports, use pip:

pip install git+https://github.com/paretogroup/omni-reports#egg=omni_reports

Usage

Create a ReportTypeResolver to resolve report types of each platform (like Google Ads). Then, create a ReportClient and execute your report definition.

from omni_reports.client import ReportClient, ReportTypeResolverBuilder
from omni_reports.google_reports import GoogleAdsReportTypeResolver

resolver = 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 to ReportClient so that a ReportTypeResolver can be configured.

from omni_reports.client import ReportClient
from omni_reports.google_reports import GoogleAdsReportTypeResolver

client = 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 ReportType

Create a ReportType in Omni Reports is simple. Just create a new class extending ReportType, declare the fields of your report type and implement the resolve method. The ReportClient will 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:

from omni_reports.client import ReportClient, ReportTypeResolverBuilder
from omni_reports.client.types import ReportType
from omni_reports.client.fields import AttributeReportField, MetricReportField, SegmentReportField


class MyAdReportType(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()

    def resolve(self, fields, predicates, report_definition, context, client):
        # logic to apply predicates and filter fields
        return []

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']
            }
        ]
    }
})

Contributing

To contribute, see the CONTRIBUTING guides.

License

MIT

Release files for omni-reports 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for omni-reports 0.0.8
File Size Uploaded
omni_reports-0.0.8.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for omni-reports 0.0.8
File Interpreter ABI Platform
omni_reports-0.0.8-py2-none-any.whl Python 2 none any Details

Total release size:29.4 kB

Release files / omni_reports-0.0.8.tar.gz

Download URL omni_reports-0.0.8.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
39f4a1d3e4fc6245371dfe36e0366aebe14b242b12e1aac990872fcfb10234c5
BLAKE2b-256 checksum
How to use checksums
2bb131ab0629ff5f6eaee3ce3000e7195d34bbbac2ca7d43dcb1dd8eb7988195
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release files / omni_reports-0.0.8-py2-none-any.whl

Download URL omni_reports-0.0.8-py2-none-any.whl
Size 17.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
5d8e15f86e9d59b512c0602aa51f496ac80674a155c996ccb078e20b79a976e8
BLAKE2b-256 checksum
How to use checksums
b16e7277a061903cd6374ce755c2075ef5d34ccdeec193d97ed2d81089575cfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page