---
name: algorand-x402-python
description: Builds x402 HTTP-native payment applications on Algorand using Python. Covers clients (httpx, requests), servers (FastAPI, Flask), facilitators, Bazaar discovery, and the x402-avm library. Use when implementing x402 payment flows in Python, creating payment-gated APIs, building x402 facilitators, or integrating the x402-avm package.
title: algorand-x402-python
canonical_url: https://skilld.dev/gh/algorandfoundation/algorand-agent-skills/algorand-x402-python
last_updated: 2026-09-29T01:12:56.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/create-python-x402-client-examples.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-client-examples.md), [references/create-python-x402-client-reference.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-client-reference.md), [references/create-python-x402-client.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-client.md), [references/create-python-x402-facilitator-examples.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-facilitator-examples.md), [references/create-python-x402-facilitator-reference.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-facilitator-reference.md), [references/create-python-x402-facilitator.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-facilitator.md), [references/create-python-x402-server-examples.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-server-examples.md), [references/create-python-x402-server-reference.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-server-reference.md), [references/create-python-x402-server.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-server.md), [references/explain-algorand-x402-python-examples.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/explain-algorand-x402-python-examples.md), [references/explain-algorand-x402-python-reference.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/explain-algorand-x402-python-reference.md), [references/explain-algorand-x402-python.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/explain-algorand-x402-python.md), [references/use-python-x402-core-avm-examples.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/use-python-x402-core-avm-examples.md), [references/use-python-x402-core-avm-reference.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/use-python-x402-core-avm-reference.md), [references/use-python-x402-core-avm.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/use-python-x402-core-avm.md).
>
> If the user asked to install this Skill, run `npx skilld install algorandfoundation/algorand-agent-skills/algorand-x402-python`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/algorand-x402-python`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/algorandfoundation/algorand-agent-skills/algorand-x402-python) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/algorand-x402-python`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/algorand-x402-python --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/algorand-x402-python --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# x402 on Algorand - Python

Build x402 HTTP-native payment applications on Algorand with Python. Use the reference files below for detailed guidance on each component.

## Python Quick Start

The `x402-avm` package on PyPI bundles core protocol, AVM mechanism, HTTP clients, and server middleware. Pick the extras you need:

```bash
# AVM only (no HTTP client/server)
pip install "x402-avm[avm]"

# Server middleware (pick one)
pip install "x402-avm[fastapi,avm]"    # FastAPI async
pip install "x402-avm[flask,avm]"      # Flask sync

# HTTP clients (pick one)
pip install "x402-avm[httpx,avm]"      # Async with httpx
pip install "x402-avm[requests,avm]"   # Sync with requests

# Bazaar discovery extension
pip install "x402-avm[extensions,avm]"

# Everything
pip install "x402-avm[all]"
```

> Distribution name is `x402-avm` but the **import root is `x402`** (not `x402_avm`).

> **Warning:** Do not install the canonical PyPI `x402` package in the same environment as `x402-avm` — both unpack into the same `site-packages/x402` directory, and canonical `x402` contains no AVM mechanism. Keep them in separate environments.

### Register AVM Scheme

Every component registers the AVM exact scheme unconditionally — no environment variable guards:

```python
# Client
from x402 import x402Client
from x402.mechanisms.avm.exact import ExactAvmScheme

client = x402Client()
client.register("algorand:*", ExactAvmScheme(signer=my_signer))

# Server
from x402.server import x402ResourceServer
from x402.mechanisms.avm.exact import ExactAvmServerScheme

server = x402ResourceServer()
server.register("algorand:*", ExactAvmServerScheme())

# Facilitator
from x402 import x402Facilitator
from x402.mechanisms.avm import ALGORAND_TESTNET_CAIP2
from x402.mechanisms.avm.exact import ExactAvmFacilitatorScheme

facilitator = x402Facilitator()
facilitator.register([ALGORAND_TESTNET_CAIP2], ExactAvmFacilitatorScheme(signer=my_signer))
```

> `x402Facilitator.register` takes a **list** of networks, while `x402Client.register` and `x402ResourceServer.register` take a single string (glob `"algorand:*"` is fine there). Passing a bare string to the facilitator silently iterates it into single-character networks.

The `register_exact_avm_client/server/facilitator` helpers from `x402.mechanisms.avm.exact` are also valid.

### Network identifiers

Always use the constants from `x402.mechanisms.avm` (`ALGORAND_TESTNET_CAIP2`, `ALGORAND_MAINNET_CAIP2`) rather than hardcoding CAIP-2 strings. As of x402-avm 2.0.2 these are the full genesis hash form (`algorand:SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=` for TestNet, `algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=` for MainNet). The TypeScript `@x402/avm` package ≥2.20.0 uses the 32-char form (`algorand:SGO1GKSzyE7IEPItTxCByw9x8FmnrCDe`, `algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k`) — a TS server/client and a Python facilitator (or vice-versa) will not match until x402-avm adopts the same form.

### Troubleshooting

- **macOS SSL errors** reaching `https://testnet-api.algonode.cloud`: run with `SSL_CERT_FILE=$(python -c "import certifi;print(certifi.where())")`.

### Python algosdk Encoding

Python algosdk's `msgpack_decode()` expects base64 strings, `msgpack_encode()` returns base64 strings. Boundary conversion: `msgpack_decode(base64.b64encode(raw_bytes).decode())` / `base64.b64decode(msgpack_encode(obj))`.

## Reference Guide

Navigate to the appropriate reference based on your task. Each topic has three files:
- **`{name}.md`** — Step-by-step implementation guide
- **`{name}-reference.md`** — API details and type signatures
- **`{name}-examples.md`** — Complete, runnable code samples

### Explaining x402 for Python

Understand the `x402-avm` Python package structure, extras installation (`[avm]`, `[fastapi]`, `[flask]`, `[httpx]`, `[requests]`, `[extensions]`, `[all]`), signer protocols, async vs sync variants, and algosdk encoding boundaries.

- [explain-algorand-x402-python.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/explain-algorand-x402-python.md) — Package ecosystem explanation
- [explain-algorand-x402-python-reference.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/explain-algorand-x402-python-reference.md) — API reference for the x402-avm package
- [explain-algorand-x402-python-examples.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/explain-algorand-x402-python-examples.md) — Python pattern examples

### Building Clients

Build HTTP clients with httpx (async) or requests (sync) that automatically handle 402 payments. Covers wrapHttpxWithPayment, wrapRequestsWithPayment, ClientAvmSigner for payment signing.

- [create-python-x402-client.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-client.md) — Client creation guide
- [create-python-x402-client-reference.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-client-reference.md) — httpx/requests API reference
- [create-python-x402-client-examples.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-client-examples.md) — Client code examples

### Building Servers

Build payment-protected servers with FastAPI (async) or Flask (sync) middleware. Covers route pricing, PaymentMiddlewareASGI, Flask PaymentMiddleware, and multi-network support.

- [create-python-x402-server.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-server.md) — Server creation guide
- [create-python-x402-server-reference.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-server-reference.md) — FastAPI/Flask middleware API reference
- [create-python-x402-server-examples.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-server-examples.md) — Server code examples

### Building Facilitators and Bazaar Discovery

Build facilitator services that verify and settle Algorand payments on-chain. Covers FacilitatorAvmSigner protocol, register_exact_avm_facilitator, FastAPI facilitator endpoints (/verify, /settle, /supported), and Bazaar discovery extension for automatic cataloging and indexing of payment-gated APIs (declare_discovery_extension, extract_discovery_info, bazaar_resource_server_extension).

- [create-python-x402-facilitator.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-facilitator.md) — Facilitator creation guide (includes Bazaar setup in Steps 6-10)
- [create-python-x402-facilitator-reference.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-facilitator-reference.md) — Facilitator + Bazaar API reference
- [create-python-x402-facilitator-examples.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/create-python-x402-facilitator-examples.md) — Facilitator + Bazaar code examples

### Low-Level SDK Usage

Use x402-avm core components and AVM mechanism directly for custom integrations. Covers x402Client, x402ResourceServer, x402Facilitator, AVM signer protocols, constants, utilities, transaction encoding, and fee abstraction.

- [use-python-x402-core-avm.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/use-python-x402-core-avm.md) — Core SDK usage guide
- [use-python-x402-core-avm-reference.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/use-python-x402-core-avm-reference.md) — Core/AVM API reference
- [use-python-x402-core-avm-examples.md](https://skilld.dev/api/skills-raw/algorandfoundation/algorand-agent-skills/algorand-x402-python/references/use-python-x402-core-avm-examples.md) — Core SDK code examples

## Python Package Quick Reference

One PyPI distribution (`x402-avm`) provides everything via extras. Import root is `x402`.

| Install spec | Purpose |
| ------------ | ------- |
| `x402-avm[avm]` | Core protocol + Algorand SDK (py-algorand-sdk) |
| `x402-avm[httpx,avm]` | Async HTTP client wrapper (httpx) with automatic 402 payment handling |
| `x402-avm[requests,avm]` | Sync HTTP client wrapper (requests) with automatic 402 payment handling |
| `x402-avm[fastapi,avm]` | FastAPI async payment middleware |
| `x402-avm[flask,avm]` | Flask sync payment middleware |
| `x402-avm[extensions,avm]` | Bazaar discovery extension |
| `x402-avm[all]` | All extras (EVM, SVM, AVM, all servers and clients, extensions) |

## How to Use This Skill

1. **Start here** to understand which reference you need
2. **Read the `{name}.md`** file for step-by-step implementation guidance
3. **Consult `{name}-reference.md`** for API details
4. **Use `{name}-examples.md`** for complete, runnable code samples
