tx3-sdk (Python)
The official Python SDK for Tx3: a DSL and protocol suite for
defining and executing UTxO-based blockchain transactions declaratively. Load a
compiled .tii protocol, bind parties and signers, and drive the full
transaction lifecycle (resolve -> sign -> submit -> wait) through TRP.
This repository is organized as a monorepo. The publishable Python package lives in sdk/.
What is Tx3
Tx3 is a domain-specific language and protocol suite for declarative, type-safe UTxO transactions. Authors write .tx3 files describing parties, environment, and transactions; the toolchain compiles them to .tii artifacts that this SDK loads at runtime to drive the resolve → sign → submit → wait lifecycle through a TRP server. See the Tx3 docs for project context.
Installation
pip install tx3-sdk
Quick start
import asyncio
from tx3_sdk import CardanoSigner, Party, PollConfig, Protocol
async def main() -> None:
# 1) Load a compiled .tii protocol
protocol = Protocol.from_file("examples/transfer.tii")
# 2) Build a client: configure TRP, profile, and parties on the builder
sender_signer = CardanoSigner.from_mnemonic(
address="addr_test1qz...",
phrase="word1 word2 ... word24",
)
client = (
protocol.client()
.trp_endpoint("https://preprod.trp.tx3.dev")
.with_profile("preprod")
.with_party("sender", Party.signer(sender_signer))
.with_party("receiver", Party.address("addr_test1qz..."))
.build()
)
# 3) Build, resolve, sign, submit
submitted = await (
await (
await client.tx("transfer").arg("quantity", 10_000_000).resolve()
).sign()
).submit()
# 4) Wait for confirmation
status = await submitted.wait_for_confirmed(PollConfig.default())
print(f"Confirmed at stage: {status.stage}")
asyncio.run(main())
All fallible validation — TRP endpoint present, profile declared, every bound
party declared — happens inside build(), which raises MissingTrpEndpointError,
UnknownProfileError, or UnknownPartyError (all under the BuilderError family,
rooted at Tx3Error). Optional setters never raise, so chains stay fluent. Profile
selection is builder-only: there is no profile-switching method on the built
client. Switching profiles requires a new builder.
Concepts
| SDK Type | Glossary Term | Description |
|---|---|---|
Protocol |
TII / Protocol | Loaded .tii with transactions, parties, and profiles. protocol.client() returns a fresh Tx3ClientBuilder |
Tx3ClientBuilder |
Client builder | Fluent builder seeded by Protocol.client() or Tx3ClientBuilder.from_parts(...); absorbs all fallible validation in build() |
Tx3Client |
Facade | Output of Tx3ClientBuilder.build() — owns the deconstructed protocol parts, TRP client, profile, and party bindings |
TxBuilder |
Invocation builder | Source-agnostic; collects args and resolves transactions |
Party |
Party | Party.address(...) or Party.signer(...) |
Profile |
Profile | { environment, parties } value baked into the client; embedded by codegen plugins, decomposed from Protocol by from_protocol |
MissingTrpEndpointError / UnknownPartyError |
Builder errors | Raised by build(); subclass of BuilderError, rooted at Tx3Error |
Signer |
Signer | Protocol producing a TxWitness for a SignRequest |
SignRequest |
SignRequest | Input passed to Signer.sign: tx_hash_hex + tx_cbor_hex |
CardanoSigner |
Cardano Signer | BIP32-Ed25519 signer at m/1852'/1815'/0'/0/0 |
Ed25519Signer |
Ed25519 Signer | Generic raw-key Ed25519 signer |
ResolvedTx |
Resolved transaction | Output of resolve(), ready for signing |
SignedTx |
Signed transaction | Output of sign(), ready for submission |
SubmittedTx |
Submitted transaction | Output of submit(), pollable for status |
PollConfig |
Poll configuration | Poll attempts and delay for wait modes |
Advanced usage
Skipping the runtime .tii (codegen flow)
If you've run trix codegen to generate typed bindings, your generated Client
embeds the per-transaction TIR envelopes and per-profile data at codegen time —
no .tii artifact at runtime. Under the hood it seeds the same builder via
Tx3ClientBuilder.from_parts(transactions, profiles, known_parties) and routes
typed per-party setters through with_party_unchecked. You can also call
from_parts directly from hand-written code:
from tx3_sdk import ClientOptions, Party, Tx3ClientBuilder
client = (
Tx3ClientBuilder.from_parts(transactions, profiles, ["sender", "receiver"])
.trp(ClientOptions(endpoint="http://localhost:8000"))
.with_party_unchecked("sender", Party.signer(signer))
.build()
)
Low-level TRP client
from tx3_sdk import TrpClient
from tx3_sdk.trp import ResolveParams
trp = TrpClient(endpoint="http://localhost:8000", headers={"Authorization": "Bearer token"})
envelope = await trp.resolve(ResolveParams(tir=..., args={"quantity": 100}))
Custom Signer
Implement the Signer protocol. sign receives a SignRequest carrying both
the tx hash and the full tx CBOR; hash-based signers read tx_hash_hex,
tx-based signers (e.g. wallet bridges) read tx_cbor_hex.
from tx3_sdk import SignRequest, Signer
from tx3_sdk.signer import TxWitness
from tx3_sdk.signer.witness import vkey_witness
class MySigner(Signer):
def address(self) -> str:
return "addr_test1..."
def sign(self, request: SignRequest) -> TxWitness:
# sign request.tx_hash_hex with your key
return vkey_witness(public_key_hex="aabb", signature_hex="ccdd")
Manual witness attachment
When a witness is produced outside any registered signer — for example by an
external wallet app or a remote signing service — resolve the transaction
first, hand the resolved hash (or full tx CBOR) to the wallet, then attach
the returned witness before sign():
from tx3_sdk.signer.witness import vkey_witness
resolved = await client.tx("transfer").arg("quantity", 10_000_000).resolve()
# Hand resolved.hash (or resolved.tx_hex) to the external wallet and get
# back a witness. The wallet needs the resolved tx to sign.
witness = vkey_witness(public_key_hex="aabb", signature_hex="ccdd") # sign resolved.hash with external wallet
signed = await resolved.add_witness(witness).sign()
submitted = await signed.submit()
add_witness may be called any number of times; manual witnesses are appended after registered-signer witnesses in attach order. Note: ResolvedTx is a frozen dataclass, so add_witness returns a new instance.
Tx3 protocol compatibility
- TRP protocol version:
v1beta0 - TII schema version:
v1beta0
Testing
- Tests follow Python's idiomatic centralized layout under
sdk/tests/. - End-to-end (e2e) tests are marked with
@pytest.mark.e2eand selected by marker.
# from python-sdk/sdk
pytest -m "not e2e"
pytest tests/e2e -m e2e
License
Apache-2.0
Metadata
Release files for tx3-sdk 0.15.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 |
|---|---|---|---|---|
| tx3_sdk-0.15.0.tar.gz | 42.2 kB | Without provenance | Details for tx3_sdk-0.15.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tx3_sdk-0.15.0-py3-none-any.whl | Python 3 | none | any | Details for tx3_sdk-0.15.0-py3-none-any.whl |
Total release size: 84.0 kB
Release files / tx3_sdk-0.15.0.tar.gz
| Download URL | tx3_sdk-0.15.0.tar.gz |
|---|---|
| Size | 42.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a823f149ae03a684415264d6683f55882da2e99faa9c869e025c164ff9d22bdb
|
|
BLAKE2b-256 checksum How to use checksums |
202729c5500ea80ce0811464222c6daabcf5669bf769e328f2b8804086fd2168
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / tx3_sdk-0.15.0-py3-none-any.whl
| Download URL | tx3_sdk-0.15.0-py3-none-any.whl |
|---|---|
| Size | 41.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6c07b9cfdbde76dced4073f462605eb67fd44cb9fdbe9fd45e8c917ded8d126f
|
|
BLAKE2b-256 checksum How to use checksums |
31896ee7f101678f1916cf5ff035f60217f77ff90523a552b9de097be844d608
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Security for tx3-sdk 0.15.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.