bidlab
A Python library for testing ad bidding methods, such as pacing, bid shading, and learning bidders, in simulated auctions.
You write a bidder class and a short Python script. bidlab runs the auctions, hides what a real bidder could not see, and reports the same metrics for every method.
Install
pip install bidlab # core: numpy, scipy, cloudpickle
pip install "bidlab[pandas]" # adds Results.to_pandas()
bidlab needs Python 3.12 or later. To work on bidlab itself, run uv sync in a clone of this repo. Changes per release are in the changelog.
Quickstart
import bidlab as bl
def true_value(bidder):
# OracleValue outputs the true value; put your own estimator here to test it.
return bl.Stack(bl.OracleValue(), bidder)
config = bl.SimConfig(
campaigns=[
bl.Campaign("truthful", true_value(bl.Linear()), budget=50, base_value=5),
bl.Campaign("pid", true_value(bl.PidPacing()), budget=15, base_value=5),
bl.Campaign("bandit", true_value(bl.UcbMultiplier()), budget=50, base_value=5),
],
auction=bl.SecondPrice(reserve=0.01),
episodes=5,
steps=500,
)
results = bl.run_many(config, seeds=range(3))
print(results.summary())
summary() shows, for each bidder, the mean across seeds and a 95% Student-t interval.
How one step works
- The market draws the impression's public features and each campaign's conversion probability pᵢ, and optionally a click probability qᵢ. The default market,
LogisticMarket, uses pᵢ = σ(x · φᵢ + βᵢ) for a random feature vector x, with no click stage (qᵢ = 1). - Each bidder's
forwardgets the inputs it names, such astime,budget_left,floor,marketand each public feature. The simulator passes no value: each bidder estimates its own.bl.OracleValuereads the truth frommarket: the campaign's base value w times the chance of its event, which is 1 for an impression, qᵢ for a click, and qᵢ × pᵢ for a conversion, the default. A bid policy such asbl.PidPacingsits after it in abl.Stack. - Each bid is capped at the bidder's remaining budget. The bidder does not see that amount; it tracks its own spend.
- The auction picks a winner:
FirstPriceorSecondPrice, with an optional reserve price. A market can add a floor and a hidden market price, the highest bid from outside; a campaign must beat it to win. - The winner is clicked with probability q, then converts with probability p of the winner.
- Each bidder gets its own
BidResult: the auction'stime, its bid, and whether it won. It also holds the price it paid, whether it was clicked and converted, and itsrealized_value. A bidder computes its own reward from it. A loser never sees the winning price.
bl.OracleValue(noise=0.5) makes that value wrong by a set amount. Simulation covers the clock and reproducibility.
Write a bidder
Subclass bl.Bidder and implement forward. Like a PyTorch module, forward names the inputs it needs, such as forward(self, time_left, budget_left). Its output is the bid. After another bidder in a bl.Stack, it also gets that bidder's output as value.
class FlatBid(bl.Bidder):
def __init__(self, amount):
self.amount = amount
def forward(self):
return self.amount
flat = bl.SimConfig(
campaigns=[
bl.Campaign("flat", FlatBid(0.2), budget=50, base_value=5),
bl.Campaign("truthful", true_value(bl.Linear()), budget=50, base_value=5),
],
episodes=2,
steps=200,
)
print(bl.run_many(flat, seeds=range(2)).summary())
Bidders covers every input, the other hooks, learning from results, and stacking bidders with bl.Stack.
Guides
| Guide | Covers |
|---|---|
| Simulation | Each step in detail, the clock, parallel runs, reproducibility |
| Campaigns | Budget, the event a campaign pays for, base value, CPA target, segments |
| Bidders | Inputs, hooks, value models and bid control, Stack, built-in bidders |
| Composite bidders | Bidders that hold and call other bidders |
| Markets | Built-in markets, segments and targeting, custom markets |
| Rewards | A reward in the bidder's own code, logging it, comparing bidders |
| Logging and callbacks | self.log in a bidder, and watching a run |
| Results | Results, RunLog, metric functions, regret |
Metrics defines every metric and its limits.
Examples
Each script runs on its own, prints its results, and ends with the answer to its question.
| Script | Question |
|---|---|
| getting_started/basic.py | When the budget is tight, does PID pacing earn more surplus than truthful bidding? |
| campaigns/events.py | With the same budget, does a click campaign pay less per click than a conversion campaign? |
| bidders/segment_rate.py | Does a bidder that counts conversions per segment learn that sports converts better than news? |
| bidders/value_estimators.py | Does a two-stage model on the public features estimate conversions better than counting? |
| bidders/oracle_noise.py | Does noise in the value estimate cost a truthful bidder surplus? |
| composite/night_shade.py | When a parent shades harder at night, does its child PID raise its multiplier at night? |
| markets/segments.py | Does a sports-only bidder win any auction outside sports? |
| markets/custom_market.py | Does the all-day bidder pay more per win at night, when the night-only bidder joins? |
| markets/independent_values.py | In a first-price auction with uniform values, does shading to (n-1)/n beat truthful bidding? |
| rewards/cpa_target.py | Does bidding target/value of the value meet a CPA target that truthful bidding misses? |
| rewards/custom_reward.py | Does a bandit rewarded for conversions pick a higher multiplier than one rewarded for surplus? |
| logging/pid_trace.py | Does PID pacing spend its whole budget in each episode? |
| simulation/clock.py | With a 12-hour day from 9:00, does an even-schedule bidder still have budget at 20:00, when truthful bidding has run out? |
| results/regret.py | With no budget limit in a second-price auction, is truthful bidding's regret zero? |
| results/reserve.py | Does a reserve price of 0.1 raise the platform's revenue? |
Metadata
Release files for bidlab 0.1.0
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 |
|---|---|---|---|---|
| bidlab-0.1.0.tar.gz | 42.0 kB | Without provenance | Details for bidlab-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bidlab-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for bidlab-0.1.0-py3-none-any.whl |
Total release size: 92.4 kB
Release files / bidlab-0.1.0.tar.gz
| Download URL | bidlab-0.1.0.tar.gz |
|---|---|
| Size | 42.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f723a03dd92fb0d4aff34461a80ed4fe7a547ad36030d7ac1339ee86b1bd154
|
|
BLAKE2b-256 checksum How to use checksums |
90d435b57683c92c4634bb5fb4a562e132089ebd60daf9c225fbe7086e32d981
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / bidlab-0.1.0-py3-none-any.whl
| Download URL | bidlab-0.1.0-py3-none-any.whl |
|---|---|
| Size | 50.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
effe38da6440c3371af0ba448c1548ff677d88c7016328cefd2c92cc28b09439
|
|
BLAKE2b-256 checksum How to use checksums |
f63321dbb1f0057e972dd1c418572b9df6a22c959ac42296183ec70f4efdee82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for bidlab 0.1.0
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.