Skip to main content

KaleidoSwap SDK Python Bindings

Python bindings for the KaleidoSwap SDK: atomic swaps (Boltz protocol) between Bitcoin, Lightning, and Liquid.

Installation

python -m pip install kaleidorg_swap_sdk

Python 3.10+ is supported. Prebuilt wheels cover Linux x86_64/aarch64, macOS x86_64/arm64, and Windows x86_64; other platforms build the published source distribution and need a Rust 1.88+ toolchain.

Quick Start

⚠️ WARNING: All examples are only to be used in REGTEST.

import kaleidorg_swap_sdk
import asyncio

async def main():
    # Initialize for regtest (do NOT use this example in production)
    network = kaleidorg_swap_sdk.Network.REGTEST
    boltz_api = kaleidorg_swap_sdk.SwapClient.default(network)

    # Example: Create a submarine swap (Lightning → Bitcoin)
    key_pair = kaleidorg_swap_sdk.KeyPair()
    btc_chain = kaleidorg_swap_sdk.btc_chain_from_network(network)

    invoice = "lightning-invoice-to-pay"

    request = kaleidorg_swap_sdk.CreateSubmarineRequest(
        _from=btc_chain,
        to=btc_chain,
        invoice=invoice,
        refund_public_key=key_pair.public(),
    )

    swap = await boltz_api.create_swap(request)
    print(f"Send {swap.expected_amount} sats to {swap.address}")

asyncio.run(main())

Partner attribution (organization API keys)

A partner organization can have the swaps it originates attributed to it. That needs an organization API key from the KaleidoSwap partner panel — a kld_test_… key for signet and staging, kld_live_… for mainnet and production. Without one, SwapClient behaves exactly as before and creates unattributed swaps.

import os
import kaleidorg_swap_sdk

client = kaleidorg_swap_sdk.SwapClient.kaleido_maker(
    "https://maker.signet.kaleidoswap.com/v2",
    os.environ["KALEIDOSWAP_API_KEY"],
    None,  # timeout in seconds
)

client.api_key_environment()  # "test"
client.api_key_id()           # the key id the partner panel shows

Scrub the key in error reporters that capture locals. It crosses the binding as a plain str, so it is a function argument on a stack frame for the length of the call. The SDK keeps it out of its own errors, logs and repr, but anything that renders frame locals — pytest --showlocals, Sentry's with_locals, some logging formatters — reads it off the frame regardless. Scrub it in your reporter's before-send hook.

The result is an ordinary client — every swap route works the same way — that sends the key as Authorization: Bearer … to that maker URL, and only to that maker URL. The key answers which partner organization created this swap? and nothing else: it authorizes no claim, no refund, no fund movement and no panel access. The per-swap swap_auth credential the maker returns on create stays separate and unchanged.

The URL must be https unless it is a loopback address, since a bearer credential over plain HTTP is readable by anything on the path. A value that cannot be a key is rejected here rather than reaching the maker as a 401 — which is the same answer a revoked key gets. There is no accessor for the secret half: api_key_id() and api_key_environment() are all the client will tell you, and UniFFI renders no string form of the object at all.

Keep the key in server-side configuration. It is permanent until revoked, so never ship it inside a mobile or desktop application, where every user holds it.

Swap Types

  • Submarine swaps - Lightning → On-chain Bitcoin/Liquid
  • Reverse swaps - On-chain Bitcoin/Liquid → Lightning
  • Chain swaps - Bitcoin ↔ Liquid atomic swaps

Examples

Complete working examples are available in the examples/ directory:

Release files for kaleidorg-swap-sdk 0.10.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 kaleidorg-swap-sdk 0.10.0
File Size Uploaded
kaleidorg_swap_sdk-0.10.0.tar.gz 293.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for kaleidorg-swap-sdk 0.10.0
File
kaleidorg_swap_sdk-0.10.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
kaleidorg_swap_sdk-0.10.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details
kaleidorg_swap_sdk-0.10.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details
kaleidorg_swap_sdk-0.10.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details
kaleidorg_swap_sdk-0.10.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details

Total release size: 27.3 MB

Release files / kaleidorg_swap_sdk-0.10.0.tar.gz

Download URL kaleidorg_swap_sdk-0.10.0.tar.gz
Size 293.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0f3b2d2a1a901bf9c5591389eb9c86a8db2875d72802a094cff5c384031071be
BLAKE2b-256 checksum
How to use checksums
908e2ec74f655cc24161a31456e705e9094ea36e27b577bb6482c4163a46146e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / kaleidorg_swap_sdk-0.10.0-py3-none-win_amd64.whl

Download URL kaleidorg_swap_sdk-0.10.0-py3-none-win_amd64.whl
Size 5.3 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
313b13478e190800ecb50bdca6c86ff3fa6de60747d08a4e69843f2faa888d02
BLAKE2b-256 checksum
How to use checksums
fbf9e9214e330aa2290dd969e69aed1d4fbc313da70e8bf64a4ae72b589bca0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / kaleidorg_swap_sdk-0.10.0-py3-none-manylinux_2_28_x86_64.whl

Download URL kaleidorg_swap_sdk-0.10.0-py3-none-manylinux_2_28_x86_64.whl
Size 5.5 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
ac64fc37014d431aea5f0574577fd3dca813793be881c11a3e0eb6ef80a19685
BLAKE2b-256 checksum
How to use checksums
21b09d3d3bd6475687725dcde7ffe8e66deeef8b0fd67522e9e16a82c5d068b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / kaleidorg_swap_sdk-0.10.0-py3-none-manylinux_2_28_aarch64.whl

Download URL kaleidorg_swap_sdk-0.10.0-py3-none-manylinux_2_28_aarch64.whl
Size 5.5 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
dfd1768ab58899f9eed138c9929f5e9bfe79c1f0836d5738ef28cf4043246048
BLAKE2b-256 checksum
How to use checksums
43bf2d2aa88ba6465f01ce6ddcc82c0f9054f7efeb06a9634a9bc6af65dd7a9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / kaleidorg_swap_sdk-0.10.0-py3-none-macosx_11_0_arm64.whl

Download URL kaleidorg_swap_sdk-0.10.0-py3-none-macosx_11_0_arm64.whl
Size 5.3 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
039bb8b97d162fb9844b1a943ed518e0e2bf6cb94114da48642f2fb9ffedb109
BLAKE2b-256 checksum
How to use checksums
d02345e4888d93dc6e8bfb264fea0fd0e4fa035cc38dcea3b79bcf4982bad3f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / kaleidorg_swap_sdk-0.10.0-py3-none-macosx_10_12_x86_64.whl

Download URL kaleidorg_swap_sdk-0.10.0-py3-none-macosx_10_12_x86_64.whl
Size 5.4 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
bcd817a86a94b0ead1c5317037b0296c0c9076331d33f563d99ba50e7f5aa11c
BLAKE2b-256 checksum
How to use checksums
e9156e2f45baf0896d780a3ca0ba24ec37806c631ebcfcd76d3bf3a3175959d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.10.0 This release

6 release files

0.9.0

6 release files

0.8.0

6 release files

0.7.2

6 release files

0.7.1

6 release files

0.7.0

6 release files

0.6.0

6 release files

0.5.0

6 release files

0.4.0

6 release files

0.3.0

6 release files

0.2.0

6 release files

0.1.1

6 release files

0.1.0

6 release files

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