Phantasma Python SDK
Typed Python SDK for the Phantasma blockchain with support for the Phoenix chain update.
The package provides JSON-RPC access, transaction building and signing, VM script helpers, Ed25519 keys/signatures, and Carbon wire-format support.
The public API uses Python naming conventions, dataclasses, exceptions, and type hints. Fixture tests lock shared VM and Carbon wire formats against reference SDK vectors.
Requirements
- Python 3.11 or newer
cryptographyrequests
Development uses uv, ruff, mypy, and pytest.
Install
pip install phantasma-sdk-py
For local development:
uv sync --extra dev
just check
Modules
phantasma_py.crypto: addresses, hashes, WIF keys, Ed25519 signaturesphantasma_py.vm: VM objects, opcodes, andScriptBuilderphantasma_py.transaction: VM script transaction serialization/signingphantasma_py.rpc: JSON-RPC client and typed response dataclassesphantasma_py.carbon: Carbon primitives, VM schemas, module call args, token builders, and transaction messages
RPC
from phantasma_py.rpc import PhantasmaRPC
rpc = PhantasmaRPC.mainnet()
account = rpc.get_account("P...")
balance = account.get_token_balance("SOUL", decimals=8)
print(balance.decimal_amount())
JsonRpcClient validates JSON-RPC response ids, propagates RPC errors as
RPCError, and accepts endpoints that echo numeric ids as strings.
Keys And Signatures
from phantasma_py.crypto import PhantasmaKeys
keys = PhantasmaKeys.from_wif("...")
signature = keys.sign(b"message")
assert signature.verify(b"message", [keys.address])
Address parsing rejects malformed Base58/checksum data. Address.from_text("NULL")
and Address.null() produce the system null address.
VM Scripts
from phantasma_py.crypto import Address, PhantasmaKeys
from phantasma_py.vm import ScriptBuilder
keys = PhantasmaKeys.from_wif("...")
script = (
ScriptBuilder.begin()
.allow_gas(keys.address, Address.null(), gas_price=10_000, gas_limit=210_000)
.call_contract("stake", "GetStake", keys.address)
.spend_gas(keys.address)
.end_script()
)
end_script() raises BuilderError if labels or user input are invalid.
end_script_with_error() returns (script, error) for callers that prefer an
explicit checked path.
VM Script Transactions
from phantasma_py.crypto import PhantasmaKeys
from phantasma_py.transaction import Transaction
from phantasma_py.vm import ScriptBuilder
keys = PhantasmaKeys.from_wif("...")
script = ScriptBuilder.begin().call_interop("Runtime.Time").end_script()
tx = Transaction("mainnet", "main", script, expiration=1_754_000_000)
tx.sign(keys)
raw_hex = tx.to_bytes().hex()
Broadcasting is intentionally separate from signing:
tx_hash = rpc.send_raw_transaction(raw_hex)
Do not run broadcasting examples without explicit credentials, funds, and an endpoint you intend to use.
Carbon
Carbon serialization uses fixed-width little-endian integers, zero-terminated
strings, fixed byte types, compact signed Int256 values, and typed transaction
payloads. Use serialize() and deserialize() for stable wire round-trips.
from phantasma_py.carbon import (
Bytes32,
IntX,
build_token_info,
build_token_metadata,
prepare_standard_token_schemas,
serialize,
)
owner = Bytes32()
schemas = prepare_standard_token_schemas(shared_metadata=False)
token = build_token_info(
symbol="ART",
max_supply=IntX(0),
is_nft=True,
decimals=0,
owner=owner,
metadata=build_token_metadata(
{
"name": "Art Token",
"icon": "data:image/png;base64,AA==",
"url": "https://example.invalid/art",
"description": "Example token metadata",
}
),
token_schemas=serialize(schemas),
)
payload = serialize(token)
Carbon token and NFT helpers validate required metadata, token symbol casing,
standard schema fields, Carbon NFT address packing, and result parsing. Token
symbols follow the Carbon token-module rule of uppercase ASCII letters A-Z.
Carbon transaction signing is available without going through RPC:
from phantasma_py.carbon import sign_and_serialize_tx_msg_hex
from phantasma_py.crypto import PhantasmaKeys
keys = PhantasmaKeys.from_wif("...")
raw_hex = sign_and_serialize_tx_msg_hex(tx_msg, keys)
Development
just f # format and autofix
just f-check # verify formatting and lint
just typecheck # strict mypy
just test # pytest
just build # package build
just check # all checks above
The shared Carbon vector fixture in tests/fixtures/carbon_vectors.tsv is
copied from the Go SDK and should stay byte-for-byte compatible across SDKs.
Metadata
Release files for phantasma-sdk-py 2.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| phantasma_sdk_py-2.5.0.tar.gz | 284.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| phantasma_sdk_py-2.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 339.7 kB
Release files / phantasma_sdk_py-2.5.0.tar.gz
| Download URL | phantasma_sdk_py-2.5.0.tar.gz |
|---|---|
| Size | 284.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e11276eea8540a4edf2f557f9ea53aa5f6265b8350e863b8bc4bd7a12276689f
|
|
BLAKE2b-256 checksum How to use checksums |
d91e0cea7c862ef8a8d5d3f522aee9bbcf71b1c70c71b3a9d801332f1d07dcb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Release files / phantasma_sdk_py-2.5.0-py3-none-any.whl
| Download URL | phantasma_sdk_py-2.5.0-py3-none-any.whl |
|---|---|
| Size | 54.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36580bae9a0a9899d8d045322c13c7ff2bf56015e7acb5b224b3c2cdcdf72bdf
|
|
BLAKE2b-256 checksum How to use checksums |
7cce24d2081030e821af00cb822243de5dc9c8d5c27dfe88677e4b078b174292
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|