The Unified Python Framework for Causal Media Modeling, Economic Systems & Complex Adaptive Systems
"Does the flap of a butterfly's wings in Brazil set off a tornado in Texas?" β Edward Lorenz
Papilon (French for "butterfly") is the most comprehensive Python framework for Marketing Mix Modeling, Causal Inference, and Complex Systems Analysis. Named after the butterfly effect, it captures how small changes in marketing spend can cascade into significant business outcomes.
| Feature | Meridian | PyMC-Marketing | Robyn | Papilon |
|---|---|---|---|---|
| Bayesian MMM | β | β | β | β |
| Causal Discovery | β | β | β | β |
| Causal Inference | β | β | β | β |
| Agent-Based Modeling | β | β | β | β |
| Economic I-O Models | β | β | β | β |
| Complex Systems | β | β | β | β |
| Autonomous Agents | β | β | β | β |
| Workflow Automation | β | β | β | β |
| Python Native | β | β | β (R) | β |
pip install papilonimport papilon as pp
# Quick MMM Analysis
model = pp.MMM(
data=df,
target="revenue",
media=["tv_spend", "digital_spend", "radio_spend"],
date_col="date"
)
model.fit()
# Get ROI estimates
rois = model.get_roi()
print(rois)
# Optimize budget
optimal = model.optimize_budget(total=1_000_000)
print(optimal)from papilon.orchestrator import MMMAgent
# Create an AI-powered agent
agent = MMMAgent(llm="claude")
# Natural language interface
results = agent.run("""
Load my marketing data,
fit an MMM model with TV, Digital, and Radio channels,
optimize budget for $2M quarterly spend,
and generate a report with visualizations.
""", data="marketing_data.csv")
# Or use quick analysis
results = agent.quick_analysis(
data="data.csv",
target_col="revenue",
media_cols=["tv", "digital", "radio"],
total_budget=2_000_000
)from papilon.orchestrator import AutoMMM
# Create automated MMM system
auto = AutoMMM(
data_source="marketing_data.csv",
target="revenue",
media_channels=["tv", "digital", "radio"]
)
# Configure automation
auto.set_retraining_schedule("0 9 * * 1") # Weekly Monday 9am
auto.set_performance_threshold("mape", max_value=0.15)
auto.set_data_trigger(min_new_rows=7)
# Add notifications
from papilon.orchestrator import SlackNotifier
auto.add_notifier(SlackNotifier(webhook_url="..."))
# Start continuous automation
auto.start()import papilon as pp
# Discover causal structure
dag = pp.discover_causal_structure(df, method="pc")
# Estimate causal effects
effect = pp.estimate_effect(
df,
treatment="marketing_spend",
outcome="sales",
method="backdoor"
)
# Synthetic control for geo experiments
sc = pp.SyntheticControl(
treated_unit="California",
control_units=["Texas", "Florida", "New York"],
treatment_time="2024-01-01"
)
sc.fit(panel_data)
causal_effect = sc.estimate_effect()papilon/
βββ core/ # Foundation modules
β βββ entropy.py # Information theory
β βββ energy.py # Statistical mechanics
β βββ states.py # State space analysis
β βββ relationships.py # Correlation analysis
β βββ topology.py # Network topology
β
βββ mmm/ # Marketing Mix Modeling
β βββ transforms/ # Adstock & saturation
β βββ models/ # Bayesian & frequentist
β βββ decomposition.py # Channel attribution
β βββ response_curves.py # Marginal response
β βββ calibration.py # Lift test integration
β βββ budget_optimizer.py # SLSQP optimization
β
βββ causal/ # Causal Inference
β βββ discovery/ # PC, FCI, GES, NOTEARS
β βββ effects/ # ATE, CATE, ITT, LATE
β βββ methods/ # DiD, synthetic control, RDD, IV
β βββ interventions.py # do-calculus
β βββ refutation.py # Robustness checks
β
βββ orchestrator/ # π Autonomous Agents
β βββ base.py # Agent framework
β βββ agents.py # MMMAgent, CausalAgent
β βββ tools.py # Tool library
β βββ workflows.py # DAG pipelines
β βββ automation.py # AutoMMM, triggers, monitors
β
βββ economics/ # Economic Modeling
β βββ io_model.py # Leontief I-O
β βββ multipliers.py # Economic multipliers
β βββ shock_analysis.py # Shock propagation
β
βββ dynamics/ # Complex Systems
β βββ attractors.py # Fixed points, chaos
β βββ bifurcation.py # Parameter sensitivity
β βββ stability.py # Lyapunov exponents
β
βββ agents/ # Agent-Based Modeling
β βββ base.py # Agent class
β βββ model.py # ABM model
β βββ space.py # Grid, network, continuous
β
βββ sensitivity/ # Sensitivity Analysis
β βββ sobol.py # Sobol indices
β βββ morris.py # Morris screening
β
βββ viz/ # Visualization
βββ dag.py # Causal graphs
βββ response.py # Response curves
βββ decomposition.py # Waterfall charts
Papilon 2.0 introduces a revolutionary autonomous agent framework that can automate your entire MMM workflow:
- Natural Language Interface: Describe tasks in plain English
- LLM Integration: Works with Claude, GPT-4, or local models
- Tool-Based Architecture: Extensible with custom tools
- Workflow Orchestration: DAG-based pipeline execution
- Event-Driven Automation: Triggers, monitors, and alerts
- Human-in-the-Loop: Approval steps when needed
| Agent | Purpose |
|---|---|
MMMAgent |
Marketing Mix Modeling automation |
CausalAgent |
Causal discovery and inference |
AgentOrchestrator |
Multi-agent coordination |
| Component | Purpose |
|---|---|
Workflow |
DAG-based pipeline definition |
AutoMMM |
Fully automated MMM system |
DataTrigger |
Retrain on new data |
PerformanceMonitor |
Track model metrics |
SlackNotifier |
Send alerts to Slack |
# Optimize $10M annual budget across channels
optimal = model.optimize_budget(
total=10_000_000,
constraints={
"tv": (1_000_000, 5_000_000),
"digital": (2_000_000, 6_000_000),
}
)# Analyze geo-lift experiment
effect = pp.difference_in_differences(
data=geo_data,
treatment_group="test_markets",
control_group="holdout_markets",
treatment_time="2024-06-01"
)# What-if analysis
scenarios = [
{"name": "Cut TV 20%", "changes": {"tv": -0.2}},
{"name": "Double Digital", "changes": {"digital": 1.0}},
]
for scenario in scenarios:
impact = agent.scenario(scenario["name"], scenario["changes"])
print(f"{scenario['name']}: {impact['total_revenue_change_pct']:.1f}%")# Input-Output modeling
io = pp.InputOutputModel(transaction_matrix)
multipliers = io.calculate_multipliers()
shock_impact = io.shock_analysis(sector="advertising", shock=-0.1)# LLM API Keys (for agent features)
export ANTHROPIC_API_KEY="sk-..."
export OPENAI_API_KEY="sk-..."
# Optional: GPU acceleration
export JAX_PLATFORM_NAME="gpu"model = pp.BayesianMMM(
# Adstock configuration
adstock_type="weibull", # geometric, weibull, delayed
adstock_max_lag=8,
# Saturation configuration
saturation_type="hill", # hill, logistic, tanh
# Priors
roi_prior="informative", # informative, weakly_informative, flat
# Inference
n_samples=2000,
n_chains=4,
target_accept=0.9,
)- GPU Acceleration: JAX/NumPyro backend for 10-100x speedup
- Parallel Workflows: Execute independent steps concurrently
- Incremental Updates: Update models with new data efficiently
- Memory Efficient: Streaming for large datasets
- Audit Logging: Track all model changes and decisions
- Role-Based Access: Control who can modify models
- Deployment Ready: Docker, Kubernetes support
- API Server: REST API for integration
- Enterprise Support: support@vector1.ai
- Issues: GitHub Issues (private repo)
- Consulting: Available for custom implementations
Proprietary License - All rights reserved.
Copyright Β© 2024-2025 Brian Curry / Vector1 Research
This software is proprietary and confidential. Unauthorized copying, distribution, or use is strictly prohibited. See LICENSE for full terms.
Built with insights from:
- Google Meridian
- PyMC-Marketing
- DoWhy / EconML / CausalML
- Mesa ABM Framework
- SALib
Papilon β Understanding the butterfly effects in your marketing