iab-specs
An unofficial Rust implementation of various IAB (Interactive Advertising Bureau) specifications.
Overview
iab-specs provides typed Rust data structures for working with IAB advertising specifications. Rather than being just a parser, this library wraps each specification's logic into idiomatic Rust types using serde for serialization/deserialization.
Currently Supported Specifications
- AdCOM 1.0 - Advertising Common Object Model (enumerations)
- OpenRTB 2.5 - Real-Time Bidding protocol
- OpenRTB 2.6 - Real-Time Bidding protocol with CTV/DOOH support
- OpenRTB 3.0 - Real-Time Bidding protocol with layered architecture
- OpenRTB Native Ads 1.2 - Native advertising specification
- Ads.txt 1.1 - Authorized Digital Sellers declaration for websites
- App-ads.txt 1.0 - Authorized Digital Sellers declaration for mobile and CTV apps
- Sellers.json 1.0 - Supply chain transparency
- Agentic RTB Framework 1.0 - Autonomous agent bidstream processing via the OpenRTB Patch Protocol
Installation
Add iab-specs to your Cargo.toml with the features you need:
[]
# Enable all specifications
= { = "0.4", = ["adcom", "openrtb_25", "openrtb_26", "openrtb_30", "openrtb_native_12", "ads_txt", "app_ads_txt", "sellers_json", "artb_10"] }
# Or enable only what you need
= { = "0.4", = ["openrtb_30"] }
Or use cargo:
# Enable all specifications
# Or enable only what you need
Features
⚠️ Important: By default, no features are enabled. You must explicitly enable the specifications you need.
The library uses cargo features to enable/disable specifications:
Specifications:
adcom- AdCOM 1.0 support (Advertising Common Object Model enumerations)openrtb_25- OpenRTB 2.5 support (automatically includesadcom)openrtb_26- OpenRTB 2.6 support (automatically includesopenrtb_25andadcom)openrtb_30- OpenRTB 3.0 support (automatically includesadcom)openrtb_native_12- OpenRTB Native Ads 1.2 support (automatically includesadcom)ads_txt- Ads.txt 1.1 supportapp_ads_txt- App-ads.txt 1.0 support (automatically includesads_txt)sellers_json- Sellers.json 1.0 support (includesserde_json)artb_10- Agentic RTB Framework 1.0 support (autonomous agent bidstream processing)
Feature Selection Examples
[]
# Only AdCOM support
= { = "0.4", = ["adcom"] }
# Only OpenRTB 2.5 support (automatically includes adcom)
= { = "0.4", = ["openrtb_25"] }
# Only OpenRTB 2.6 support (automatically includes openrtb_25 and adcom)
= { = "0.4", = ["openrtb_26"] }
# Only OpenRTB 3.0 support (automatically includes adcom)
= { = "0.4", = ["openrtb_30"] }
# Only ads.txt support
= { = "0.4", = ["ads_txt"] }
# Only app-ads.txt support (automatically includes ads_txt)
= { = "0.4", = ["app_ads_txt"] }
# Only sellers.json support
= { = "0.4", = ["sellers_json"] }
# OpenRTB 3.0 with ads.txt and sellers.json
= { = "0.4", = ["openrtb_30", "ads_txt", "sellers_json"] }
# Only ARTB 1.0 support (autonomous agent bidstream processing)
= { = "0.4", = ["artb_10"] }
# All specifications
= { = "0.4", = ["adcom", "openrtb_25", "openrtb_26", "openrtb_30", "openrtb_native_12", "ads_txt", "app_ads_txt", "sellers_json", "artb_10"] }
Why no default features?
This design allows you to:
- Minimize dependencies: Only include what you actually use
- Reduce compile time: Don't compile unused specifications
- Smaller binary size: Eliminate unused code from your final binary
- Explicit dependencies: Be clear about which IAB specs your project relies on
Serialization Formats
All types derive serde::Serialize and serde::Deserialize, making the library transport-agnostic. You can use any serde-compatible format:
- JSON — Use
serde_jsonfor human-readable JSON serialization - Protobuf — Use
prostto encode/decode typed messages withVec<u8>extension fields - MessagePack — Use
rmp-serdefor compact binary serialization - CBOR — Use
ciboriumfor CBOR encoding - Any serde format — Plug in any serializer/deserializer that works with serde
Extension fields default to Vec<u8> (opaque bytes), making the library serde-agnostic out of the box. You can use explicit type parameters like BidRequest<serde_json::Value> for JSON extensions, or provide your own types implementing the Extension trait.
Quick Start
Creating an OpenRTB Bid Request
use ;
Using the Builder Pattern
For more ergonomic construction, use the builder pattern:
use ;
Usage Examples
AdCOM
Use standardized enumeration values from the Advertising Common Object Model:
use ;
// Auction types
let auction = FirstPrice;
assert_eq!;
// Device types
let device = Phone;
assert_eq!;
// API frameworks
let api = Mraid3;
assert_eq!;
// Video protocols
let protocol = Vast4;
assert_eq!;
Extension Trait
The Extension trait provides a flexible mechanism for adding custom fields to IAB specification objects. This is particularly useful for vendor-specific data, internal tracking, or experimental features.
Key Features:
- Type-safe extension handling with generics
- Default to
Vec<u8>(opaque bytes, serde-agnostic) - Support for custom strongly-typed extensions
- Thread-safe (Send + Sync)
- Format-neutral serde support (JSON, MessagePack, CBOR, protobuf via prost, etc.)
Types Supporting Extensions:
The Extension trait is used throughout the crate on many types:
- AdCOM types:
Ad,Placement,DistributionChannel,Site,App,User,Device,Content,Publisher,Geo,Segment,Data,Regs, and many more - OpenRTB 2.5/2.6 types:
BidRequest,BidResponse,Imp,Banner,Video,Audio,Site,App,Device,User,Geo,Publisher,Content,Source,SeatBid,Bid, and many more - OpenRTB 3.0 types:
Request,Response,Item,Bid,SeatBid,Source,SupplyChain,SupplyChainNode,Deal,Metric, and many more
Using JSON extensions (with explicit serde_json::Value type parameter):
use AdBuilder;
# use Error;
#
Using custom typed extensions:
use ;
use ;
use Builder;
# use Error;
#
No extensions needed:
use Ad;
# use Error;
#
For complete documentation and examples, see the Extension trait documentation.
OpenRTB 2.5 and 2.6
OpenRTB 2.5 and 2.6 are fully implemented with complete bid request/response objects.
Supply Chain Transparency
use ;
OpenRTB 2.6 Features
OpenRTB 2.6 adds support for CTV ad pods, DOOH multipliers, and more:
use Video;
use ;
OpenRTB 3.0
OpenRTB 3.0 introduces a layered architecture with explicit versioning and supply chain transparency as a first-class feature:
use ;
use ;
Key OpenRTB 3.0 Features:
- Explicit protocol and domain versioning
- Supply chain transparency promoted to core object
- Item-based inventory (replaces Imp)
- Comprehensive tracking URLs (nurl, burl, lurl)
- Package bidding support
- Measurement metrics
OpenRTB 3.0 Documentation:
- Migration Guide - Migrate from 2.x to 3.0
- Usage Guide - Complete examples and patterns
- Best Practices - Production guidelines
OpenRTB Native Ads 1.2
Create and parse native ad requests and responses:
use ;
Integration with OpenRTB 2.5:
use ;
use NativeRequest;
// Create native request
let native_req = builder
.ver
.assets
.build?;
// Serialize to JSON string
let native_json = to_string?;
// Embed in OpenRTB bid request
let bid_request = builder
.id
.imp
.build?;
Key Features:
- Asset-based composition (title, image, video, data)
- Event tracking with impression and click support
- Multi-placement support for feed-based layouts
- DCO (Dynamic Creative Optimization) URL support
- AdCOM integration for standardized enumerations
Agentic RTB Framework 1.0
Process OpenRTB bidstream with autonomous agents using the ARTB Patch Protocol.
Note: The example below uses
serde_json::Valuefor JSON payloads via explicit type parameters. The default payload type isVec<u8>(opaque bytes). Use explicit type parameters likeRTBRequestBuilder::<serde_json::Value, Vec<u8>>::default()for JSON payloads.
use ;
Key ARTB 1.0 Features:
- Atomic, intent-declared mutations to OpenRTB bid requests and responses
- Segment activation, deal management, bid shading, metrics, and content data
- Agent metadata with API and model versioning
- Extension support for custom agent-specific data
Ads.txt
Parse and generate ads.txt files:
use ;
use FromStr;
// Parse an ads.txt file
let ads_txt_content = "google.com, pub-1234567890123456, DIRECT, f08c47fec0942fa0";
let ads_txt = from_str?;
// Create an ads.txt programmatically
let ads_txt = builder
.contact
.owner_domain
.systems
.build?;
// Serialize to string
let output = ads_txt.to_string;
App-ads.txt
Parse and generate app-ads.txt files for mobile and CTV applications:
use ;
use FromStr;
// Parse an app-ads.txt file
let app_ads_content = r#"
contact=monetization@mygame.com
subdomain=games.mygame.com
# Primary ad network
google.com, pub-1234567890123456, DIRECT, f08c47fec0942fa0
# Reseller partners
silverssp.com, 9876, RESELLER, f6578439
"#;
let app_ads = from_str?;
// Create an app-ads.txt programmatically
let app_ads = builder
.contact
.subdomain
.systems
.build?;
// Serialize to string
let output = app_ads.to_string;
Note on ads.txt 1.1 vs app-ads.txt 1.0:
App-ads.txt v1.0 is based on an earlier ads.txt specification and does not support the ads.txt 1.1 features:
OWNERDOMAIN(not in app-ads.txt v1.0)MANAGERDOMAIN(not in app-ads.txt v1.0)
Attempting to parse an app-ads.txt file containing these directives will result in an error.
Sellers.json
Parse and generate sellers.json files:
use ;
use FromStr;
// Parse a sellers.json file
let sellers_json = r#"{
"contact_email": "adops@example.com",
"version": "1.0",
"sellers": [
{
"seller_id": "12345",
"seller_type": "publisher",
"name": "Example Publisher",
"domain": "example.com"
}
]
}"#;
let sellers = from_str?;
// Create sellers.json programmatically
let sellers = builder
.contact_email
.version
.sellers
.build?;
// Serialize to JSON string
let output = to_string_pretty?;
Documentation
Full API documentation is available on docs.rs.
For usage examples, please refer to the unit tests in the source code. Each module includes comprehensive test cases demonstrating both serialization and deserialization.
Development
The project includes shell scripts for common development tasks:
Format Code
Check or fix code formatting with rustfmt:
Run Linter
Check code quality with clippy:
Run Tests
Run tests with configurable features:
Generate Coverage
Generate code coverage reports:
All scripts support --help for more options.
Roadmap
- AdCOM 1.0
- Ads.txt 1.1
- App-ads.txt 1.0
- Sellers.json 1.0
- OpenRTB 2.5
- OpenRTB 2.6
- OpenRTB 3.0
- OpenRTB Native Ads 1.2
- Agentic RTB Framework 1.0
- Additional IAB specifications (contributions welcome!)
Contributing
Contributions are welcome! Whether it's:
- Adding new IAB specifications
- Improving existing implementations
- Fixing bugs
- Improving documentation
- Adding examples
Please see CONTRIBUTING.md for detailed guidelines on:
- Development setup
- Running tests locally with
act - Code coverage requirements
- Contribution workflow
License
Licensed under Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.