Skip to main content

stellar-xdr

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.1.0

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.1.0
File Size Uploaded Provenance Actions
stellar_xdr-0.1.0.tar.gz 1.9 MB With provenance Details for stellar_xdr-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 2.2 MB

Release files / stellar_xdr-0.1.0.tar.gz

Download URL stellar_xdr-0.1.0.tar.gz
Size 1.9 MB
Tags Source
SHA-256 checksum
How to use checksums
b7a82f22f9294636741923bc7bedc83917bf1c479dc8259f0c56b1e211320a98
BLAKE2b-256 checksum
How to use checksums
9efbd836cc20ae3aa12ca4c467cc0b16c9dfe8162fa0c01b7e40be6b65480d0f
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 10, 2026.

Transparency log

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

Download URL stellar_xdr-0.1.0-py3-none-any.whl
Size 269.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8b61a7cf016898d1e6d707fd9fe11330d5a37a6bdcd32bc69fe513445ca93cb
BLAKE2b-256 checksum
How to use checksums
1aedd8a5fb14898b595c2240ce9f7a49a3043716e5cf44c761bf7564fd197cc0
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 10, 2026.

Transparency log

Security for stellar-xdr 0.1.0

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.1.0.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 10, 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