Skip to main content

dv360-bidkit

PyPI version CI Python versions License: MIT Polar Pro Agent Skill MCP Server

Turn DV360 report data into verified, high-performance custom bidding algorithms without guesswork, AST syntax errors, or platform rejections.

dv360-bidkit is an open-source, agent-ready programmatic bidding engine engineered for Google Display & Video 360 (DV360). It lints custom bidding scripts against Google's 2026 DSL specification, runs deterministic local simulations without eval()/exec(), checks Google S2 training readiness (500 advertiser / 50 line-item positives), and compiles structured rulesets into production-grade Python scripts.


Quickstart: Inspectable Demo in 1 Command

dv360-bidkit includes realistic synthetic display report fixtures requiring zero external Google Cloud or DV360 API credentials. Install and run an inspectable pre-flight evaluation pass in a single command:

# Install from PyPI:
pip install dv360-bidkit

# Run instant diagnostic simulation:
bidkit demo

Inspectable Terminal Output:

                       DV360 BidKit Open-Core Demo Simulation                        
┏━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Metric                ┃ Observed Value ┃ Google S2 / Health Standard              ┃
┡━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Total Impressions     │        273,146 │ Historical baseline sample               │
│ Positive Impressions  │         93,878 │ ≥ 500 required by Google S2              │
│ Positive Scoring Rate │          34.4% │ Target: 5% – 40% for active bidding      │
│ Weighted Mean Score   │           2.41 │ Scale baseline                           │
│ Gini Inequality       │          0.712 │ 0 = flat, 1 = extreme concentration      │
│ Max-to-Median Ratio   │           1.3x │ ≤ 20.0x prevents DSP pacing starvation   │
│ Readiness Status      │ MEETS_MINIMUM_HISTORY │ Google Custom Bidding training readiness │
└───────────────────────┴────────────────┴──────────────────────────────────────────┘

✓ Demo bundle successfully generated in: demo
  • Report: demo/report.csv
  • Mapping: demo/mapping.json
  • Rules: demo/rules.json
  • Policy: demo/policy.json
  • Compiled Script: demo/script.py
  • Diagnostics JSON: demo/diagnostics.json
  • Pro Config: demo/campaign.json

The Python Data Science / ML Pipeline Bridge (bidkit.from_sklearn)

Data scientists and quantitative programmatic traders train predictive models in Python (scikit-learn, LightGBM, XGBoost), but historically faced an impassable roadblock: Google DV360 Custom Bidding only executes custom Python algorithms inside Google's sandboxed DSL (no import, no external libraries, 64 KB size cap, restricted AST nodes).

dv360-bidkit bridges this gap with bidkit.from_sklearn(). It translates fitted Scikit-Learn DecisionTreeClassifier and DecisionTreeRegressor estimators directly into 100% compliant Google DV360 Custom Bidding Python scripts.

1-Minute Code Example:

from sklearn.tree import DecisionTreeClassifier
import dv360_bidkit as bidkit

# 1. Train standard decision tree on impression/conversion logs
features = ["device_type", "environment", "hour_of_day", "day_of_week"]
clf = DecisionTreeClassifier(max_depth=3, min_samples_leaf=50)
clf.fit(X_train, y_train)

# 2. Compile directly into Google DV360 Custom Bidding DSL:
dv360_script = bidkit.from_sklearn(
    clf,
    feature_names=features,
    output_style="conditional",  # or "aggregate" for first_match_aggregate
    scale_factor=100.0,
    validate=True,               # Validates against Google's AST linter & 64 KB limit
)

print(dv360_script)

Try it Instantly from the Terminal:

# Train a tree on synthetic impression logs and display syntax-highlighted DV360 DSL:
bidkit tree-demo --max-depth 3 --style conditional

# Or export Google aggregate format:
bidkit tree-demo --style aggregate --out my_bidding_model.py

The 4 Fatal Pitfalls of DV360 Custom Bidding

DV360 custom bidding models replace Google's standard click/conversion heuristics with a custom machine-learning reward function. However, four subtle pitfalls routinely undermine live campaigns:

1. Small-Sample Winner's Curse (Publisher Noise)

  • The Pitfall: Long-tail domains with small impression samples (e.g., 3/3 viewable impressions $= 100%$) receive maximum bid multipliers under naive scoring rules, wasting budget on unverified tail traffic.
  • The Solution: Never bid on raw empirical rates. dv360-bidkit-pro applies Empirical Bayes shrinkage towards the campaign's baseline viewability ($\lambda_i = \frac{n_i}{n_i + k^*}$), pulling low-volume publishers toward the global mean while granting full confidence only to high-volume domains.

2. Score Mass Domination (Objective Dilution)

  • The Pitfall: In multi-objective funnels blending purchases with proxy signals (e.g. Add-to-Cart or Clicks), high-frequency proxy signals can inadvertently capture $90%+$ of total score mass ($M = \sum N_k w_k$). Google's bidding algorithm optimizes purely for the proxy and ignores primary conversions.
  • The Solution: Enforce transition-bounded econometric caps ($w_{\text{proxy}} \le w_{\text{macro}} \times P(\text{Macro} \mid \text{Proxy})$) and allocate at least $65%$ of expected score mass to primary conversions using bidkit-pro weights.

3. Pacing Starvation from Outlier Spikes

  • The Pitfall: Uncapped continuous metrics (e.g., e-commerce transaction values or duration) create extreme score spikes. If the ratio of maximum score to positive median ($\max / \text{median}$) exceeds $20\times$, DV360's dual pacing controller ($\alpha_t$) destabilizes, causing immediate bid starvation.
  • The Solution: Apply 95th-percentile Winsorization caps emitted as DV360-compliant ternary expressions (cap if val > cap else val).

4. Model Training Exclusion vs. Ad-Serving Blocks

  • The Pitfall: Returning None in a custom bidding script (return None) excludes an impression from model training; it does NOT block the ad from serving.
  • The Solution: Programmatic traders must maintain a strict separation between algorithm exclusions (return None for model health) and ad-serving blocks. dv360-bidkit exports targeting_block_request.csv as an actionable checklist for trafficking into DV360 Line Item targeting.

Community (Open-Source Core) vs. Pro

dv360-bidkit (Open-Source Core) is the Safety and Execution Rail: it ensures scripts are syntactically valid, budget-compliant, and accurately simulated.
dv360-bidkit-pro (Commercial) is the Econometric Brain: it eliminates manual weight guessing, calculates optimal proxy weights, shrinks long-tail publisher noise, and exports complete production bundles.

Feature Open-Source Core (dv360-bidkit) Commercial Pro (dv360-bidkit-pro)
Licensing Public MIT Proprietary License (Polar.sh)
DV360 DSL Grammar & Syntax Linter (2026.1 Registry) ✅ Included ✅ Included
Safe AST Pre-Flight Simulator (No eval/exec) ✅ Included ✅ Included
Google S2 Training Readiness Check (500 / 50 Positives) ✅ Included ✅ Included
Deterministic RuleSet Compiler (sum, max, first_match) ✅ Included (Manual weights) ✅ Included (Auto-calibrated)
Customer Inventory Policy Loader (Exclusions & Overrides) ✅ Included ✅ Included
DV360 Report Loader (Preamble & Footer Auto-Stripping) ✅ Included ✅ Included
Attention Dwell Prior Tables (Simonov & Valletti / Lumen) ✅ Open Normative Factors ✅ Multi-Factor Joint Calibration
MFA (Made-For-Advertising) Clutter Discounting Engine ❌ (Manual domain lists) ✅ Automated Spillover & MFA Discount
Empirical Bayes Viewability Shrinkage (MML Auto-Tuning) ❌ (Static rules only) ✅ Automatic $\lambda_i$ shrinkage
Client Funnel Proxy Screening & Mass-Balanced Weighting ❌ (Manual guesswork) ✅ bidkit-pro weights
Automated 95th-Percentile Ternary Outlier Capping ❌ (Manual coding) ✅ DV360-safe ternary emit
Impression-Weighted Rule Quantization ($K$-Bins) ❌ (Exact rules only) ✅ Bounded RMSE & $R^2$
Multi-Objective Pareto Trade-Off Scenarios (80/20, 50/50) ❌ ✅ Gini & decile evaluation
Customer Inventory Spend & Coverage Impact Audit ❌ ✅ Projected coverage & spend
Production Campaign Bundle Exporter & Audit HTML ❌ Basic HTML ✅ Full 8-artifact bundle

Commercial Value Analysis: €100,000 Monthly Spend Scenario

Dimension / Metric Plain DV360 (Standard Bidding) Open-Core (dv360-bidkit) Enterprise Pro (dv360-bidkit-pro)
AST Linter & Platform Rejections N/A (Standard DV360 CPA/CPC) 0h turnaround (catches syntax & type errors locally) 0h turnaround (validated before artifact packaging)
Script Engineering & QA Time 10–15 hours manual Python scripting per campaign 2–3 hours (automated compilation & local simulation) < 30 minutes (end-to-end automated pipeline & CLI)
Outlier & Pacing Starvation Risk High risk ($\max/\text{median} > 20\times$ destabilizes pacing $\alpha_t$) Manual inspection required via diagnostic JSON Automated 95th-percentile ternary capping eliminates starvation
Attention & Dwell Optimization 3rd-party vendor fees ($0.20–$0.40 CPM) or run unweighted Zero-vendor-fee open dwell tables (format, position, device) Dynamic multi-factor calibration with automated MFA & clutter discounting
Small-Sample Tail Noise Waste Unprotected (long-tail domains get maximum bid weights) Manual domain exclusions via policy.csv Empirical Bayes shrinkage ($\lambda_i$) prevents ~€4k–€8k tail overspend
Multi-Objective Funnel Optimization Single Floodlight conversion event only Manual proxy weights (risk of proxy domination) Econometric mass balancing preserves 65% conversion mass
Pre-Flight Simulation & Safety None (upload and wait for Google's model to train) Deterministic AST simulation against historical CSVs Turnkey 8-artifact campaign bundle with HTML audit report
Modeled Media Efficiency Uplift Baseline (€100k gross media spend) ~€3,000 – €5,000 in avoided misconfigurations + engineering time saved ~€15,000 – €25,000 modeled value uplift (reduced tail waste + balanced pacing)

Command Line Interface (CLI)

# 1. Generate synthetic benchmark data and starter rules
bidkit demo --out-dir ./demo

# 2. Lint an existing script against the 2026.1 signal registry
bidkit lint script.py --format text

# 3. Compile a structured RuleSet and inventory policy into a DV360 script
bidkit compile --rules rules.json --policy policy.csv --out script.py

# 4. Simulate a script against historical DV360 report data
bidkit evaluate script.py --report report.csv --mapping mapping.json --out diagnostics.json

# 5. Render evaluation diagnostics to an HTML visual report
bidkit report diagnostics.json --out audit.html

# 6. Train and compile a Scikit-Learn tree directly to DV360 DSL
bidkit tree-demo --max-depth 3 --style conditional --out my_model.py

Python SDK Quickstart

import json
from dv360_bidkit import (
    load_report,
    load_inventory_policy,
    compile_script,
    evaluate_script,
    lint_script,
    ReportMapping,
    RuleSet,
    Rule,
    RuleCondition,
    AggregationMode,
)

# 1. Define custom bidding rules
ruleset = RuleSet(
    aggregation_mode=AggregationMode.FIRST_MATCH,
    rules=[
        Rule(
            id="premium_news",
            conditions=[RuleCondition(field="domain", operator="in", value=["spiegel.de", "zeit.de"])],
            score=10.0,
        ),
        Rule(
            id="mobile_web",
            conditions=[
                RuleCondition(field="device_type", operator="==", value=2),
                RuleCondition(field="environment", operator="==", value=1),
            ],
            score=5.0,
        ),
    ],
    fallback_score=1.0,
)

# 2. Compile to production DV360 Python DSL
comp_result = compile_script(ruleset)
print(comp_result.script_code)

# 3. Validate against syntax and signal registry
lint_rep = lint_script(comp_result.script_code)
assert lint_rep.is_valid

# 4. Pre-flight simulation on customer report
mapping = ReportMapping(
    canonical_field_map={
        "impressions": "Impressions",
        "domain": "App/URL",
        "device_type": "Device Type",
        "environment": "Environment",
        "line_item_id": "Line Item ID",
    },
    date_window="30d",
)
data = load_report("dv360_report.csv", mapping=mapping)
eval_rep = evaluate_script(comp_result.script_code, data, history_window_days=30)

print(f"Readiness: {eval_rep.readiness.status.value}")
print(f"Positively Scored Impressions: {eval_rep.metrics.positive_score_impressions:,}")

Core Data Contracts

1. Report Mapping (ReportMapping)

Maps raw DV360 Standard or Instant Report column headers (English or German) to canonical fields:

{
  "canonical_field_map": {
    "impressions": "Impressions",
    "measurable_impressions": "Active View: Measurable Impressions",
    "viewable_impressions": "Active View: Viewable Impressions",
    "domain": "App/URL",
    "device_type": "Device Type",
    "environment": "Environment",
    "line_item_id": "Line Item ID",
    "advertiser_id": "Advertiser ID",
    "clicks": "Clicks",
    "conversions": "Total Conversions"
  },
  "denominators": {
    "viewable_impressions": "measurable_impressions",
    "measurable_impressions": "impressions"
  },
  "row_grain": "homogeneous_aggregate",
  "date_window": "30d"
}

2. Customer Inventory Policy (InventoryPolicy)

Customer-defined domain and site lists specifying score overrides, training exclusions, or ad-serving block requests:

entity_type,entity_value,action,source,as_of,expiry,score,label
domain,fraud-network.com,exclude_from_training,audit_2026,2026-01-01,,0.0,Excluded from model
domain,direct-partner.com,set_score,pmp_deal,2026-01-01,2026-12-31,25.0,Preferred Deal Floor
domain,toxic-site.com,targeting_block_request,safety,2026-01-01,,0.0,Block Ad Serving

⚡ Commercial Pro Tier (dv360-bidkit-pro)

dv360-bidkit-pro is available for enterprise programmatic trading desks and agencies requiring automated Active View quality shrinkage, multi-objective Floodlight funnel balancing, and turnkey campaign bundle compilation:

👉 Get DV360 BidKit Pro License on Polar.sh

Pro Installation & Setup

  1. Obtain License & Download Wheel Bundle: Purchase on Polar.sh to receive your BK_PRO_... license key and pre-compiled native binary wheel bundle (dv360-bidkit-pro-0.1.0-all-wheels.zip).
  2. Install Platform Wheel:
    unzip dv360-bidkit-pro-0.1.0-all-wheels.zip
    pip install --find-links . dv360-bidkit-pro
    
  3. Authenticate:
    bidkit-pro auth --key BK_PRO_...
    

🤖 Agentic Custom Bidding Skill (dv360-custom-bidding)

dv360-bidkit ships with an Antigravity / Cursor / Claude Code agent skill: skills/dv360-custom-bidding/SKILL.md.

Equipped with this skill, AI coding assistants can:

  1. Parse client DV360 report files and generate exact ReportMapping definitions.
  2. Formulate multi-vector scoring algorithms and verify them against the DV360 signal registry.
  3. Simulate positive score density to prevent READINESS_STATE_INSUFFICIENT_DATA launch failures.
  4. Call bidkit-pro weights and bidkit-pro build to export production campaign bundles.

Install directly via skills.sh into Cursor, Claude Code, Antigravity, Copilot, and other agent environments:

npx skills add flovv/dv360-bidkit

🔌 Model Context Protocol (MCP) Server (Zero Python Required)

dv360-bidkit provides a production MCP server running globally on Cloudflare Workers edge. Media buyers, non-technical analysts, and programmatic teams can interact with BidKit directly inside Claude Desktop, Cursor, or web agents with zero local setup:

Connect to Claude Desktop (1 Click)

Add the live SSE endpoint to your claude_desktop_config.json:

{
  "mcpServers": {
    "dv360-bidkit": {
      "url": "https://dv360-bidkit-mcp.teschner.workers.dev/sse"
    }
  }
}

Local stdio MCP Server (Developers)

For local execution without cloud networks, launch via Python or uvx:

# Using CLI:
bidkit mcp

# Using uvx:
uvx dv360-bidkit mcp

3 Exposed MCP Tools:

  • validate_custom_bidding_script: Verifies Google 2026 DSL compliance, AST syntax, and 65k character budgets.
  • get_attention_benchmarks: Retrieves empirical dwell multipliers and APM norms (Simonov & Valletti 2024 / Lumen).
  • compile_custom_bidding_script: Compiles structured rules into production Google DV360 Python scripts.

Documentation & AI Retrieval Index


License

dv360-bidkit is open-source software licensed under the MIT License.
Commercial Pro extensions (dv360-bidkit-pro) are available under proprietary commercial licenses via Polar.sh.

Metadata

Release files for dv360-bidkit 0.1.2

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

Source distribution (sdist)

Source distribution for dv360-bidkit 0.1.2
File Size Uploaded Provenance Actions
dv360_bidkit-0.1.2.tar.gz 112.5 kB With provenance Details for dv360_bidkit-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dv360-bidkit 0.1.2
File Interpreter ABI Platform Actions
dv360_bidkit-0.1.2-py3-none-any.whl Python 3 none any Details for dv360_bidkit-0.1.2-py3-none-any.whl

Total release size: 181.4 kB

Release files / dv360_bidkit-0.1.2.tar.gz

Download URL dv360_bidkit-0.1.2.tar.gz
Size 112.5 kB
Tags Source
SHA-256 checksum
How to use checksums
aaa7b085865e24db7c71209744b44b51781bd86faa6199568e139e620e4b2c7e
BLAKE2b-256 checksum
How to use checksums
716f32f6997dd53b373eee4d5ae427e4a94bce094d7837aa3842d9489a9433fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / dv360_bidkit-0.1.2-py3-none-any.whl

Download URL dv360_bidkit-0.1.2-py3-none-any.whl
Size 68.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61d3cfa60e4f3956af210df05696da969de713ce6e08e42cb470abee55c19ec9
BLAKE2b-256 checksum
How to use checksums
abcbe1b90ade8c5bd89220e3075d2348dbda322cbf832f6ad8ab5a7e3d52bfd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for dv360-bidkit 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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dv360_bidkit-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

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.

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