adstack 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. adstack-0.2.0/CHANGELOG.md +58 -0
  2. adstack-0.2.0/CONTRIBUTING.md +74 -0
  3. adstack-0.2.0/LICENSE +177 -0
  4. adstack-0.2.0/MANIFEST.in +6 -0
  5. adstack-0.2.0/PKG-INFO +235 -0
  6. adstack-0.2.0/README.md +198 -0
  7. adstack-0.2.0/SECURITY.md +28 -0
  8. adstack-0.2.0/adstack/__init__.py +3 -0
  9. adstack-0.2.0/adstack/__main__.py +3 -0
  10. adstack-0.2.0/adstack/cli.py +476 -0
  11. adstack-0.2.0/adstack/config.py +141 -0
  12. adstack-0.2.0/adstack/engine.py +178 -0
  13. adstack-0.2.0/adstack/errors.py +17 -0
  14. adstack-0.2.0/adstack/mcp_server.py +330 -0
  15. adstack-0.2.0/adstack/plan.py +177 -0
  16. adstack-0.2.0/adstack/providers/__init__.py +23 -0
  17. adstack-0.2.0/adstack/providers/base.py +62 -0
  18. adstack-0.2.0/adstack/providers/google_ads/__init__.py +40 -0
  19. adstack-0.2.0/adstack/providers/google_ads/api.py +342 -0
  20. adstack-0.2.0/adstack/providers/google_ads/planner.py +710 -0
  21. adstack-0.2.0/adstack/providers/google_ads/sandbox.py +342 -0
  22. adstack-0.2.0/adstack/providers/google_ads/schema.py +258 -0
  23. adstack-0.2.0/adstack/scaffold.py +44 -0
  24. adstack-0.2.0/adstack/validation.py +82 -0
  25. adstack-0.2.0/adstack.egg-info/PKG-INFO +235 -0
  26. adstack-0.2.0/adstack.egg-info/SOURCES.txt +46 -0
  27. adstack-0.2.0/adstack.egg-info/dependency_links.txt +1 -0
  28. adstack-0.2.0/adstack.egg-info/entry_points.txt +2 -0
  29. adstack-0.2.0/adstack.egg-info/requires.txt +11 -0
  30. adstack-0.2.0/adstack.egg-info/top_level.txt +1 -0
  31. adstack-0.2.0/docs/configuration.md +143 -0
  32. adstack-0.2.0/docs/how-it-works.md +95 -0
  33. adstack-0.2.0/docs/mcp.md +76 -0
  34. adstack-0.2.0/examples/multi-file/brand.yaml +13 -0
  35. adstack-0.2.0/examples/multi-file/provider.yaml +11 -0
  36. adstack-0.2.0/examples/multi-file/subscriptions.yaml +30 -0
  37. adstack-0.2.0/examples/multi-file/templates.yaml +22 -0
  38. adstack-0.2.0/examples/quickstart/adstack.yaml +44 -0
  39. adstack-0.2.0/pyproject.toml +59 -0
  40. adstack-0.2.0/setup.cfg +4 -0
  41. adstack-0.2.0/tests/conftest.py +78 -0
  42. adstack-0.2.0/tests/test_cli.py +141 -0
  43. adstack-0.2.0/tests/test_config.py +147 -0
  44. adstack-0.2.0/tests/test_engine.py +98 -0
  45. adstack-0.2.0/tests/test_google_ads_api.py +248 -0
  46. adstack-0.2.0/tests/test_google_ads_planner.py +216 -0
  47. adstack-0.2.0/tests/test_mcp.py +141 -0
  48. adstack-0.2.0/tests/test_sandbox.py +87 -0
@@ -0,0 +1,58 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 (2026-11-26)
4
+
5
+ The first release on PyPI. Adstack is now a general-purpose, open-source tool with a Terraform-style workflow and an MCP server.
6
+
7
+ ### Added
8
+
9
+ - `adstack` command with `init`, `validate`, `plan`, `apply`, `destroy`, `show`, `state list`, `report`, `mcp` and `version`.
10
+ - `plan --out` saves a self-contained plan. It embeds its configuration, so `apply PLAN_FILE` needs no configuration files, and it is recomputed and refused if anything changed. `plan --detailed-exitcode` exits 2 when there are changes; `plan --json` and `show --json` print machine-readable plans.
11
+ - `apply` without a plan file plans and then asks for approval (`yes`), or proceeds with `--auto-approve`.
12
+ - `destroy` pauses every campaign in the namespace. Adstack still never deletes campaigns.
13
+ - Several campaigns per configuration, and configurations split across the YAML files in a directory.
14
+ - Campaigns that are in the namespace but no longer configured block the plan until it is pruned (`--prune` pauses them).
15
+ - A local sandbox account (`--sandbox`) for trying configurations, plans and the MCP server without an ad account.
16
+ - MCP server (`adstack mcp`): `validate`, `plan`, `show_plan`, `state`, `report`, `example_config`, and `apply` when the server uses the sandbox or runs with `--allow-apply`.
17
+ - Receipts are written automatically to `.adstack/receipts/` after every apply.
18
+ - A provider interface, so ad platforms other than Google Ads can be added.
19
+ - Inline ads in ad groups (`ad:`) as an alternative to `ad_template`.
20
+ - `provider.google_ads.customer_id` and `login_customer_id` can pin the account in the configuration.
21
+ - Configurable `limits` for budgets and bids.
22
+ - Terraform-style plan output, grouped by campaign and ad group, with color when the output is a terminal.
23
+
24
+ ### Changed
25
+
26
+ - The project is no longer tied to one advertiser: the advertiser-specific example was replaced by fictional ones.
27
+ - The command is `adstack` (was `ads`), and the package is `adstack` (was `adstack-cli`).
28
+ - New configuration layout: `namespace` and `currency` moved into `provider.google_ads`, and `campaign` became the list `campaigns`. See below.
29
+ - Managed names start with `adstack:` (was `aac:`).
30
+ - Environment variables are named like Google's client libraries: `GOOGLE_ADS_CUSTOMER_ID`, `GOOGLE_ADS_LOGIN_CUSTOMER_ID`, `GOOGLE_ADS_ACCESS_TOKEN`, `GOOGLE_ADS_CLIENT_ID`, `GOOGLE_ADS_CLIENT_SECRET` and `GOOGLE_ADS_REFRESH_TOKEN` (were `ADS_*`).
31
+ - The fixed caps (500 daily budget, 20 CPC) became configurable limits with defaults of 1000 and 50.
32
+ - Released under the Apache License 2.0.
33
+
34
+ ### Fixed
35
+
36
+ - Plans that changed several fields of one resource (for example an ad group's bid and status) sent one operation per field, which Google rejects (`ID_EXISTS_IN_MULTIPLE_MUTATES`). They are now merged into one operation.
37
+ - Review and performance metadata on ads no longer changes the account snapshot, so it can't make a saved plan look stale.
38
+
39
+ ### Migrating from 0.1
40
+
41
+ ```yaml
42
+ # 0.1 # 0.2
43
+ version: 1 version: 1
44
+ namespace: shop provider:
45
+ currency: USD google_ads:
46
+ campaign: namespace: shop
47
+ id: search currency: USD
48
+ ... campaigns:
49
+ ad_templates: {...} - id: search
50
+ ...
51
+ ad_templates: {...}
52
+ ```
53
+
54
+ Rename the `ADS_*` environment variables to `GOOGLE_ADS_*`. Version 0.1 was never run against a live account, so there are no `aac:` campaigns to rename. If you created some, rename them to `adstack:<namespace>:<id>` (and their ad groups to `adstack:<id>`) before planning.
55
+
56
+ ## 0.1.0
57
+
58
+ Initial local version: one Google Search campaign per YAML file, reviewed plans, applies validated by Google, and safety flags for enabling campaigns, increasing budgets and bids, and changing live campaigns.
@@ -0,0 +1,74 @@
1
+ # Contributing to Adstack
2
+
3
+ Thanks for helping. Adstack changes real advertising accounts that spend real money, so changes are judged first on whether they keep the workflow safe and predictable, and then on features.
4
+
5
+ ## Development setup
6
+
7
+ ```bash
8
+ git clone https://github.com/markwroberts0/adstack
9
+ cd adstack
10
+ python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
11
+ pip install -e '.[dev]'
12
+ pytest -q # the whole suite runs offline in a few seconds
13
+ ruff check . && ruff format --check .
14
+ ```
15
+
16
+ Try your change end to end against the sandbox:
17
+
18
+ ```bash
19
+ adstack plan examples/quickstart --sandbox
20
+ adstack apply examples/quickstart --sandbox --auto-approve
21
+ adstack mcp --sandbox # for MCP changes; connect a client as in docs/mcp.md
22
+ ```
23
+
24
+ ## Ground rules
25
+
26
+ - **No network in tests.** Tests use the sandbox backend, fake HTTP sessions and canned API rows. CI never has ad platform credentials, and pull requests must not require them.
27
+ - **Planning is pure.** A provider's `plan` function takes the desired state and a snapshot and returns the same plan every time, with no I/O. Saved plans are verified by recomputing them, so any non-determinism (timestamps, set ordering, random IDs) breaks applies.
28
+ - **Fail closed.** When the account contains something Adstack doesn't understand or doesn't own, report a blocker or raise an error. Never guess, adopt or delete.
29
+ - **Explicit permissions stay explicit.** Anything that can start or increase spend, or touch a serving campaign, must be reflected in the plan's `requires`.
30
+ - **Keep the sandbox honest.** If you depend on a platform rule (ordering, uniqueness, atomicity), make the sandbox enforce it too, so tests catch violations.
31
+ - **Document behavior changes.** Update `docs/` and `CHANGELOG.md` with user-visible changes.
32
+
33
+ ## Project layout
34
+
35
+ See the [architecture overview](docs/how-it-works.md#architecture). In short: `config.py`, `engine.py`, `plan.py`, `cli.py` and `mcp_server.py` are provider-independent; everything specific to an ad platform lives in `adstack/providers/<name>/`.
36
+
37
+ ## Adding a provider
38
+
39
+ A provider implements the `Provider` protocol in [`adstack/providers/base.py`](adstack/providers/base.py):
40
+
41
+ | Method | Responsibility |
42
+ | --- | --- |
43
+ | `load(settings, document)` | Validate the provider block and the rest of the configuration (strictly) and return a JSON-serializable desired state. |
44
+ | `summary(desired)` | One line such as `2 campaigns, 5 ad groups, 23 keywords`. |
45
+ | `connect(desired, sandbox_dir=..., env=...)` | Return a `Backend` for the real account (credentials from `env`) or, when `sandbox_dir` is set, an offline sandbox. |
46
+ | `plan(desired, state, account, prune=..., destroy=...)` | Pure reconciliation. Return `changes` (records with `action`, `resource`, `campaign`, `ad_group`, `name` and optional `attributes`, `diff`, `note`), `blockers`, `requires` (the three permission flags) and `operations`. |
47
+ | `inventory(desired, state)` | Flatten a snapshot into records for `adstack state list`. |
48
+ | `format_account(account)` | Display form of an account ID. |
49
+
50
+ A `Backend` has `account`, `sandbox`, `read()`, `mutate(operations, validate_only=...)` and `report(kind, days, all_campaigns=...)`. Mutations must be atomic, or the provider must explain clearly why they can't be. Register the provider in `adstack/providers/__init__.py`.
51
+
52
+ Ship a sandbox backend with the provider, plus tests covering at least: an initial plan, a no-op re-plan after applying it, drift correction, prune, destroy, the permission flags, and the platform rules the planner depends on.
53
+
54
+ ## Pull requests
55
+
56
+ - Keep each pull request focused, and describe the user-visible behavior change.
57
+ - Add or update tests; `pytest`, `ruff check` and `ruff format --check` must pass.
58
+ - For changes to API payloads or queries, link the platform documentation you relied on, and say whether you tested against a real (test) account.
59
+
60
+ ## Project page
61
+
62
+ The project page is a single static file, [`site/index.html`](site/index.html), with no build step: open it in a browser to preview it. Pushes to `main` that touch `site/` publish it to GitHub Pages through [`.github/workflows/pages.yml`](.github/workflows/pages.yml) (in the repository settings, Pages must use **GitHub Actions** as its source). The terminal demo replays real `adstack` output, so update it when the CLI's output changes.
63
+
64
+ ## Reporting bugs
65
+
66
+ Open an issue with the Adstack version, the command you ran, the configuration (redact anything private) and the output. Never paste credentials, plan files or receipts from a real account into an issue: they contain account details. Report security problems privately, as described in [SECURITY.md](SECURITY.md).
67
+
68
+ ## Releasing
69
+
70
+ Releases are published to PyPI by [`.github/workflows/release.yml`](.github/workflows/release.yml) with PyPI [Trusted Publishing](https://docs.pypi.org/trusted-publishers/), so no API token is stored anywhere.
71
+
72
+ 1. Set the new version in `adstack/__init__.py` and move the changes in `CHANGELOG.md` under that version and date.
73
+ 2. Merge to `main`, then push a matching tag: `git tag v0.2.1 && git push origin v0.2.1`.
74
+ 3. The workflow checks that the tag matches the version, builds the package, runs the tests against the built wheel and publishes it. PyPI versions can't be replaced, so a broken release is fixed with a new version.
adstack-0.2.0/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,6 @@
1
+ # Ship the tests, examples and docs in the source distribution, so it is self-contained.
2
+ include CHANGELOG.md CONTRIBUTING.md SECURITY.md
3
+ graft docs
4
+ graft examples
5
+ graft tests
6
+ global-exclude __pycache__ *.py[cod]
adstack-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,235 @@
1
+ Metadata-Version: 2.4
2
+ Name: adstack
3
+ Version: 0.2.0
4
+ Summary: Advertising campaigns as code: declarative configuration, reviewable plans, safe applies, and an MCP server for AI assistants.
5
+ Author: Adstack contributors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/markwroberts0/adstack
8
+ Project-URL: Documentation, https://github.com/markwroberts0/adstack/tree/main/docs
9
+ Project-URL: Issues, https://github.com/markwroberts0/adstack/issues
10
+ Project-URL: Changelog, https://github.com/markwroberts0/adstack/blob/main/CHANGELOG.md
11
+ Keywords: ads-as-code,google-ads,advertising,ppc,infrastructure-as-code,terraform,mcp
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Information Technology
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Office/Business
23
+ Classifier: Topic :: System :: Systems Administration
24
+ Requires-Python: >=3.11
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: PyYAML<7,>=6
28
+ Requires-Dist: requests<3,>=2.31
29
+ Provides-Extra: mcp
30
+ Requires-Dist: mcp<3,>=2.3; extra == "mcp"
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest<10,>=8; extra == "dev"
33
+ Requires-Dist: ruff>=0.15; extra == "dev"
34
+ Requires-Dist: build>=1.2; extra == "dev"
35
+ Requires-Dist: mcp<3,>=2.3; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # Adstack
39
+
40
+ **Advertising campaigns as code.** Declare campaigns in YAML, review a plan of exactly what will change, then apply it: the workflow Terraform uses for infrastructure, built for ad platforms. An [MCP server](https://github.com/markwroberts0/adstack/blob/main/docs/mcp.md) lets AI assistants such as Claude validate, plan and (when you allow it) apply changes too.
41
+
42
+ [![CI](https://github.com/markwroberts0/adstack/actions/workflows/ci.yml/badge.svg)](https://github.com/markwroberts0/adstack/actions/workflows/ci.yml)
43
+ [![PyPI](https://img.shields.io/pypi/v/adstack.svg)](https://pypi.org/project/adstack/)
44
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/markwroberts0/adstack/blob/main/LICENSE)
45
+
46
+ ```console
47
+ $ adstack plan --out launch.plan.json
48
+ Adstack will perform the following actions in Google Ads account 123-456-7890:
49
+
50
+ + campaign running-shoes (status = PAUSED, type = SEARCH, bidding = MANUAL_CPC, networks = Google Search only, geo_targeting = PRESENCE)
51
+ + daily budget (amount = 25.00 USD)
52
+ + location 2840
53
+ + negative keyword "free"
54
+ + negative keyword "jobs"
55
+ + ad group road (cpc_bid = 1.10 USD)
56
+ + keyword [road running shoes]
57
+ + keyword [running shoes for men]
58
+ + responsive search ad (template = running-shoes, headlines = 3, descriptions = 2, final_url = https://www.example.com/running-shoes)
59
+
60
+ Plan: 9 to add, 0 to change, 0 to remove.
61
+
62
+ $ adstack apply launch.plan.json
63
+ ...
64
+ Apply complete! Resources: 9 added, 0 changed, 0 removed.
65
+ Receipt: .adstack/receipts/20261126T133746Z-44e0f9dbfe49.json
66
+ ```
67
+
68
+ This is the plan for the configuration shown [below](#configuration).
69
+
70
+ ## Why Adstack
71
+
72
+ - **Reviewable.** Campaign changes go through pull requests and a plan you read before anything happens.
73
+ - **Safe by default.** New campaigns start paused. Enabling a campaign, raising a budget or bid, and touching a campaign that is serving each need an explicit flag. A saved plan is re-verified against the live account before it is applied, and the platform validates every request before it commits. Adstack never deletes campaigns, ad groups, keywords or ads.
74
+ - **Convergent.** The account is made to match the configuration. Changes made by hand show up in the next plan.
75
+ - **AI-ready.** The MCP server gives assistants the same validate → plan → apply loop, with applying disabled unless you turn it on.
76
+ - **Try it offline.** A local sandbox account runs the whole workflow without an ad account or credentials.
77
+
78
+ **Status: alpha.** The first provider is **Google Ads** (Search campaigns with manual CPC bidding, exact-match keywords, responsive search ads, negative keywords and location targeting). The plan/apply logic is covered by tests against the sandbox, but the REST integration has not yet been exercised against a live Google Ads account; run it against a [test account](https://developers.google.com/google-ads/api/docs/best-practices/test-accounts) first. More providers are welcome; see [CONTRIBUTING.md](https://github.com/markwroberts0/adstack/blob/main/CONTRIBUTING.md).
79
+
80
+ ## Install
81
+
82
+ Adstack needs Python 3.11 or later.
83
+
84
+ ```bash
85
+ pip install "adstack[mcp]" # CLI and MCP server
86
+ ```
87
+
88
+ Omit `[mcp]` if you only need the CLI. To work on Adstack itself, see [CONTRIBUTING.md](https://github.com/markwroberts0/adstack/blob/main/CONTRIBUTING.md).
89
+
90
+ ## Quick start (no ad account needed)
91
+
92
+ ```bash
93
+ adstack init my-ads # write an annotated starter configuration
94
+ adstack validate my-ads # offline checks
95
+ adstack plan my-ads --sandbox # plan against a local sandbox account
96
+ adstack apply my-ads --sandbox # apply after typing 'yes'
97
+ adstack plan my-ads --sandbox # No changes.
98
+ ```
99
+
100
+ The sandbox lives in `.adstack/sandbox/` in the current directory. It applies the same API operations Adstack sends to Google and enforces the same request rules, but it does not review ads or serve them. Two complete examples are in [`examples/`](https://github.com/markwroberts0/adstack/tree/main/examples/).
101
+
102
+ ## Configuration
103
+
104
+ A configuration is one YAML file, or a directory of YAML files that are merged (like a Terraform module):
105
+
106
+ ```yaml
107
+ version: 1
108
+
109
+ provider:
110
+ google_ads:
111
+ namespace: example # campaigns are named adstack:example:<campaign id>
112
+ currency: USD # must match the account
113
+ customer_id: 123-456-7890 # optional: pin the account in code review
114
+
115
+ ad_templates:
116
+ running-shoes:
117
+ final_url: https://www.example.com/running-shoes
118
+ headlines: [Running Shoes For Every Pace, Free Returns On All Shoes, Find Your Perfect Fit]
119
+ descriptions:
120
+ - Road, trail and track shoes from leading brands. Free shipping on orders over $50.
121
+ - Not the right fit? Return any pair within 60 days for a full refund.
122
+
123
+ campaigns:
124
+ - id: running-shoes
125
+ status: PAUSED
126
+ daily_budget: 25.00
127
+ default_cpc: 1.10
128
+ locations: [2840] # United States
129
+ negative_keywords: ['"free"', '"jobs"']
130
+ ad_groups:
131
+ - id: road
132
+ ad_template: running-shoes
133
+ keywords: ['[road running shoes]', '[running shoes for men]']
134
+ ```
135
+
136
+ Every option is described in [docs/configuration.md](https://github.com/markwroberts0/adstack/blob/main/docs/configuration.md).
137
+
138
+ ## Commands
139
+
140
+ | Command | What it does |
141
+ | --- | --- |
142
+ | `adstack init [DIR]` | Write an annotated starter configuration. |
143
+ | `adstack validate [PATH]` | Check the configuration offline. |
144
+ | `adstack plan [PATH] [--out FILE]` | Read the account and show what would change. Changes nothing. `--prune` also pauses or removes managed resources that are no longer configured; `--validate` asks the platform to validate the changes too; `--detailed-exitcode` exits 2 when there are changes. |
145
+ | `adstack apply PLAN_FILE` | Apply a saved plan after verifying the account hasn't changed since it was made. |
146
+ | `adstack apply [PATH]` | Plan, then apply after you type `yes` (or `--auto-approve`). |
147
+ | `adstack destroy [PATH]` | Pause every campaign Adstack manages. Nothing is deleted. |
148
+ | `adstack show PLAN_FILE` | Display a saved plan (`--json` for machines). |
149
+ | `adstack state list [PATH]` | List what Adstack manages in the account. |
150
+ | `adstack report performance\|search-terms [PATH]` | Clicks, cost and conversions for the last 7, 14 or 30 days. |
151
+ | `adstack mcp` | Run the MCP server over stdio. |
152
+
153
+ `PATH` defaults to the current directory. Add `--sandbox` (or set `ADSTACK_SANDBOX=1`) to use the local sandbox account.
154
+
155
+ Applying also needs an explicit flag when a plan would:
156
+
157
+ | Flag | Needed when |
158
+ | --- | --- |
159
+ | `--allow-enable` | a paused campaign starts serving |
160
+ | `--allow-budget-increase` | a budget or bid on an existing campaign or ad group increases |
161
+ | `--allow-live-changes` | anything changes in a campaign that is serving now |
162
+
163
+ Plan files and receipts (written to `.adstack/receipts/` after every apply) are never overwritten. Treat them as private operational data.
164
+
165
+ ## Connect Google Ads
166
+
167
+ Adstack uses the Google Ads REST API (v26). Since September 9, 2026, API access belongs to the Google Cloud project behind your OAuth credentials; a developer token is no longer needed.
168
+
169
+ 1. In [Google Cloud Console](https://console.cloud.google.com/apis/library/googleads.googleapis.com), select or create a project and enable the Google Ads API.
170
+ 2. Request an [access level](https://developers.google.com/google-ads/api/docs/api-policy/access-levels) for the project. Test access works only with Google Ads test accounts; start there if you can.
171
+ 3. Configure the OAuth consent screen and create a Desktop OAuth client. The Google user who authorizes it must have access to the Google Ads account. Obtain a refresh token with the `https://www.googleapis.com/auth/adwords` scope ([Google's OAuth guide](https://developers.google.com/google-ads/api/docs/oauth/overview)). While an external consent screen is in Testing mode, refresh tokens can expire after seven days.
172
+ 4. Set the credentials in your environment or secret manager. Never commit them. See [`.env.example`](https://github.com/markwroberts0/adstack/blob/main/.env.example).
173
+
174
+ ```bash
175
+ export GOOGLE_ADS_CUSTOMER_ID=123-456-7890 # or provider.google_ads.customer_id
176
+ export GOOGLE_ADS_CLIENT_ID='...'
177
+ export GOOGLE_ADS_CLIENT_SECRET='...'
178
+ export GOOGLE_ADS_REFRESH_TOKEN='...'
179
+ # export GOOGLE_ADS_LOGIN_CUSTOMER_ID=111-222-3333 # only when using a manager account
180
+ # export GOOGLE_ADS_ACCESS_TOKEN='...' # alternative: a short-lived access token
181
+ ```
182
+
183
+ Then use the commands without `--sandbox`. Before enabling a campaign, check billing, ad policy status, landing pages and conversion tracking in Google Ads: Adstack doesn't manage those.
184
+
185
+ ## Use with AI assistants (MCP)
186
+
187
+ ```bash
188
+ claude mcp add adstack -- adstack mcp --sandbox --root /path/to/your/ads # Claude Code, sandbox
189
+ ```
190
+
191
+ The server's tools are `validate`, `plan`, `show_plan`, `state`, `report` and `example_config`. A configuration can be a path inside `--root` or YAML text. The `apply` tool appears only with `--sandbox` or `--allow-apply`. It accepts only a plan the server created, requires the account ID as confirmation and the same permission flags as the CLI, and re-verifies the plan against the live account. See [docs/mcp.md](https://github.com/markwroberts0/adstack/blob/main/docs/mcp.md) for Claude Desktop and other clients.
192
+
193
+ ## Use in CI
194
+
195
+ Run offline validation (and, if you choose, a plan) on every pull request, and apply reviewed plans deliberately:
196
+
197
+ ```yaml
198
+ # .github/workflows/ads.yml in the repository that holds your configuration
199
+ on: pull_request
200
+ permissions:
201
+ contents: read
202
+ jobs:
203
+ validate:
204
+ runs-on: ubuntu-latest
205
+ steps:
206
+ - uses: actions/checkout@v4
207
+ - uses: actions/setup-python@v5
208
+ with:
209
+ python-version: "3.13"
210
+ - run: pip install adstack
211
+ - run: adstack validate ads/
212
+ ```
213
+
214
+ Planning against the real account needs credentials. Don't expose them to workflows that run untrusted pull request code.
215
+
216
+ ## How it works
217
+
218
+ Adstack keeps no state file. A campaign's identity is its name, `adstack:<namespace>:<campaign id>`, so every campaign in the namespace is managed and every other campaign is ignored. Each plan reads the account, compares it with the configuration, and lists every change, blocker and required permission. Applying sends one atomic request. The details, including what Adstack deliberately doesn't manage, are in [docs/how-it-works.md](https://github.com/markwroberts0/adstack/blob/main/docs/how-it-works.md).
219
+
220
+ ## Roadmap
221
+
222
+ - More providers: Microsoft Advertising, Meta, LinkedIn.
223
+ - More Google Ads features: other bidding strategies, phrase and broad keywords in ad groups, display paths, assets, ad schedules.
224
+ - Importing existing campaigns into configuration.
225
+ - A JSON Schema for editor completion and validation.
226
+
227
+ Ideas and pull requests are welcome.
228
+
229
+ ## Contributing
230
+
231
+ See [CONTRIBUTING.md](https://github.com/markwroberts0/adstack/blob/main/CONTRIBUTING.md). Please report security issues privately, as described in [SECURITY.md](https://github.com/markwroberts0/adstack/blob/main/SECURITY.md).
232
+
233
+ ## License
234
+
235
+ [Apache License 2.0](https://github.com/markwroberts0/adstack/blob/main/LICENSE).