Skip to main content

Python SDK

Use the Python SDK when building Python agents or backend services.

Run the local Python example

Try the SDK against the mock AAP server with AAP_API_KEY=aap_demo_key and fake checkout data.
Install
pip install agent-attribution-protocol
quickstart.py
from agent_attribution_protocol import AAP

aap = AAP(api_key="your-api-key")

# 1. Search for offers
result = aap.search(vertical="sim", max_price=10, contract_months=0)
print(f"Found {result.count} offers")

# 2. Recommend an offer (records attribution)
rec = aap.recommend(
    session_id=result.session_id,
    offer_id=result.offers[0].id,
    context="User asked for cheap SIM with no contract",
)
print(f"Fallback URL: {rec.fallback_url}")

# 3. Initiate checkout
checkout = aap.checkout(
    session_id=result.session_id,
    recommendation_id=rec.recommendation_id,
)
print(f"Transaction: {checkout.transaction_id}")

Client

AAP(api_key, base_url="https://api.rako.sh")

Create a client. It can also be used as a context manager:
with AAP(api_key="your-api-key") as aap:
    result = aap.search(vertical="sim")

Methods

aap.search(**kwargs)

Search for offers.
OptionTypeDescription
verticalstrsim, broadband, energy, flights, hotels, insurance
providerstrFilter by provider name
max_pricefloatMaximum price
min_data_gbintMinimum data allowance for SIM offers
contract_monthsintContract length, where 0 means rolling

aap.recommend(session_id, offer_id, context)

Record a recommendation. This is the attribution event.

aap.checkout(session_id, recommendation_id, user_details)

Initiate checkout for a recommended offer.

aap.get_session(session_id)

Get session details including recommendations and conversions.

aap.verify_code(code)

Verify an AAP Code is authentic.

Mock conversion learning

The runnable SDK example reaches a mock checkout URL. To understand why checkout-link creation is separate from conversion recording, see Mock Conversion Artifact.

PyPI

GitHub