Skip to main content

stellar-strkey

Encode and decode Stellar strkeys, the G..., C... and M... strings that identify accounts, contracts, signers and other things on the Stellar network.

  • Complete. Supports every strkey type defined by SEP-23.
  • Strict. Accepts a strkey only in its one canonical form and rejects everything else with a clear error, so invalid input never gets through.
  • Thoroughly tested. Verified against the SEP-23 test cases and a shared set of test vectors, with property-based tests and 100% branch coverage.
  • Safe with secrets. Secret seeds are never printed or serialized by accident, and error messages never include the input.
  • Lightweight. Fully typed, pure Python, no dependencies.

The documentation has the guide and the API reference.

Install

pip install stellar-strkey

Usage

from stellar_strkey import (
    Contract,
    Ed25519PublicKey,
    MuxedEd25519Account,
    StrkeyError,
    parse,
)

# When you know the type, use its class. Anything else is rejected.
key = Ed25519PublicKey.from_string(
    "GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ"
)
assert key.key.hex() == (
    "3f0c34bf93ad0d9971d04ccc90f705511c838aad9734a4a2fb0d7a03fc7fe89a"
)
# The same 32 bytes as a contract give a different strkey.
assert str(Contract(key.key)) == (
    "CA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUWDA"
)

# When you don't, parse() returns the matching class.
match parse("MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAJLK"):
    case Ed25519PublicKey(key):
        description = f"account {key.hex()}"
    case MuxedEd25519Account(key, id):
        description = f"muxed account {key.hex()} with ID {id}"
    case other:
        description = f"something else: {other!r}"
assert description.endswith("with ID 9223372036854775808")

# Invalid input raises StrkeyError, which is a ValueError.
try:
    parse("GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGA")
except StrkeyError as error:
    message = str(error)
assert message == "strkey checksum does not match"

Secret seeds

Secret seeds (S...) have their own parser, and parse() refuses them, so code that handles arbitrary addresses can't pick up a secret by accident:

from stellar_strkey import Ed25519PrivateKey, WrongStrkeyTypeError, parse

# In real code, load the secret from the environment or a secret store, never from
# source code. This is a well-known test seed.
secret = "SBU2RRGLXH3E5CQHTD3ODLDF2BWDCYUSSBLLZ5GNW7JXHDIYKXZWHOKR"

key = Ed25519PrivateKey.from_string(secret)
seed = key.seed  # the raw 32 bytes, for example for an ed25519 signing library
assert len(seed) == 32

# Printing or logging the key never shows the seed.
assert str(key) == "<redacted>"
assert repr(key) == "Ed25519PrivateKey(<redacted>)"

# Get the strkey back only where you mean to.
assert key.reveal() == secret

try:
    parse(secret)
except WrongStrkeyTypeError as error:
    refused = error.found
assert refused is Ed25519PrivateKey

Types

Prefix Class Fields to_bytes() / from_bytes() layout
G Ed25519PublicKey key 32-byte key
S Ed25519PrivateKey seed 32-byte seed
M MuxedEd25519Account key, id 32-byte key, 8-byte big-endian ID
P Ed25519SignedPayload key, payload 32-byte key, XDR opaque<64> payload
T PreAuthTx hash 32-byte hash
X HashX hash 32-byte hash
C Contract hash 32-byte hash
L LiquidityPool hash 32-byte hash
B ClaimableBalance hash 0x00 version byte, 32-byte hash
W MuxedContract hash, id 32-byte hash, 8-byte big-endian ID

See the guide for how to handle errors, and for what private keys are protected against and what they aren't.

Development

uv sync --all-groups       # create the environment, including the docs tools
uv run prek install        # optional: check before each commit
make check                 # format check, lint, type checks and tests with coverage
make docs-serve            # preview the documentation

tests/vectors/strkeys.json holds the shared test vectors in a language neutral form. Add new cases there by hand, with the expected result that SEP-23 requires.

To release, run make release-prep VERSION=<version>, which sets the version and adds the commits since the last release to CHANGELOG.md. Edit the new section where a commit title isn't enough, commit it, then push a v<version> tag. The publish workflow verifies that the tag matches the version and publishes to PyPI with trusted publishing, along with PEP 740 attestations.

License

Apache-2.0

Metadata

Release files for stellar-strkey 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-strkey 0.1.0
File Size Uploaded Provenance Actions
stellar_strkey-0.1.0.tar.gz 33.6 kB With provenance Details for stellar_strkey-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 50.7 kB

Release files / stellar_strkey-0.1.0.tar.gz

Download URL stellar_strkey-0.1.0.tar.gz
Size 33.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b7901c38829171b1973fa278f509ae512cd2efd63f5beb8e1f98f72854b46198
BLAKE2b-256 checksum
How to use checksums
6aa65de38075ed7284519b19d821c0c5908eee690bed0b505693b568940f5017
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 7, 2026.

Transparency log

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

Download URL stellar_strkey-0.1.0-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a02bc88263354bde0b0d7fd1fedf52de987081f6d9c0e06453770113a4f71f23
BLAKE2b-256 checksum
How to use checksums
64c632a71b52ca90d8b7b35084881c5015db1fd805e8d4f9edbd037e178a5524
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 7, 2026.

Transparency log

Security for stellar-strkey 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_strkey-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 7, 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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