Python toolkit for running GA4 and Search Console reports in Colab/Notebooks and publishing results to Google Sheets, CSV, or BigQuery, with built-in retries and easy append/upsert.
Project description
megaton
Megaton is a Python toolkit for working with Google Analytics 4, Google Search Console, Google Sheets, and BigQuery from Notebooks with minimal code. It focuses on fast iteration during analysis and provides a UX tailored for Notebook workflows.
Core Concepts
- Result objects — Method chaining via
SearchResult/ReportResult - Simple flow — Open → Set dates → Run → Save
- Notebook-first — Designed for inspecting intermediate results at every step
Quick Start
Prerequisites
You need a Google Cloud service account JSON file with access to GA4, Search Console, or Sheets. See Google Cloud docs for how to create one.
Install
pip install megaton
Run a GA4 report and save to Google Sheets
from megaton.start import Megaton
mg = Megaton("/path/to/service_account.json")
# GA4: fetch event data
mg.report.set.dates("2024-01-01", "2024-01-31")
result = mg.report.run(d=["date", "eventName"], m=["eventCount"])
# Save to Google Sheets
mg.open.sheet("https://docs.google.com/spreadsheets/d/...")
mg.save.to.sheet("_ga_data", result.df)
Run the same report over multiple date ranges
df = mg.report.run.ranges(
date_ranges=[("2024-01-01", "2024-01-31"), ("2025-01-01", "2025-01-31")],
d=["date", "eventName"],
m=["eventCount"],
)
Read a worksheet as DataFrame
mg.open.sheet("https://docs.google.com/spreadsheets/d/...")
daily_df = mg.sheets.read("daily")
Duplicate a worksheet and patch a cell
mg.open.sheet("https://docs.google.com/spreadsheets/d/...")
mg.sheets.duplicate(
"template",
"report_2024_02",
cell_update={"cell": "B1", "value": "202402"},
)
Search Console with method chaining
# query_map: dict mapping regex patterns to category names
# e.g. {"brand.*keyword": "Brand", ".*": "(other)"}
result = (mg.search
.run(dimensions=['query', 'page'], clean=True)
.categorize('query', by=query_map)
.filter_impressions(min=100)
)
mg.save.to.sheet('_query', result.df, sort_by='impressions')
Installation
# From PyPI
pip install megaton
# Latest from GitHub
pip install git+https://github.com/mak00s/megaton.git
Documentation
Note: Detailed docs are written in Japanese.
If you're new, start with the cookbook for practical examples, then refer to the API reference for details.
| Doc | Description |
|---|---|
| cookbook.md | Practical recipes — start here |
| api-reference.md | Full API reference (single source of truth) |
| cheatsheet.md | One-line quick reference |
| design.md | Design philosophy and trade-offs |
Testing & Coverage
pytest --cov=megaton --cov-report=term-missing
- Coverage tracking excludes
megaton/ga3.py. - Rationale: GA3 (Universal Analytics) is a legacy compatibility module and is outside the active quality gate for current GA4/Search Console workflows.
Changelog
- CHANGELOG.md
- docs/changelog-archive.md — 0.x series history
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file megaton-1.1.0.tar.gz.
File metadata
- Download URL: megaton-1.1.0.tar.gz
- Upload date:
- Size: 143.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6cb6f44defd6276b1aa0be1bf0967ccaef6d6d4bdc8bd53e23a4f03f57ce465
|
|
| MD5 |
536caa936ee686fac1b074e8b3332289
|
|
| BLAKE2b-256 |
53979d6847a40932c5c4a8da598a829fa8bd5baddee025d2104930fded811fdb
|
File details
Details for the file megaton-1.1.0-py3-none-any.whl.
File metadata
- Download URL: megaton-1.1.0-py3-none-any.whl
- Upload date:
- Size: 96.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfedb141705d3fef577fd51b851f882398ad58bb30f70f46799ac899894f0526
|
|
| MD5 |
5c8c76150d3fb46210668e615a0d6b85
|
|
| BLAKE2b-256 |
f8b88ea354eabd2154449136e482ea9af5afac043589af9eb1a34cad672e7967
|