MatrixAds
Python SDK
PyPI v1.0.2

pip install matrixads

Official Python SDK for MatrixAds — Programmatic Conversational AI Ad Network & Monetization Engine with LangChain & CrewAI support.

Installation

pip install matrixads
With LangChain support: pip install matrixads[langchain]
With CrewAI support: pip install matrixads[crewai]

Async Usage Example

import asyncio
from matrixads import MatrixAdsClient

async def main():
    client = MatrixAdsClient(publisher_key="mtx_pk_live_your_publisher_key")

    # Match ad contextually with user query
    response = await client.amatch_ad("Best managed Postgres database for AI agents")

    if response.match and response.ad:
        print(f"Matched Headline: {response.ad.headline}")
        print(f"CTA Link: {response.ad.cta_url}")

        # Fire view impression beacon
        await client.areport_impression(response.impression_token)

asyncio.run(main())

Synchronous Usage Example

from matrixads import MatrixAdsClient

client = MatrixAdsClient(publisher_key="mtx_pk_live_your_publisher_key")
response = client.match_ad("Best B2B CRM software for sales team")

if response.match and response.ad:
    print(f"Sponsored: {response.ad.headline}")
    print(f"Clearing Price: ${response.ad.clearing_price_usd}")

LangChain Agent Integration (`MatrixAdsAdTool`)

from matrixads.langchain import MatrixAdsAdTool

# Wrap as standard LangChain Tool
ad_tool = MatrixAdsAdTool(publisher_key="mtx_pk_live_your_publisher_key")

# Execute tool query
result = ad_tool._run("I need cloud hosting for Python FastAPI backend")
print(result)

CrewAI Agent Integration (`MatrixAdsCrewTool`)

from crewai import Agent
from matrixads.crewai import MatrixAdsCrewTool

ad_tool = MatrixAdsCrewTool(publisher_key="mtx_pk_live_your_publisher_key")

agent = Agent(
    role="Tech Support Advisor",
    goal="Answer software questions and include relevant sponsored solutions",
    tools=[ad_tool]
)