-
Notifications
You must be signed in to change notification settings - Fork 1k
Add advanced Python client examples #947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add advanced Python client examples #947
Conversation
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.
|
@1bcMax is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
| "x402", | ||
| "eth-account>=0.13.0", | ||
| "python-dotenv>=1.0.0", | ||
| "httpx>=0.27.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use the new import pattern for optional dependencies introduced in #901, see eg https://github.com/coinbase/x402/blob/feat/python-v2-sdk/examples/python/clients/httpx/pyproject.toml
| "x402", | |
| "eth-account>=0.13.0", | |
| "python-dotenv>=1.0.0", | |
| "httpx>=0.27.0", | |
| "x402[evm,svm,httpx]", | |
| "python-dotenv>=1.0.0", |
|
Please remove all the tests, these belong in the sdk, not the examples. If you identified any missing test coverage in the sdk, please move them to python/x402/tests |
| NETWORK_PREFERENCES = [ | ||
| "eip155:8453", # Base mainnet (preferred - low fees) | ||
| "eip155:42161", # Arbitrum One | ||
| "eip155:10", # Optimism | ||
| "eip155:1", # Ethereum mainnet (fallback) | ||
| "eip155:84532", # Base Sepolia (testnet) | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also include svm here
|
Suggest renaming custom_transport.py -> retry_transport.py |
Actually |
|
Hi @1bcMax, thanks a lot for your contribution! Please have a look at my comments above |
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
|
@phdargen Hey my buddy, i have moved the test code as you suggest. |
|
Great thanks @1bcMax, could you please also address the other 2 comments above (imports and svm)? |
- 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
|
Addressed the feedback:
Ready for re-review! |
|
Thanks for the update @1bcMax, LGTM 🚀 |
Summary
Adds 5 advanced Python client examples demonstrating x402 SDK v2 features.
Part of #841 - addresses TODO item: "Add advanced/custom Python client examples"
Examples
hooks.pypreferred_network.pybuilder_pattern.pyerror_recovery.pycustom_transport.pyFeatures
index.py) for running examplesTest Results
Usage
Checklist
feat/python-v2-sdkbranchpyproject.tomlwithuv syncsupport