Official Python SDK for the Causality Engine API — causal attribution for e-commerce.
Project description
Causality Engine Python SDK
The official Python SDK for the Causality Engine API — causal attribution for e-commerce. Replace last-click with math.
Installation
pip install causality-engine
Quick Start
import causality
ce = causality.CausalityEngine(api_key="ce_live_sk_...")
# Run causal attribution analysis
result = ce.attribution.analyze(
store="my-store.myshopify.com",
date_range=["2026-01-01", "2026-01-31"],
)
for ch in result.data["channel_impact"]:
print(f"{ch['channel']}: {ch['causal_lift']:.0%} lift, ROI {ch['roi']:.1f}x")
Authentication
Get your API key at developers.causalityengine.ai/api-keys.
# Option 1: Pass directly
ce = causality.CausalityEngine(api_key="ce_live_sk_...")
# Option 2: Environment variable
# export CAUSALITY_ENGINE_API_KEY="ce_live_sk_..."
ce = causality.CausalityEngine()
API Coverage
| Resource | Methods | Description |
|---|---|---|
ce.attribution |
analyze(), retrieve(), list() |
Causal attribution analysis |
ce.channels |
performance(), amplification() |
Cross-channel performance |
ce.journeys |
flow(), leakage() |
Customer journey mapping |
ce.campaigns |
overview() |
Campaign-level intelligence |
ce.health |
score() |
Marketing health diagnostics |
ce.brand |
decompose() |
Brand awareness decomposition |
ce.agents |
register(), me(), usage() |
AI agent management |
ce.referrals |
list() |
Referral chain tracking |
ce.commissions |
list(), verify() |
Commission ledger |
ce.billing |
summary(), value_proofs() |
Billing & Delta_R tracking |
ce.auth |
token(), rotate_key() |
OAuth & key management |
Examples
Channel Performance
perf = ce.channels.performance(
data_source_id="ds_abc123",
date_range=["2026-01-01", "2026-01-31"],
)
for ch in perf.data["channels"]:
print(f"{ch['name']}: score {ch['performance_score']}")
Cross-Channel Amplification
amp = ce.channels.amplification(
data_source_id="ds_abc123",
date_range=["2026-01-01", "2026-01-31"],
)
print(f"Strongest pair: {amp.data['strongest_pair']}")
print(f"Total synergy: {amp.data['total_synergy_score']}")
Customer Journey Flow
flow = ce.journeys.flow(
data_source_id="ds_abc123",
date_range=["2026-01-01", "2026-01-31"],
min_conversions=10,
)
for path in flow.data["top_paths"]:
print(f"{' → '.join(path['path'])}: {path['conversions']} conversions")
Register an AI Agent
agent = ce.agents.register(
name="my-attribution-agent",
operator_email="dev@yourcompany.com",
capabilities=["attribution", "channel_analysis"],
)
print(f"Agent ID: {agent.data['agent_id']}")
print(f"Referral code: {agent.data['referral_code']}")
Marketing Health Score
health = ce.health.score(
data_source_id="ds_abc123",
date_range=["2026-01-01", "2026-01-31"],
)
print(f"Score: {health.data['score']}/100 (Grade: {health.data['grade']})")
print(f"Recommendation: {health.data['top_recommendation']}")
Error Handling
from causality_engine import (
AuthenticationError,
RateLimitError,
NotFoundError,
ValidationError,
CausalityEngineError,
)
try:
result = ce.attribution.analyze(
data_source_id="ds_abc123",
date_range=["2026-01-01", "2026-01-31"],
)
except AuthenticationError:
print("Invalid API key")
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after}s")
except NotFoundError:
print("Resource not found")
except ValidationError as e:
print(f"Invalid request: {e.message}")
except CausalityEngineError as e:
print(f"API error: {e.message} (status {e.status_code})")
Configuration
ce = causality.CausalityEngine(
api_key="ce_live_sk_...",
base_url="https://api.causalityengine.ai", # default
timeout=30.0, # request timeout in seconds
max_retries=3, # retries on 429/5xx errors
)
The SDK automatically retries on rate limits (429) and server errors (5xx) with exponential backoff.
Context Manager
with causality.CausalityEngine(api_key="ce_live_sk_...") as ce:
result = ce.attribution.analyze(
store="demo.myshopify.com",
date_range=["2026-01-01", "2026-01-31"],
)
# Transport is automatically closed
Documentation
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file causality_engine-1.0.0.tar.gz.
File metadata
- Download URL: causality_engine-1.0.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec05a8ccc96eb28e53765c9afddd888ae7239f088060f1837bfd5576cfc76c0d
|
|
| MD5 |
408769a1c279e5fbb3e6ad2fe19d374a
|
|
| BLAKE2b-256 |
2d3ded7be841cc439a1eb6128c26edc91010d301fc11e915356baee8b44aed28
|
File details
Details for the file causality_engine-1.0.0-py3-none-any.whl.
File metadata
- Download URL: causality_engine-1.0.0-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcb4dc03aae363a8df6173a314ad0f1a0158ff56266a412d7466a93c7ff0e169
|
|
| MD5 |
9244dadf10d716a899f0f53f8e695a2a
|
|
| BLAKE2b-256 |
2a1aa65c45a991fa05fabb1e80acb35a130cb7047f45a08e0ea4f1a5916f0140
|