Skip to content

Rebuild Python SDK from Aptos SDK Specification v1.0.0 (Tier 2)#74

Open
gregnazario wants to merge 7 commits intomainfrom
from-spec
Open

Rebuild Python SDK from Aptos SDK Specification v1.0.0 (Tier 2)#74
gregnazario wants to merge 7 commits intomainfrom
from-spec

Conversation

@gregnazario
Copy link
Contributor

Summary

Ground-up rewrite of the Aptos Python SDK to fully conform to the Aptos SDK Specification v1.0.0, achieving Tier 2 (P0 + P1) compliance.

What changed

  • 19 modules rewritten from scratch against the spec (~11,550 lines of source)
  • 1,060 unit tests with 96% code coverage (up from ~50%)
  • 22 integration tests for devnet (transfer, fee-payer, simulation, secp256k1, node health)
  • Async-only using httpx with HTTP/2
  • Python 3.10+ minimum (3.9 is EOL)
  • Full design document at docs/python-DESIGN.md

New capabilities

Feature Spec Priority
Spec-aligned error hierarchy (30+ exception types) 08 P0
BIP-39/BIP-44 mnemonic key derivation 04 P1
TransactionBuilder pattern 05 P1
Configurable retry strategy with exponential backoff 06 P1
Domain-separated hashing (centralized) 03 P0
Full TypeTag string parsing (recursive descent) 01 P0
Structured API response dataclasses 06 P0
AIP-80 private key format 03 P1
AIP-40 address formatting 01 P0
SingleKey/MultiKey crypto wrappers 03 P1
Gas estimation 06 P1
Transaction simulation 06 P1
View function support (JSON + BCS) 06 P1
Fee-payer (sponsored) transactions 05 P1
Multi-agent transactions 05 P1

Removed modules (layered concerns)

  • aptos_token_client.py, aptos_tokenv1_client.py — token-specific
  • package_publisher.py — can use EntryFunction directly
  • transaction_worker.py, account_sequence_number.py — can build on core
  • aptos_cli_wrapper.py, cli.py — separate tooling concern
  • ans.py, fungible_asset.py — domain-specific layers

Breaking changes

Change Migration
Python 3.10+ required Upgrade Python
Error classes restructured Catch AptosError subtypes
AccountAddress.from_str()from_hex() Rename calls
Network config restructured Use Network.TESTNET etc.
TimeoutErrorAptosTimeoutError Avoids shadowing builtin
No sync API Wrap with asyncio.run()

Quality

  • mypy clean across aptos_sdk/, tests/, examples/
  • flake8 clean across all directories
  • black + isort formatted
  • All commits pass make fmt && make lint && make test

Module coverage breakdown

Module Coverage
__init__.py 100%
account.py 99%
account_address.py 100%
async_client.py 100%
authenticator.py 100%
bcs.py 95%
errors.py 100%
hashing.py 100%
transaction_builder.py 100%
transactions.py 99%
type_tag.py 97%
Overall 96%

Test plan

  • All 1,060 unit tests pass (make test)
  • mypy type checking clean (make lint)
  • flake8 linting clean (make lint)
  • black + isort formatting clean (make fmt)
  • Run integration tests against devnet (make integration_test)
  • Verify examples work against devnet (make examples)
  • Verify package installs cleanly (poetry install)

Ground-up rewrite of the Python SDK based on the Aptos SDK Specification
v1.0.0, targeting Tier 2 (P0 + P1) compliance with Python 3.10+.

New modules: errors, bcs, hashing, account_address, chain_id, type_tag,
asymmetric_crypto, ed25519, secp256k1_ecdsa, crypto_wrapper, account,
mnemonic, authenticator, transactions, transaction_builder, network,
retry, async_client.

Key features:
- Async-only API with httpx HTTP/2 client
- AIP-40 address formatting, AIP-80 private key formatting
- Ed25519 + Secp256k1 ECDSA with SingleKey/MultiKey auth
- BIP-39/SLIP-0010 mnemonic key derivation
- Fluent TransactionBuilder pattern
- Spec-aligned error hierarchy
- Retry with exponential backoff + jitter
- Full BCS serialization with option/variant_index/map/u256
- Clean mypy, flake8, black across all 19 modules

Removes legacy modules: account_sequence_number, aptos_cli_wrapper,
aptos_token_client, aptos_tokenv1_client, asymmetric_crypto_wrapper,
cli, metadata, package_publisher, transaction_worker.
16 test files covering 698 tests across all SDK modules:
- Foundation: errors (hierarchy+categories), bcs (serialize/deserialize
  round-trips for all types), hashing (SHA3-256, HashPrefix), chain_id
- Types: account_address (AIP-40, from_hex/str, BCS), type_tag (all
  primitive/struct/vector tags, parser, generics)
- Crypto: ed25519 (sign/verify, AIP-80, multi-key), secp256k1 (sign/verify,
  low-S normalization), crypto_wrapper (AnyPublicKey, MultiKey, bitmap)
- Accounts: account (generate, persist, mnemonic), mnemonic (BIP-39,
  SLIP-0010 derivation), network (all configs), retry (backoff, retryable)
- Transactions: transactions (RawTransaction sign/verify/BCS, EntryFunction),
  authenticator (all variant types, BCS), transaction_builder (fluent API)

All tests pass with 0 failures. Formatted with black+isort, flake8 clean.
71 tests covering response dataclasses, _raise_for_status error mapping,
context manager, all REST endpoints, wait_for_transaction polling,
FaucetClient, and legacy compatibility aliases. Total: 769 tests.
Remove unused json and Account imports from test_async_client.py
(flake8 F401). Simplify multi-line import in account_address.py.
- Add 22 integration tests across 5 files (transfer, simulate, node
  queries, fee-payer, secp256k1) with env-var driven network config
- Update 6 working examples to use new SDK API surface
- Remove 13 broken examples that imported deleted modules
- Fix CLAUDE.md to reflect current architecture (Python 3.10+, no
  IndexerClient, correct module listing and error names)
- Extend make lint to cover tests/ and examples/ (mypy + flake8)
- Fix mypy errors: implicit Optional, nullable comparisons, async
  generator return types, sign_transaction typing
- Replace legacy typing.List/Tuple with builtin generics in ed25519.py
- Add license headers to empty __init__.py files
- Add coverage config and integration marker to pyproject.toml
Add 291 new unit tests across 7 test files targeting previously
uncovered code paths:

- async_client.py: 78% → 100% (account_balance, modules, create/submit
  transactions, multi-agent, simulation, bcs_transfer, transfer_coins,
  view_bcs_payload, all legacy aliases)
- transactions.py: 79% → 99% (Script, ScriptArgument, Multisig,
  MultiAgent/FeePayer sign/verify/deserialize, SignedTransaction
  round-trips)
- authenticator.py: 84% → 100% (display methods, deserialization for
  all authenticator variants, verify paths)
- type_tag.py: 89% → 97% (primitive repr/eq, StructTag edge cases,
  deserialization variants, error paths)
- bcs.py: 89% → 95% (overflow/underflow, ULEB128 edge cases, u16/u256,
  encoder helper, truncated reads)
- crypto_wrapper.py: 88% → 97% (display methods, cross-variant
  rejection, MultiKey boundary cases)
- asymmetric_crypto.py: 67% → 77% (parse_hex_input, format_private_key
  edge cases)
Rewrites the pre-implementation planning document into a post-implementation
reference document reflecting the completed Tier 2 SDK rewrite: 19 modules,
11,550 lines, 1,060 tests at 96% coverage. Adds cross-language comparison
section, accurate module line counts, corrected test structure, and updated
spec compliance matrix with completion status.
@gregnazario gregnazario requested a review from a team as a code owner February 21, 2026 08:14
@gregnazario gregnazario requested a review from Copilot February 21, 2026 08:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR is a ground-up rewrite of the Aptos Python SDK to fully comply with the Aptos SDK Specification v1.0.0, achieving Tier 2 (P0 + P1) compliance. The SDK now provides comprehensive error handling, improved type safety, async-only operations, and modern Python 3.10+ support with 96% test coverage.

Changes:

  • Rebuilt 19 core modules (~11,550 lines) to align with SDK spec v1.0.0
  • Added 1,060 unit tests achieving 96% code coverage (up from ~50%)
  • Migrated to async-only architecture using httpx with HTTP/2
  • Removed legacy modules for token clients, CLI wrappers, and package publishers (moved to separate concerns)

Reviewed changes

Copilot reviewed 41 out of 81 changed files in this pull request and generated no comments.

Show a summary per file
File Description
examples/multisig.py Removed legacy multi-signature example (depends on removed modules)
examples/multikey.py Removed multi-key example (depends on removed modules)
examples/large_package_publisher.py Removed package publisher example (module removed)
examples/integration_test.py Simplified to only test fee-payer, secp256k1, simulation, and transfer
examples/hello_blockchain.py Removed hello blockchain example (depends on removed CLI wrapper)
examples/fee_payer_transfer_coin.py Updated to use new API (RestClient constructor, TransactionAuthenticator)
examples/common.py Simplified configuration (removed APTOS_CORE_PATH and INDEXER_URL)
examples/aptos_token.py Removed token client example (module removed)
examples/init.py Added copyright header to empty init file
docs/api/index.html Added redirect to generated API documentation
aptos_sdk/transaction_worker.py Removed transaction worker module (layered concern)
aptos_sdk/transaction_builder.py Added new fluent TransactionBuilder pattern per spec
aptos_sdk/retry.py Added exponential backoff retry strategy per spec
aptos_sdk/package_publisher.py Removed package publisher (layered concern)
aptos_sdk/network.py Added NetworkConfig dataclass and Network constants
aptos_sdk/mnemonic.py Added BIP-39/SLIP-0010 key derivation support
aptos_sdk/metadata.py Removed metadata module (no longer needed)
aptos_sdk/hashing.py Added centralized hashing with domain-separated prefixes
aptos_sdk/errors.py Added 30+ spec-aligned exception types
aptos_sdk/crypto_wrapper.py Added SingleKey/MultiKey wrappers per spec
aptos_sdk/cli.py Removed CLI module (separate tooling concern)
aptos_sdk/chain_id.py Added ChainId type per spec
aptos_sdk/bcs.py Rewrote BCS with improved error handling and protocols
aptos_sdk/asymmetric_crypto_wrapper.py Removed old crypto wrapper (replaced by crypto_wrapper.py)
aptos_sdk/asymmetric_crypto.py Rewrote as protocols with AIP-80 support
aptos_sdk/aptos_tokenv1_client.py Removed token v1 client (layered concern)
aptos_sdk/aptos_token_client.py Removed token client (layered concern)
aptos_sdk/aptos_cli_wrapper.py Removed CLI wrapper (separate tooling concern)
aptos_sdk/account_sequence_number.py Removed sequence number manager (layered concern)
aptos_sdk/account.py Rewrote with BIP-39 support, JSON persistence, and multiple key types
aptos_sdk/init.py Added comprehensive public API exports with version
Makefile Updated test/lint targets to use pytest and new directory structure
CLAUDE.md Added comprehensive project documentation for AI assistants

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants