Skip to main content

py-stellar-xdr

A Python library to encode and decode Stellar XDR, the binary format of transactions, ledger entries, contract values and everything else on the Stellar network, and its SEP-51 JSON form.

  • Complete. Every type of the network's XDR definitions, generated from them, with a release for each protocol version; stellar_xdr.PROTOCOL_VERSION says which.
  • Strict. Binary decoding accepts only the one canonical encoding of a value. Constructors check their arguments, so any value that exists can be encoded as XDR.
  • Typed. Immutable classes, unions you can match on, and complete type hints that mypy and pyright check in strict mode.
  • Thoroughly tested. Every type and union arm is tested with random values, and the tests cover 100% of the branches of the code. On top of that, real data from the public networks decodes and encodes back unchanged, and JSON matches the reference implementation value for value.

Install

pip install stellar-xdr

Usage

import json

import stellar_xdr as xdr

# Decode a transaction envelope, as Stellar's APIs return it.
envelope = xdr.TransactionEnvelope.from_xdr_base64(
    "AAAAAgAAAADmmSZkwY3163TMouB2TY8MljqXw2IxVYTGyvDrR6YtAAAqmmQAABpuAAAAAQAAAAAAAAAAAAAAAQ"
    "AAAAAAAAAYAAAAAQAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAABAAAABgAAAAHXkotywnA8z+r365/0"
    "701QSlWouXn8m0UOoshCtNHOYQAAABQAAAABAAI9fQAAAAAAAAD4AAAAAAAqmgAAAAABR6YtAAAAAEArDtxbqU"
    "I+CsdkRmV0lFhVt0wyB7fyrmmkM6Fr35wpPcK8WKcXeKTl4BQ+akE14MZtpaea9LMdhXopaW3pJA0E"
)

# A union is one class per arm, so match tells them apart.
match envelope:
    case xdr.TransactionEnvelope.Tx(v1):
        transaction = v1.tx
    case _:
        raise ValueError("expected a v1 transaction")
assert transaction.fee == 2792036
assert isinstance(transaction.operations[0].body, xdr.OperationBody.InvokeHostFunction)

# Build a value. Strings accept str, and arrays any sequence.
args = xdr.SCVal.Vec(
    [xdr.SCVal.Symbol("transfer"), xdr.SCVal.I128(xdr.Int128Parts(0, 100))]
)
assert xdr.SCVal.from_xdr_base64(args.to_xdr_base64()) == args

# SEP-51 JSON, ready for json.dumps.
assert json.dumps(args.to_json_value()) == (
    '{"vec": [{"symbol": "transfer"}, {"i128": "100"}]}'
)
assert xdr.SCVal.from_json_value(json.loads('{"u32": 5}')) == xdr.SCVal.U32(5)

The guide covers values, unions, decoding, errors and JSON in more detail.

Development

The project uses uv.

make check       # lint, type-check and test
make generate    # regenerate the package from xdr/xdr.json
make docs-serve  # preview the documentation

The modules of the package, other than _runtime, are generated by generator/ from xdr/xdr.json, a description of the network's .x files. xdr/source.toml records where the file comes from. To move to another version:

make update-xdr COMMIT=<full commit hash>
make generate

The tests also check the package against data from the public networks and from the reference implementation. tests/vectors/README.md describes that data and how to update it with a new version.

License

Apache-2.0

Metadata

Release files for stellar-xdr 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stellar-xdr 0.2.1
File Size Uploaded Provenance Actions
stellar_xdr-0.2.1.tar.gz 1.8 MB With provenance Details for stellar_xdr-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stellar-xdr 0.2.1
File Interpreter ABI Platform Actions
stellar_xdr-0.2.1-py3-none-any.whl Python 3 none any Details for stellar_xdr-0.2.1-py3-none-any.whl

Total release size: 2.1 MB

Release files / stellar_xdr-0.2.1.tar.gz

Download URL stellar_xdr-0.2.1.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
1e707c35877fab6e4926596c234902a6d7fdb3db9b82add5e0d11ca26fa0a7a6
BLAKE2b-256 checksum
How to use checksums
44cdfb710c27a23cbc265836a3897ddd69b86d1e8b876534195cedbab3fc055c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / stellar_xdr-0.2.1-py3-none-any.whl

Download URL stellar_xdr-0.2.1-py3-none-any.whl
Size 281.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5169dee7de0e89bc346b2409939424518c7b0c6a0a512083532097c6235650ac
BLAKE2b-256 checksum
How to use checksums
68076b4205c41607f7fe0d9714fdb4c56baf868335e2356e20e597aa59c3fe15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Security for stellar-xdr 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for stellar_xdr-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page