Skip to content

feat(ci): add Python binding release workflow#391

Merged
thibault-martinez merged 124 commits intodevelopfrom
ci/python-release
Nov 19, 2025
Merged

feat(ci): add Python binding release workflow#391
thibault-martinez merged 124 commits intodevelopfrom
ci/python-release

Conversation

@Alex6323
Copy link
Contributor

@Alex6323 Alex6323 commented Nov 7, 2025

Closes #243

This PR is not as straight-forward as it may seem, because of the following difficulties:

  • a decision had to be made between maturin or setuptools-rust to create the platform specific Python packages, i.e. the wheels (.whl); both have downsides and I picked maturin + a small hack (more on that later) over the other, which is the way more complex approach. maturin supports uniffi out-of-the-box, so it places the generated iota-sdk-ffi.py and the libiota-sdk-ffi.{LIB_EXT} the way it's expected by uniffi. That means however that with maturin we can't use our make build script, because it is designed to do everything from start (building) to finish (packaging, uploading)
  • In order for maturin to produce a valid iota-sdk-ffi.py we need to install the exact same version of the uniffi-bindgen CLI which currently is at 0.29 in the iota-sdk-ffi crate deps. maturin looks for a binary named uniffi-bindgen in the PATH env var, so luckily we can control which binary it should use. We can't use a pipx install uniffi-bindgen in the CI because the latest version installable through pip is 0.28.3 (which tests showed is incompatible), which is why we need to build and cargo install that binary in the CI from the repo, which will always make sure that the versions correctly match. I had to rename the binary to uniffi-bindgen in the iota-sdk-ffi crate to make that work.

UPDATE: There was a naming incompatibility issue that was fixed upstream (with maturin 1.10), so the initially required repair_whl.sh script is no longer needed! 🥳 FYI here's where they fixed it: https://github.com/PyO3/maturin/pull/2840/files#diff-ef3401ac6425fac36616570d22b89962c2c4c9b5033f849ce8e0b6ab904c9fe9L1186. That means that we must set the minimum maturin version to 1.10 in the pyproject.toml.

Other than that this PR can be tested locally easily with the following commands:

  1. pipx install maturin (cargo install maturin fails to compile unless you install their latest main)
  2. cargo install --path crates/iota-sdk-ffi --bin uniffi-bindgen
  3. cd bindings/python/src
  4. maturin build --release (you'll find the generated .whl in target/wheels)
  5. create a python test project with a virtual environment
  6. pip install target/wheels/iota_sdk-0.1.0-<PLATFORM_SPECIFIC>.whl
  7. finally paste and run:
from iota_sdk import *

import asyncio

async def main():
    client = GraphQlClient.new_devnet()

    chain_id = await client.chain_id()
    print("Chain ID:", chain_id)

if __name__ == "__main__":
    asyncio.run(main())

The published Python bindings can be found on TestPyPi: https://test.pypi.org/project/iota-sdk/3.0.0a1.dev16/

Version like 3.0.0-alpha.1 are converted to 3.0.0a1 according to PEP-440 standard: https://peps.python.org/pep-0440/#public-version-identifiers

@DaughterOfMars
Copy link
Contributor

Since we're building maturin from source anyway, could we instead fork it and make some tweaks to suit our purposes?

@Alex6323
Copy link
Contributor Author

Alex6323 commented Nov 7, 2025

Since we're building maturin from source anyway, could we instead fork it and make some tweaks to suit our purposes?

sorry, I think I had a mistakte in the PR description. We're not building maturin since we're using the action, we actually do build it from source. Locally I installed a prebuilt binary. I wouldn't think it's worth the effort to fork it and then having to maintain the fork. Eventually they might fix the issue anyways, and we can just remove the repair script and the CI step then.

@thibault-martinez thibault-martinez dismissed Thoralf-M’s stale review November 19, 2025 10:01

Changed significantly since your approval

Alex6323 and others added 4 commits November 19, 2025 12:12
Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com>
@thibault-martinez thibault-martinez merged commit a3b2ed6 into develop Nov 19, 2025
29 of 30 checks passed
@thibault-martinez thibault-martinez deleted the ci/python-release branch November 19, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create workflow to publish Python package to pypi

5 participants