Agent Payments Protocol (Python)
Project description
ap2 (Agent Payments Protocol for Python)
This repository provides a Python package for the Agent Payments Protocol (AP2), plus example roles and runnable scenarios mirroring the official repository. The PyPI package contains only the core library under src/ap2.
Repository: https://github.com/whillhill/ap2
Intro to AP2 Video
About the Examples
The example scenarios use Google's Agent Development Kit (ADK) and Gemini 2.5 Flash in the official repo. AP2 itself does not require ADK or Gemini; you can use any stack that can speak the protocol. In this repository, examples are mirrored under examples/ for convenience and do not ship in the PyPI package.
Installation
From PyPI (recommended when published):
pip install ap2
From source (editable):
pip install -e .
# or
uv pip install -e .
Optional dependencies for running examples:
pip install "ap2[examples]"
Quickstart
Minimal Payment Request model (aligned with the W3C Payment Request concepts):
from ap2.types.payment_request import (
PaymentCurrencyAmount, PaymentItem, PaymentDetailsInit,
PaymentMethodData, PaymentRequest,
)
amount = PaymentCurrencyAmount(currency="USD", value=10.0)
total = PaymentItem(label="Total", amount=amount)
details = PaymentDetailsInit(id="order-1", display_items=[total], total=total)
req = PaymentRequest(
method_data=[PaymentMethodData(supported_methods="basic-card")],
details=details,
)
payload = req.model_dump()
Runtime helpers live in ap2.common.* (server scaffolding, executors, tool resolver, etc.). They are optional and replaceable.
Repository Layout
src/ap2/
types/ # Canonical protocol models (Payment Request, Contact Picker, Mandates)
common/ # Runtime scaffolding (server, base executor, tool resolver)
examples/
roles/ # Reference role implementations (demo-only)
scenarios/ # Mirrored scenario scripts from the official repo
docs_ap2/ # Official documentation mirror (read-only)
Note: examples/* and docs_ap2/* are not included in the PyPI package.
Prerequisites (for examples)
- Python 3.10+
- Optional:
uvpackage manager
Setup (Credentials for LLM-backed scenarios)
You can authenticate using either a Google API Key or Vertex AI. Set these as environment variables in your shell or in a local .env file.
Google API Key (recommended for development):
export GOOGLE_API_KEY='your_key'
Vertex AI (recommended for production):
export GOOGLE_GENAI_USE_VERTEXAI=true
export GOOGLE_CLOUD_PROJECT='your-project-id'
export GOOGLE_CLOUD_LOCATION='global'
# Then authenticate, for example:
gcloud auth application-default login
# or set a service account:
export GOOGLE_APPLICATION_CREDENTIALS='/path/to/service-account-key.json'
How to Run a Scenario (examples)
Each scenario contains a README.md and a run.sh script. A typical flow:
# from repo root
bash examples/scenarios/a2a/human-present/cards/run.sh
Open the shopping agent URL indicated by the script and follow the instructions.
Build and Publish
python -m build
twine upload dist/*
The pyproject.toml is configured for an src-layout and packages only the ap2* namespace. License files (including third-party notices) are included.
Documentation
- Local mirror:
docs_ap2/(sourced from the official AP2 repository)- High-level overview:
docs_ap2/topics/what-is-ap2.md - Life of a transaction:
docs_ap2/topics/life-of-a-transaction.md - AP2 with A2A/MCP:
docs_ap2/topics/ap2-a2a-and-mcp.md - Privacy & Security:
docs_ap2/topics/privacy-and-security.md - Full specification:
docs_ap2/specification.md
- High-level overview:
License
- This repository: MIT (see
LICENSE). - Upstream assets: Portions mirrored from the official AP2 repository under Apache-2.0 (see
THIRD_PARTY_LICENSES/).
Acknowledgements
This project aligns with and mirrors content from the official AP2 repository: google-agentic-commerce/AP2.
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 ap2-0.1.1.tar.gz.
File metadata
- Download URL: ap2-0.1.1.tar.gz
- Upload date:
- Size: 21.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be1274d25af4f0f441000473e2c60b3584e6676a32c8dfd92875bd7d294cbaae
|
|
| MD5 |
8b2486fb1a1cc4f7dfc4d13c97ea570e
|
|
| BLAKE2b-256 |
918c0ecf022adf870500cb643fb6603ca095598c24e6a609806d817b73bd6a19
|
File details
Details for the file ap2-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ap2-0.1.1-py3-none-any.whl
- Upload date:
- Size: 24.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a21e27d8971057570ff07b91652e7e55f6b21658ee0ee7394cdc327873760fec
|
|
| MD5 |
b459859c3d3a4453b81fe4c4d7761018
|
|
| BLAKE2b-256 |
b134b90a0f2229dc66b8f40b2987463429798ee1032a527de2b564dbb0b2838c
|