Batch-build UTM-tagged campaign links from a CSV, with consistent names, validation that catches analytics-wrecking mistakes, optional QR codes and a static index page.
pip install utmkit
$ utmkit validate spec.csv
WARN row 2: not_lowercase: utm_source='Instagram' should be lowercase (analytics tools split cases)
1 finding(s)
$ utmkit batch spec.csv --out-dir out --fix --html
INFO row 2: fixed: utm_source: 'Instagram' -> 'instagram'
2 link(s) -> out/links.csv
Real output from a throwaway folder with the two-row spec.csv shown under Batch.
- One spec, many links. One CSV row per link; stable file names;
out/links.csvand a printableout/index.html. - Catches the quiet mistakes.
Instagramvsinstagram, missing source, duplicate final URLs, off-list values. - Optional QR codes. PNG or print-ready SVG, same names as the links.
Quickstart
pip install utmkit # links, slugs, validation
pip install 'utmkit[qr]' # + QR code generation
utmkit --help # examples and exit codes
One link
utmkit gen https://calasautomations.com/onfile \
--source instagram --medium social --campaign launch26
# https://calasautomations.com/onfile?utm_source=instagram&utm_medium=social&utm_campaign=launch26
utmkit gen ... --qr launch26-ig.png # QR for the same URL (needs [qr] extra)
utmkit gen ... --qr launch26-ig.svg # vector SVG for print: needs only the qrcode package, no Pillow
Batch
spec.csv:
url,source,medium,campaign,name
https://calasautomations.com/onfile,instagram,social,launch26,Spring Ad
https://calasautomations.com/quote,newsletter,email,launch26,Quote Nudge
utmkit batch spec.csv --out-dir out/ --qr --html
Produces out/links.csv (slug, final URL, QR filename), one QR code per row when enabled (PNG, or vector SVG with --qr-format svg), and out/index.html — a table of every link with clickable URLs and QR images.
Validation
utmkit validate spec.csv flags the classics without building anything:
- error — missing
utm_source, empty URL - warn (
batchonly) —duplicate_url: two rows build the exact same final URL, so their clicks can't be told apart in analytics; the warning names both rows - warn — uppercase values (analytics tools split
Instagramfrominstagram), spaces in values, unusualutm_mediumvalues, URLs without a scheme
--fix on gen and batch cleans the five UTM values before validation: lowercase, trim, and inner spaces to - (" Instagram Ads " becomes instagram-ads). Each change is reported as an info finding naming the old and new value. Without --fix, nothing is changed.
Warnings don't fail the build unless --strict. In batch, a row with an error is reported and skipped (no link built) and the run exits 1.
Audit an existing link
utmkit parse "https://x.com/?utm_source=IG&utm_medium=social"
# url: https://x.com/
# utm_source: IG
# utm_medium: social
# WARN not_lowercase: utm_source='IG' should be lowercase (analytics tools split cases)
# WARN no_campaign: utm_campaign is missing
Splits a tagged URL someone else made into its base URL and UTM values, then runs the same checks as validate (plus --rules if given). parse also warns when utm_campaign is missing (gen/batch don't). Exit 1 on an error such as a missing utm_source; --json for automation.
Naming rules (allow-list)
Lock the values your team may use, so nobody invents Insta next to instagram:
{"source": ["instagram", "facebook"], "medium": ["social", "email", "cpc", "qr"], "campaign_pattern": "^[a-z0-9-]+$"}
utmkit validate spec.csv --rules rules.json # also on gen and batch
All three keys are optional. A source or medium outside its list, or a campaign that doesn't match the regex, is an error (not_allowed): the row is skipped in batch and the run exits 1. When you give a medium list, it replaces the built-in "unusual medium" warning. A missing or malformed rules file (bad JSON, a list that isn't a list of strings, an invalid regex, an unknown key) exits 2 with a message. Use --fix together with --rules to lowercase values before they are checked.
Limits up front
- utmkit builds links; it doesn't track clicks. Pair it with your analytics tool.
- It checks the five UTM values and your allow-list. It does not check that the destination page exists.
- QR PNG needs the
[qr]extra (Pillow); SVG needs only theqrcodepackage. - Without
--fix, nothing is changed in your values.
Design notes
- Deterministic slugs: the
namecolumn (else the final tagged URL) becomes the filename slug; collisions get-2,-3suffixes — same input, same output names, every run. - Existing params survive:
?id=7&ref=navstays intact; stale values for the five standard keys (utm_source,utm_medium,utm_campaign,utm_term,utm_content) are replaced by the campaign (the campaign is the source of truth); other params such asutm_idare kept. - QR is optional: the core has zero dependencies;
qrcodeis only imported when you pass--qrand installs via the[qr]extra. PNG needs Pillow (the extra pulls it in); SVG output uses qrcode's own SVG writer and works without Pillow. Custom backends can be injected through the Python API. - Static
index.html: host it, print it, or hand it to whoever is running the campaign — no JS, no build step.
Python API
from utmkit import Campaign, build_url, slugify
url = build_url(Campaign("https://ex.com", source="ig", medium="social", campaign="c1"))
assert slugify("Spring Sale — 20% OFF!") == "spring-sale-20-off"
License
MIT. Use it, ship it, no warranty. Changes: CHANGELOG.md.
Made by Calas Automations (CAL-us). Need help? Call Cara 431-244-9026.
Metadata
Release files for utmkit 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| utmkit-0.1.2.tar.gz | 19.9 kB | Without provenance | Details for utmkit-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| utmkit-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for utmkit-0.1.2-py3-none-any.whl |
Total release size: 34.0 kB
Release files / utmkit-0.1.2.tar.gz
| Download URL | utmkit-0.1.2.tar.gz |
|---|---|
| Size | 19.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d438af9a1246d7c4557f0cfac6357600309824ea385e7677d18e9360b3b286e
|
|
BLAKE2b-256 checksum How to use checksums |
e148416fc3a0c0fd6fb0310e121a02c1abb24d7664ee3408e919d5eb32631215
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / utmkit-0.1.2-py3-none-any.whl
| Download URL | utmkit-0.1.2-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7773f3f8aa76fc705ffaa8f3a7c5a1555868c8db3cb24f2aaf2bb2e7a6663467
|
|
BLAKE2b-256 checksum How to use checksums |
6ea68a03d5dd6fcedd95945a16caa1d43a4ad1448a1eafe732593f162cc9bb61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for utmkit 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.