py-stellar-strkey
A Python library to 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.
account = Ed25519PublicKey.from_string(
"GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ"
)
assert account.key.hex() == (
"3f0c34bf93ad0d9971d04ccc90f705511c838aad9734a4a2fb0d7a03fc7fe89a"
)
# The same 32 bytes as a contract give a different strkey.
assert str(Contract(account.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, muxed_id):
description = f"muxed account {key.hex()} with ID {muxed_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"
private_key = Ed25519PrivateKey.from_string(secret)
seed = private_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(private_key) == "<redacted>"
assert repr(private_key) == "Ed25519PrivateKey(<redacted>)"
# Get the strkey back only where you mean to.
assert private_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
Metadata
Release files for stellar-strkey 0.2.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 | Provenance | Actions |
|---|---|---|---|---|
| stellar_strkey-0.2.0.tar.gz | 36.1 kB | With provenance | Details for stellar_strkey-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stellar_strkey-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for stellar_strkey-0.2.0-py3-none-any.whl |
Total release size: 54.1 kB
Release files / stellar_strkey-0.2.0.tar.gz
| Download URL | stellar_strkey-0.2.0.tar.gz |
|---|---|
| Size | 36.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b1c89bbb0a64cf9e6ec332e80e72d272300f61f9a628a84cf16994a4effc433
|
|
BLAKE2b-256 checksum How to use checksums |
0c054c93a8ac9ae30662255853a4dc9b6130859296f3bb62540bc9da82bb2d51
|
| 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 12, 2026.
Transparency logRelease files / stellar_strkey-0.2.0-py3-none-any.whl
| Download URL | stellar_strkey-0.2.0-py3-none-any.whl |
|---|---|
| Size | 18.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59f2acbb8b3dc6ecdb2742980b864163ff9d2477aabef14b2bc42acae12a42ae
|
|
BLAKE2b-256 checksum How to use checksums |
9ccd71bafcc0c2324e03a2c6ff06b0674a9f70d570ccad26d3420650666902db
|
| 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 12, 2026.
Transparency logSecurity for stellar-strkey 0.2.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.
Attestation for stellar_strkey-0.2.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 12, 2026.
Transparency logA 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.