156 lines
5.0 KiB
Python
Raw Permalink Normal View History

feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
"""Bazaar catalog for storing discovered x402 resources.
This module provides a simple in-memory catalog for discovered resources during e2e testing
"""
from datetime import datetime
from typing import Any
class DiscoveredResource:
"""A discovered resource entry in the bazaar catalog."""
def __init__(
self,
resource: str,
resource_type: str,
x402_version: int,
accepts: list[dict[str, Any]],
discovery_info: dict[str, Any] | None = None,
route_template: str | None = None,
extensions: dict[str, Any] | None = None,
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
) -> None:
self.resource = resource
self.type = resource_type
self.x402_version = x402_version
self.accepts = accepts
self.discovery_info = discovery_info
self.route_template = route_template
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
self.last_updated = datetime.now().isoformat()
self.extensions = extensions or {}
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
def to_dict(self) -> dict[str, Any]:
"""Convert to dictionary for JSON serialization."""
result: dict[str, Any] = {
"resource": self.resource,
"type": self.type,
"x402Version": self.x402_version,
"accepts": self.accepts,
"lastUpdated": self.last_updated,
"extensions": self.extensions,
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
}
if self.discovery_info:
result["discoveryInfo"] = self.discovery_info
if self.route_template:
result["routeTemplate"] = self.route_template
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
return result
class BazaarCatalog:
feat: Payment Identifier Extension SDK - Python (#1111) * feat(python): add payment-identifier extension types and constants - Add PaymentIdentifierInfo and PaymentIdentifierExtension Pydantic models - Add constants: PAYMENT_IDENTIFIER, PAYMENT_ID_MIN_LENGTH, PAYMENT_ID_MAX_LENGTH, PAYMENT_ID_PATTERN - Define PaymentIdentifierSchema type alias * feat(python): add payment-identifier utility functions - Add generate_payment_id() to create UUID v4-based payment IDs - Add is_valid_payment_id() to validate ID format (16-128 chars, alphanumeric + hyphens/underscores) * feat(python): add payment-identifier JSON Schema definition - Add payment_identifier_schema compliant with JSON Schema Draft 2020-12 - Schema validates required boolean and optional id string field * feat(python): add payment-identifier validation and extraction functions - Add ValidationResult dataclass for validation results - Add is_payment_identifier_extension() type guard - Add validate_payment_identifier() for full extension validation - Add extract_payment_identifier() to extract ID from PaymentPayload - Add extract_and_validate_payment_identifier() combined function - Add has_payment_identifier() to check extension presence - Add is_payment_identifier_required() to check requirement flag - Add validate_payment_identifier_requirement() for requirement compliance * feat(python): add payment-identifier client utilities - Add append_payment_identifier_to_extensions() to append payment ID to extensions dict - Only appends if server declared the extension - Generates new ID if not provided * feat(python): add payment-identifier resource server utilities - Add declare_payment_identifier_extension() to create extension declaration - Add PaymentIdentifierResourceServerExtension class implementing ResourceServerExtension protocol - Add payment_identifier_resource_server_extension singleton instance * feat(python): add payment-identifier extension main module - Export all public APIs from payment-identifier extension - Add comprehensive usage documentation with examples for servers, clients, and idempotency * feat(python): export payment-identifier extension from extensions module - Add payment-identifier imports and exports to main extensions __init__.py - Export all constants, types, functions, and classes for public API * fix(python): resolve ValidationResult type mismatch in extensions module - Export payment_identifier.ValidationResult as ValidationResult (matches payment_identifier function return types) - Export bazaar.ValidationResult as BazaarValidationResult for explicit bazaar usage - Both ValidationResult classes are structurally equivalent (same dataclass fields) - Fixes type mismatch where payment_identifier functions returned payment_identifier.ValidationResult but ValidationResult imported from x402.extensions was bazaar.ValidationResult * refactor(python): rename payment_identifier ValidationResult to PaymentIdentifierValidationResult - Rename ValidationResult class to PaymentIdentifierValidationResult in payment_identifier/validation.py - Update all function return types and usages throughout validation.py - Update exports in payment_identifier/__init__.py - Update imports/exports in extensions/__init__.py - Keep ValidationResult from bazaar as default export for backward compatibility - Export PaymentIdentifierValidationResult separately for explicit payment_identifier usage - Makes naming consistent with BazaarValidationResult pattern * test(python): add comprehensive test suite for payment_identifier extension - Add test_types.py: Test constants and Pydantic models - Add test_utils.py: Test ID generation and validation functions - Add test_validation.py: Test all validation and extraction functions - Add test_client.py: Test client-side utilities - Add test_server.py: Test server-side utilities - Tests cover all major functionality including edge cases and error handling - Follows same structure as bazaar extension tests * fix(python): fix payment_identifier test helper and assertions - Fix create_extension_with_id helper to handle invalid IDs for testing - Update test assertion to check for 'identifier' in error message - All 67 tests now passing * fix(python): add ValidationResult alias for backward compatibility - Add ValidationResult = BazaarValidationResult alias after bazaar import - Fixes AttributeError when importing ValidationResult from x402.extensions - ValidationResult was imported as BazaarValidationResult but exported in __all__ - Now both ValidationResult and BazaarValidationResult are available * test(python): add test to verify __all__ exports are importable - Add test_exports.py to verify all items in __all__ can be imported - Tests that ValidationResult alias works correctly - Tests that 'import *' works as expected - This would have caught the ValidationResult AttributeError bug * fix(python): make jsonschema import lazy in payment_identifier validation - Remove module-level jsonschema import that raised ImportError - Import jsonschema lazily only when schema validation is needed - Return validation error instead of raising ImportError at module level - Allows payment_identifier extension to be imported without jsonschema - Users can still use non-validation functions without optional dependency * fix(python): fix linting errors - Remove unused variable in test_types.py - Fix import sorting in extensions/__init__.py - Add noqa comment for intentional E402 (import after alias) * Lint * docs(python): add payment-identifier extension examples Add client and server examples demonstrating how to use the payment-identifier extension for idempotent payment processing. Client example shows: - Generating payment IDs with generate_payment_id() - Using on_before_payment_creation hook to inject the ID - Making duplicate requests to demonstrate cache behavior Server example shows: - Declaring extension support with declare_payment_identifier_extension() - Extracting payment IDs with extract_payment_identifier() - Caching responses after settlement for idempotency * Lint * Format * Changelog
2026-02-11 18:46:46 -05:00
"""Catalog for storing discovered x402 resources."""
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
def __init__(self) -> None:
self._resources: dict[str, DiscoveredResource] = {}
def catalog_resource(
self,
resource_url: str,
method: str,
x402_version: int,
discovery_info: dict[str, Any] | None,
payment_requirements: dict[str, Any],
route_template: str | None = None,
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
) -> None:
"""Add a discovered resource to the catalog.
Args:
resource_url: The URL of the discovered resource.
method: The HTTP method (GET, POST, etc.).
x402_version: The x402 protocol version.
discovery_info: Optional discovery metadata.
payment_requirements: The payment requirements for this resource.
route_template: Optional route template for dynamic routes.
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
"""
print(f"📝 Discovered resource: {resource_url}")
print(f" Method: {method}")
print(f" x402 Version: {x402_version}")
if route_template:
print(f" Route template: {route_template}")
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
self._resources[resource_url] = DiscoveredResource(
resource=resource_url,
resource_type="http",
x402_version=x402_version,
accepts=[payment_requirements],
discovery_info=discovery_info,
route_template=route_template,
extensions={},
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
)
feat: Payment Identifier Extension SDK - Python (#1111) * feat(python): add payment-identifier extension types and constants - Add PaymentIdentifierInfo and PaymentIdentifierExtension Pydantic models - Add constants: PAYMENT_IDENTIFIER, PAYMENT_ID_MIN_LENGTH, PAYMENT_ID_MAX_LENGTH, PAYMENT_ID_PATTERN - Define PaymentIdentifierSchema type alias * feat(python): add payment-identifier utility functions - Add generate_payment_id() to create UUID v4-based payment IDs - Add is_valid_payment_id() to validate ID format (16-128 chars, alphanumeric + hyphens/underscores) * feat(python): add payment-identifier JSON Schema definition - Add payment_identifier_schema compliant with JSON Schema Draft 2020-12 - Schema validates required boolean and optional id string field * feat(python): add payment-identifier validation and extraction functions - Add ValidationResult dataclass for validation results - Add is_payment_identifier_extension() type guard - Add validate_payment_identifier() for full extension validation - Add extract_payment_identifier() to extract ID from PaymentPayload - Add extract_and_validate_payment_identifier() combined function - Add has_payment_identifier() to check extension presence - Add is_payment_identifier_required() to check requirement flag - Add validate_payment_identifier_requirement() for requirement compliance * feat(python): add payment-identifier client utilities - Add append_payment_identifier_to_extensions() to append payment ID to extensions dict - Only appends if server declared the extension - Generates new ID if not provided * feat(python): add payment-identifier resource server utilities - Add declare_payment_identifier_extension() to create extension declaration - Add PaymentIdentifierResourceServerExtension class implementing ResourceServerExtension protocol - Add payment_identifier_resource_server_extension singleton instance * feat(python): add payment-identifier extension main module - Export all public APIs from payment-identifier extension - Add comprehensive usage documentation with examples for servers, clients, and idempotency * feat(python): export payment-identifier extension from extensions module - Add payment-identifier imports and exports to main extensions __init__.py - Export all constants, types, functions, and classes for public API * fix(python): resolve ValidationResult type mismatch in extensions module - Export payment_identifier.ValidationResult as ValidationResult (matches payment_identifier function return types) - Export bazaar.ValidationResult as BazaarValidationResult for explicit bazaar usage - Both ValidationResult classes are structurally equivalent (same dataclass fields) - Fixes type mismatch where payment_identifier functions returned payment_identifier.ValidationResult but ValidationResult imported from x402.extensions was bazaar.ValidationResult * refactor(python): rename payment_identifier ValidationResult to PaymentIdentifierValidationResult - Rename ValidationResult class to PaymentIdentifierValidationResult in payment_identifier/validation.py - Update all function return types and usages throughout validation.py - Update exports in payment_identifier/__init__.py - Update imports/exports in extensions/__init__.py - Keep ValidationResult from bazaar as default export for backward compatibility - Export PaymentIdentifierValidationResult separately for explicit payment_identifier usage - Makes naming consistent with BazaarValidationResult pattern * test(python): add comprehensive test suite for payment_identifier extension - Add test_types.py: Test constants and Pydantic models - Add test_utils.py: Test ID generation and validation functions - Add test_validation.py: Test all validation and extraction functions - Add test_client.py: Test client-side utilities - Add test_server.py: Test server-side utilities - Tests cover all major functionality including edge cases and error handling - Follows same structure as bazaar extension tests * fix(python): fix payment_identifier test helper and assertions - Fix create_extension_with_id helper to handle invalid IDs for testing - Update test assertion to check for 'identifier' in error message - All 67 tests now passing * fix(python): add ValidationResult alias for backward compatibility - Add ValidationResult = BazaarValidationResult alias after bazaar import - Fixes AttributeError when importing ValidationResult from x402.extensions - ValidationResult was imported as BazaarValidationResult but exported in __all__ - Now both ValidationResult and BazaarValidationResult are available * test(python): add test to verify __all__ exports are importable - Add test_exports.py to verify all items in __all__ can be imported - Tests that ValidationResult alias works correctly - Tests that 'import *' works as expected - This would have caught the ValidationResult AttributeError bug * fix(python): make jsonschema import lazy in payment_identifier validation - Remove module-level jsonschema import that raised ImportError - Import jsonschema lazily only when schema validation is needed - Return validation error instead of raising ImportError at module level - Allows payment_identifier extension to be imported without jsonschema - Users can still use non-validation functions without optional dependency * fix(python): fix linting errors - Remove unused variable in test_types.py - Fix import sorting in extensions/__init__.py - Add noqa comment for intentional E402 (import after alias) * Lint * docs(python): add payment-identifier extension examples Add client and server examples demonstrating how to use the payment-identifier extension for idempotent payment processing. Client example shows: - Generating payment IDs with generate_payment_id() - Using on_before_payment_creation hook to inject the ID - Making duplicate requests to demonstrate cache behavior Server example shows: - Declaring extension support with declare_payment_identifier_extension() - Extracting payment IDs with extract_payment_identifier() - Caching responses after settlement for idempotency * Lint * Format * Changelog
2026-02-11 18:46:46 -05:00
def get_resources(self, limit: int = 100, offset: int = 0) -> dict[str, Any]:
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
"""Get paginated list of discovered resources.
Args:
limit: Maximum number of resources to return.
offset: Number of resources to skip.
Returns:
Dictionary with x402Version, items, and pagination info.
"""
all_resources = list(self._resources.values())
total = len(all_resources)
items = all_resources[offset : offset + limit]
return {
"x402Version": 2,
"items": [r.to_dict() for r in items],
"pagination": {
"limit": limit,
"offset": offset,
"total": total,
},
}
def search_resources(
self,
query: str,
resource_type: str | None = None,
limit: int | None = None,
) -> dict[str, Any]:
"""Search resources using case-insensitive keyword matching.
Matches against the resource URL, type, and extension values.
Args:
query: The search query string.
resource_type: Optional filter by resource type.
limit: Optional advisory maximum number of results.
Returns:
Dictionary with x402Version, items, and optional pagination hints.
"""
needle = query.lower()
results = []
for r in self._resources.values():
haystack = " ".join(
[r.resource, r.type] + [str(v) for v in r.extensions.values()]
).lower()
if needle in haystack:
results.append(r)
if resource_type:
results = [r for r in results if r.type == resource_type]
items = results[:limit] if limit is not None else results
return {
"x402Version": 2,
"resources": [r.to_dict() for r in items],
"partialResults": False,
"pagination": None,
}
feat: New Python SDK with v2 support (#841) * chore: renamed python/x402 to python/legacy * feat: initial Python core SDK * feat: added core HTTP wrappers * feat: added core types * feat: added evm mechanism for exact v1/v2 * feat: added httpx client * feat: added requests client * feat: added fastapi middleware * feat: added flask middleware * feat: added integration tests * feat: added Python SDK to e2e tests * python-v2: fix workflow checks (#863) * fix format * fix lint * fix build * fix pytest * Fix syntax errors and missing imports in manual integration example (#902) - Add missing imports (base64, json, Response, JSONResponse, PaymentPayload, FacilitatorClient) - Fix function signature syntax error - Fix dict initialization syntax (colon to equals) - Add missing return statement after successful payment - Remove trailing whitespace * feat: add Python SDK v2 server examples (FastAPI, Flask) (#879) * feat: add fastapi example project configuration * feat: add fastapi example with x402 payment middleware * docs: add comprehensive README for fastapi example * feat: add flask example project configuration * feat: add flask example with x402 payment middleware * docs: add comprehensive README for flask example * feat: add test clients for fastapi and flask examples * docs: add test client usage to READMEs * chore - remove python-version and test-client.py * docs - remove test client guide from README.md * chore - remove license and classifier * feat - add description and mime type * feat - update .env-local * feat: add Python v2 client examples (httpx & requests) (#857) * feat: add Python v2 client examples (httpx & requests) Add simple client examples demonstrating httpx (async) and requests (sync) usage with the x402 Python v2 SDK. - examples/python/clients/example.py - Simple example showing both httpx and requests - Uses EthAccountSigner with register_exact_evm_client helper - Minimal configuration required * refactor: split Python client examples into separate directories Address PR review feedback: - Separate httpx/ and requests/ directories - Add pyproject.toml for uv sync support - Add environment variable validation - Add payment response header extraction - Use context manager for requests session cleanup Tested on Base Sepolia testnet: - httpx: tx 0xce49f668aba01c4b0b1af2eb0d9a381f4c62295506a91f20af479e0e834ef350 - requests: tx 0xb83b6feefa5a744b7779ba5b37df33f9c7241f58119454d66102acd97a92f024 * Update examples/python/clients/httpx/main.py Co-authored-by: phdargen <pdargent@icloud.com> * Update examples/python/clients/requests/main.py Co-authored-by: phdargen <pdargent@icloud.com> --------- Co-authored-by: phdargen <pdargent@icloud.com> * feat(python): Make v2 framework and client dependencies optional extras (#901) * python-v2: add svm mechanism (#904) * add svm mechanism * add unit tests * add integration tests * update server examples * add e2e tests * update clients * make EVM/SVM dependencies optional extras * fix legacy uv paths * V2 python bazaar (#929) * add bazaar extension * strip query params for discovery * fix 862 * updated e2e tests * Add advanced Python client examples (#947) * Add advanced Python client examples Implements 5 advanced patterns demonstrating x402 SDK v2 features: - hooks.py: Payment lifecycle hooks (before, after, failure) - preferred_network.py: Custom network preference selector - builder_pattern.py: Network-specific registration with wildcards - error_recovery.py: Error classification and recovery strategies - custom_transport.py: Custom httpx transport with retry/timing Includes: - CLI entry point (index.py) for running examples - Comprehensive test suite (40 unit tests) - E2E integration tests - README documentation All tests passing. * Remove tests and examples beyond TypeScript SDK parity Address PR review feedback: - Remove tests directory (tests belong in SDK, not examples) - Remove custom_transport.py (runtime error, beyond TS parity) - Remove error_recovery.py (duplicate of hooks.py, beyond TS parity) - Update index.py, README.md, pyproject.toml accordingly * Address PR feedback: add SVM support and use optional deps - Update pyproject.toml to use x402[evm,svm,httpx] instead of listing dependencies separately - Add Solana/SVM network examples to preferred_network.py - Support both EVM and SVM signers for cross-chain flexibility - Update .env-local with SOLANA_PRIVATE_KEY option * Python-v2: facilitator example + e2e (#950) * add facilitator example * improve svm signer * add description to DiscoveredResource * add facilitator e2e * add paywall builder (#953) * Add Python custom client example (#954) Demonstrates manual x402 v2 payment flow without convenience wrappers. Shows the 6-step process: 1. Initialize client and register payment schemes 2. Make initial request, receive 402 3. Decode PAYMENT-REQUIRED header 4. Create signed payment payload 5. Retry with PAYMENT-SIGNATURE header 6. Handle success/failure response Useful for integrating with non-standard HTTP libraries or implementing custom retry logic. * feat(v2-sdk): support async dynamic hooks for price and metadata (#900) * feat(http): implement dual class design for sync/async support - Add x402HTTPResourceServer (async) for FastAPI/Starlette - Add x402HTTPResourceServerSync (sync) for Flask/Django - Share common logic via _x402HTTPServerBase - Remove dynamic description/resource (keep only dynamic price/payTo) - Update Flask middleware to use sync server directly - Integrate with enrich_extensions for bazaar support - Add per-route hook_timeout_seconds configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(types): add missing Awaitable import and fix test import sorting - Add Awaitable import to types.py for DynamicPayTo/DynamicPrice type hints - Fix import block sorting in test_async_hooks.py and test_core.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: simplify API by removing unused types and making timeout opt-in Address reviewer feedback from @phdargen: - Remove SyncDynamicPayTo/SyncDynamicPrice (unused types that would require SyncPaymentOption to be useful) - Change hook_timeout_seconds default to None (opt-in, matching TS/Go parity) - Export x402HTTPResourceServerSync from http/__init__.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * python-v2: make create_facilitator_config work with both V1 and V2 (#968) * make create_facilitator_config work with both V1 and V2 * fix lint * feat: add Python SDK v2 server advanced example (FastAPI) (#952) * feat - add pyproject.toml, uv.lock for advanced example * feat - add bazaar extension * feat - add hooks * feat - add x402 extensions to pyproject.toml * feat - add dynamic pricing feature * feat - add dynamic pay-to and custom money parser features * docs - add README for advanced server example * style - apply lint * chore - add comments for bazaar extension code * fix: python v2 x402HTTPAdapter retry logic (#978) * fix: fix consecutive payment bug in x402HTTPAdapter - Replace instance-level _is_retry flag with per-request header to prevent state leakage between consecutive 402 requests. * tests - add test case for consecutive payment with x402HTTPAdapter * style - apply lint * Python-v2: async lifecycle hooks (#975) * add dual sync/async classes for server/client/facilitator * update integration/e2e tests * add unit tests for core, http and implement wrapHttpxWithPaymentFromConfig/wrapRequestsWithPayment * refactor core server/client/facilitator * refactor x402_http_server/facilitator_client/x402_http_client * update exmamples * add utility function that takes care of html-safe escaping * add sdk readmes * add retry unit tests to httpx client * Update Python SDK Docs for v2 (#976) * Porting docs and updating for v2 changes (#813) * porting docs and updating for v2 changes * update quickstart for sellers * update quickstarts, miniapps, and mcp docs * update doc links * update FAQs * fix getting started docs * update core concepts * remove miniapps guide * update extensions * fix bazaar code examples * fix broken links and yaml file * remove unnecessary protocol layer doc * add migration guide * update documentation for python v2 sdk * testing pr preview * docs(python): remove unused os imports and align with TS tab patterns - Remove unused 'import os' from FastAPI and Flask examples in quickstart-for-sellers - Update bazaar-discovery-layer Python example to use hardcoded '0xYourPrivateKey' to match TypeScript tab consistency * update migration doc * cleanup comments * cleanup readme * fix: Python facilitator e2e code * fix: lint --------- Co-authored-by: phdargen <p.dargent@cern.ch> Co-authored-by: somesome <57699892+sohw400@users.noreply.github.com> Co-authored-by: Logan Kang <kcs93023@gmail.com> Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: phdargen <pdargent@icloud.com> Co-authored-by: Vladimir Sotnikov <bubert9@gmail.com> Co-authored-by: Shuhei <shuhei0866@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Faris Habib <faris.habib@coinbase.com>
2026-01-21 16:32:07 -08:00
def get_count(self) -> int:
"""Get total count of discovered resources."""
return len(self._resources)