Skip to main content

Python bindings for sparse-ir-capi

This is a low-level binding for the sparse-ir-capi Rust library.

Requirements

  • Python >= 3.10
  • Rust toolchain (for building the Rust library)
  • uv (for building and managing Python dependencies)
  • numpy >= 1.26.4
  • scipy

BLAS Support

This package automatically uses SciPy's BLAS backend for optimal performance. No additional BLAS installation is required - SciPy will provide the necessary BLAS functionality.

Build

Install Dependencies and Build

# Build the package (Rust library will be built automatically)
cd python
uv build

This will:

  • Automatically build the Rust sparse-ir-capi library using Cargo (via CMake)
  • Copy the built library and header files to the Python package
  • Create both source distribution (sdist) and wheel packages

Development Build

For development:

# Install in development mode (will auto-prepare if needed)
uv sync --locked

Note for CI/CD: The Rust library is built automatically during the Python package build. No separate build step is needed:

# In CI/CD scripts
cd python
uv build

See .github-workflows-example.yml for a complete GitHub Actions example.

BLAS Configuration

The package automatically uses SciPy's BLAS backend, which provides optimized BLAS operations without requiring separate BLAS installation. The build system is configured to use SciPy's BLAS functions directly.

Clean Build Artifacts

To remove build artifacts and files copied from the parent directory:

uv run clean

This will remove:

  • Build directories: build/, dist/, *.egg-info
  • Compiled libraries: pylibsparseir/*.so, pylibsparseir/*.dylib, pylibsparseir/*.dll
  • Cache directories: pylibsparseir/__pycache__

Build Process Overview

The build process works as follows:

  1. CMake Configuration: scikit-build-core invokes CMake, which:

    • Finds the Cargo executable
    • Sets up build targets for the Rust library
  2. Rust Library Build: CMake calls Cargo to build sparse-ir-capi:

    • Compiles the Rust library to a shared library (.so, .dylib, or .dll)
    • Generates C header file (sparseir.h) using cbindgen (via build.rs)
    • Copies the library and header to the pylibsparseir directory
  3. Python Package Building: uv build or uv sync --locked:

    • Packages everything into distributable wheels and source distributions
  4. Installation: The built package includes the compiled shared library and Python bindings

Conda Build

This package can also be built and distributed via conda-forge. The conda recipe is located in conda-recipe/ and supports multiple platforms and Python versions.

Building conda packages locally:

# Install conda-build
conda install conda-build

# Build the conda package
cd python
conda build conda-recipe

# Build for specific platforms
conda build conda-recipe --platform linux-64
conda build conda-recipe --platform osx-64
conda build conda-recipe --platform osx-arm64

Supported platforms:

  • Linux x86_64
  • macOS Intel (x86_64)
  • macOS Apple Silicon (ARM64)

Supported Python versions:

  • Python 3.11, 3.12, 3.13, 3.14

Supported NumPy versions:

  • NumPy 2.1, 2.2, 2.3

The conda build automatically:

  • Uses SciPy's BLAS backend for optimal performance
  • Cleans up old shared libraries before building
  • Builds platform-specific packages with proper dependencies

Handle Ownership

Every function in pylibsparseir.core that creates a C object returns an owning handle instead of a raw ctypes pointer: KernelHandle, SVEResultHandle, BasisHandle, FuncsHandle, SamplingHandle, or GemmBackendHandle (the default BLAS backend returned by get_default_blas_backend()).

  • A handle is released exactly once with the matching spir_*_release: when it becomes unreachable, when close() is called (also on leaving a with handle: block), or at interpreter exit. Closing it again does nothing.
  • An open handle can be passed directly to any _lib.spir_* function and is truthy. A released handle is falsy, and passing it to C raises ctypes.ArgumentError instead of handing C a freed pointer.
  • Do not release an owned handle through _lib.spir_*_release. Those entry points refuse owned handles with ctypes.ArgumentError, because the owner would free them a second time. Handles created directly through _lib remain the caller's to release, or can be handed over to an owner, e.g. FuncsHandle(_lib.spir_funcs_clone(funcs)).
  • C handles never depend on the handles they were created from (spir_basis_new copies the kernel and the SVE result; funcs and samplings own their data), so handles can be released in any order.

Performance Notes

BLAS Support

This package automatically uses SciPy's optimized BLAS backend for improved linear algebra performance:

  • Automatic BLAS: Uses SciPy's BLAS functions for optimal performance
  • No additional setup: SciPy provides all necessary BLAS functionality

The build system automatically configures BLAS support through SciPy. You can verify BLAS support with debug output enabled:

export SPARSEIR_DEBUG=1
python -c "import pylibsparseir"

This will show:

[core.py] Created SciPy BLAS backend handle
[core.py] Registered SciPy BLAS dgemm @ 0x...
[core.py] Registered SciPy BLAS zgemm @ 0x...

Debug Output

The SPARSEIR_DEBUG environment variable enables debug output only when it is set to 1, true, yes or on, in any letter case. Any other value, including 0, false or an empty string, disables it, as does leaving it unset. The same rule applies to both layers:

  • pylibsparseir prints its messages to stdout. It checks the variable when it is imported.
  • The Rust library prints [SPARSEIR DEBUG], [SPARSEIR DEBUG ERROR] and [SPARSEIR WARN] lines to stderr. It checks the variable each time it would print one.

Troubleshooting

Build fails with missing Cargo:

# Make sure Rust toolchain is installed
# Install from https://rustup.rs/
# Then retry:
cd python
uv build

Clean rebuild:

# Remove all build artifacts
uv run clean
cd ../sparse-ir-capi
cargo clean
cd ../python
uv build

Metadata

Release files for pylibsparseir 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pylibsparseir 0.10.0
File
pylibsparseir-0.10.0-cp314-cp314-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64 Details
pylibsparseir-0.10.0-cp314-cp314-macosx_15_0_arm64.whl CPython 3.14 CPython 3.14 macOS 15.0+ ARM64 Details
pylibsparseir-0.10.0-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details
pylibsparseir-0.10.0-cp313-cp313-macosx_15_0_arm64.whl CPython 3.13 CPython 3.13 macOS 15.0+ ARM64 Details
pylibsparseir-0.10.0-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details
pylibsparseir-0.10.0-cp312-cp312-macosx_15_0_arm64.whl CPython 3.12 CPython 3.12 macOS 15.0+ ARM64 Details
pylibsparseir-0.10.0-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details
pylibsparseir-0.10.0-cp311-cp311-macosx_15_0_arm64.whl CPython 3.11 CPython 3.11 macOS 15.0+ ARM64 Details
pylibsparseir-0.10.0-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details
pylibsparseir-0.10.0-cp310-cp310-macosx_15_0_arm64.whl CPython 3.10 CPython 3.10 macOS 15.0+ ARM64 Details

Total release size: 12.6 MB

Release files / pylibsparseir-0.10.0-cp314-cp314-manylinux_2_28_x86_64.whl

Download URL pylibsparseir-0.10.0-cp314-cp314-manylinux_2_28_x86_64.whl
Size 1.6 MB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
84b463bc2f2d9b754e5f8f1a1c0b54a7b3ba959ab711ab58bf80bfb5ecabef74
BLAKE2b-256 checksum
How to use checksums
a174b5ce756969ff212d06b0298b375d7b3b255d5a1404e06ca520e2ce823cc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pylibsparseir-0.10.0-cp314-cp314-macosx_15_0_arm64.whl

Download URL pylibsparseir-0.10.0-cp314-cp314-macosx_15_0_arm64.whl
Size 933.6 kB
Tags CPython 3.14 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
770eb762d7c2a5925549b07f0948885f2c25a1dbe0a13ab0830bb7009bb63c13
BLAKE2b-256 checksum
How to use checksums
43169cce53050d180942dfbd3206f7f9eeaaac81862226cbbc2ac5efae586992
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pylibsparseir-0.10.0-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL pylibsparseir-0.10.0-cp313-cp313-manylinux_2_28_x86_64.whl
Size 1.6 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
43cbad8516700703da13e50ab292f275b8947fafddeb0afee0094d1cf664ab34
BLAKE2b-256 checksum
How to use checksums
d86dc8c89c5b468ed028826c1b70bbca3544c2251505381eb68d70a595e7c96e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pylibsparseir-0.10.0-cp313-cp313-macosx_15_0_arm64.whl

Download URL pylibsparseir-0.10.0-cp313-cp313-macosx_15_0_arm64.whl
Size 933.6 kB
Tags CPython 3.13 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
2f7033592ec4b90184f006912adf1fbae746cc536e5644cfddd8d6ec99916247
BLAKE2b-256 checksum
How to use checksums
e6424dacb0395db4aea1be9c8a85d147352931755eedc3a0e660e06b6a7f2d00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pylibsparseir-0.10.0-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL pylibsparseir-0.10.0-cp312-cp312-manylinux_2_28_x86_64.whl
Size 1.6 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
48ede90cc818238398b94cbf229ff0950b824d2b0149cd8180f2e4270cda0d85
BLAKE2b-256 checksum
How to use checksums
11bbbafcd1c37197b62a0e29363354529f09205eb40b1c0cd381d44fc10906d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pylibsparseir-0.10.0-cp312-cp312-macosx_15_0_arm64.whl

Download URL pylibsparseir-0.10.0-cp312-cp312-macosx_15_0_arm64.whl
Size 933.6 kB
Tags CPython 3.12 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
9fa765f3cc1218896c023f8e21493f90bf37670021ad9191a33fe65ef62190f8
BLAKE2b-256 checksum
How to use checksums
18fd85b2f49760fe2182c5ce4961062c8519dcced8720a8b27cc0ccef1a77c33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pylibsparseir-0.10.0-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL pylibsparseir-0.10.0-cp311-cp311-manylinux_2_28_x86_64.whl
Size 1.6 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
0d90ab7be63e7a7253a30a9298e72150b627fe392ec83c637e6b0e1d464c622d
BLAKE2b-256 checksum
How to use checksums
3180701461f704d73c97c5eefabed19eece90edcf3607e27dffee231e4d95d02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pylibsparseir-0.10.0-cp311-cp311-macosx_15_0_arm64.whl

Download URL pylibsparseir-0.10.0-cp311-cp311-macosx_15_0_arm64.whl
Size 933.6 kB
Tags CPython 3.11 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
abf436462f190121432718e797ff31d983a0e4ac9bb5ca13a5171657d57efafb
BLAKE2b-256 checksum
How to use checksums
b191bba11a06992956ec1971e5d5bd7082e64c08a90e62774682ca4a2d110ce5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pylibsparseir-0.10.0-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL pylibsparseir-0.10.0-cp310-cp310-manylinux_2_28_x86_64.whl
Size 1.6 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
122be87e131a54feda66e9a899f86152052d55ea56b2f77e30637ac8c7147bc8
BLAKE2b-256 checksum
How to use checksums
795cbc01e8139e484f973a1340fcf7e9fcfab44888590accf7ff8d22e7745eeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pylibsparseir-0.10.0-cp310-cp310-macosx_15_0_arm64.whl

Download URL pylibsparseir-0.10.0-cp310-cp310-macosx_15_0_arm64.whl
Size 933.6 kB
Tags CPython 3.10 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
7c70d24f2e833b1ba66b2496a531e22517b68d5ab216c68e0e416a217ac357b8
BLAKE2b-256 checksum
How to use checksums
67812ff33ae367300edac991b6553c4876a2976daed3d03eb903ace04c6ea684
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.10.0 This release

10 release files

0.9.1

10 release files

0.9.0

10 release files

0.8.4

8 release files

0.8.3

8 release files

0.8.2

8 release files

0.8.0

8 release files

0.7.5

8 release files

0.7.4

8 release files

0.7.3

8 release files

0.6.0

16 release files

0.5.2

16 release files

0.1.0

16 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