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 with Cargo (through the hatchling build hook in hatch_build.py)
  • Copy the built library and header file 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/ in the repository for the workflows that build and test this package.

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:

make clean

This will remove:

  • Build directories and caches: build/, dist/, *.egg-info, __pycache__/, .pytest_cache/, .venv/
  • Files copied into the package: pylibsparseir/*.so, pylibsparseir/*.dylib, pylibsparseir/*.dll, pylibsparseir/*.h

Build Process Overview

The build process works as follows:

  1. Build hook: pyproject.toml uses the hatchling backend, which runs the custom build hook in hatch_build.py.

  2. Rust Library Build: the hook runs cargo build --release -p sparse-ir-capi from the repository root:

    • Compiles the Rust library to a shared library (.so, .dylib, or .dll)
    • Removes old shared libraries from pylibsparseir/, then copies the new library and the header sparse-ir-capi/include/sparseir/sparseir.h there
  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 (the conda recipe; the PyPI package itself supports Python 3.10 and newer, see pyproject.toml)

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)).
  • The DLR and MiniPole entry points have no wrapper in pylibsparseir.core; call them through _lib (spir_dlr_new_independent, spir_dlr_new, spir_minipole_from_dlr, spir_minipole_from_matsubara). A DLR is a spir_basis and can be handed to BasisHandle. A spir_pole_repr has no owning handle class, so release it yourself with _lib.spir_pole_repr_release.
  • 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
make clean
cd ../sparse-ir-capi
cargo clean
cd ../python
uv build

Metadata

Release files for pylibsparseir 0.14.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.14.0
File Actions
pylibsparseir-0.14.0-cp314-cp314-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64 Details for pylibsparseir-0.14.0-cp314-cp314-manylinux_2_28_x86_64.whl
pylibsparseir-0.14.0-cp314-cp314-macosx_15_0_arm64.whl CPython 3.14 CPython 3.14 macOS 15.0+ ARM64 Details for pylibsparseir-0.14.0-cp314-cp314-macosx_15_0_arm64.whl
pylibsparseir-0.14.0-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details for pylibsparseir-0.14.0-cp313-cp313-manylinux_2_28_x86_64.whl
pylibsparseir-0.14.0-cp313-cp313-macosx_15_0_arm64.whl CPython 3.13 CPython 3.13 macOS 15.0+ ARM64 Details for pylibsparseir-0.14.0-cp313-cp313-macosx_15_0_arm64.whl
pylibsparseir-0.14.0-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details for pylibsparseir-0.14.0-cp312-cp312-manylinux_2_28_x86_64.whl
pylibsparseir-0.14.0-cp312-cp312-macosx_15_0_arm64.whl CPython 3.12 CPython 3.12 macOS 15.0+ ARM64 Details for pylibsparseir-0.14.0-cp312-cp312-macosx_15_0_arm64.whl
pylibsparseir-0.14.0-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details for pylibsparseir-0.14.0-cp311-cp311-manylinux_2_28_x86_64.whl
pylibsparseir-0.14.0-cp311-cp311-macosx_15_0_arm64.whl CPython 3.11 CPython 3.11 macOS 15.0+ ARM64 Details for pylibsparseir-0.14.0-cp311-cp311-macosx_15_0_arm64.whl
pylibsparseir-0.14.0-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details for pylibsparseir-0.14.0-cp310-cp310-manylinux_2_28_x86_64.whl
pylibsparseir-0.14.0-cp310-cp310-macosx_15_0_arm64.whl CPython 3.10 CPython 3.10 macOS 15.0+ ARM64 Details for pylibsparseir-0.14.0-cp310-cp310-macosx_15_0_arm64.whl

Total release size: 67.2 MB

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

Download URL pylibsparseir-0.14.0-cp314-cp314-manylinux_2_28_x86_64.whl
Size 7.3 MB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
788ba40ca0fc85af54f054fca3d5e0fc84096298a1f5551bf640dc966a1e41af
BLAKE2b-256 checksum
How to use checksums
d317dafe9d29fa70663700269f3b03e80441823068e04bb0fe184a44f55a028c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL pylibsparseir-0.14.0-cp314-cp314-macosx_15_0_arm64.whl
Size 6.2 MB
Tags CPython 3.14 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
a05a4e1f4b3d42732f6bd43c47dfa7c5ea2afc4d91b5051299f2865895e1f397
BLAKE2b-256 checksum
How to use checksums
0d0888510d31e45354759e23c189cd53b43b82b477ae471d0d2aafc0a6f38570
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL pylibsparseir-0.14.0-cp313-cp313-manylinux_2_28_x86_64.whl
Size 7.3 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
26088c2ac8843255cca77e5ff0039190d10cbe3d0d5a390d601c4ae16506e099
BLAKE2b-256 checksum
How to use checksums
e2fa483f2df401e57e299c19896f349ddba615328d415bced0f06cdbc70b3180
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL pylibsparseir-0.14.0-cp313-cp313-macosx_15_0_arm64.whl
Size 6.2 MB
Tags CPython 3.13 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
708e89ff2105646df94a4be4ff810efa7bf258191711e317a357d3bbe0b5ed1f
BLAKE2b-256 checksum
How to use checksums
a3cdfab76e364bb7e2c8bbfb26c0381a806563d6f47a3e15567afe4f97c649e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL pylibsparseir-0.14.0-cp312-cp312-manylinux_2_28_x86_64.whl
Size 7.3 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
e5ffe7991e40fad6f20a6704b63c67ea4c49543140d9d6a2ebd9c4e36ad49eb0
BLAKE2b-256 checksum
How to use checksums
4b341e5fc194ce487af5c82a89b2800433136d19a076499d9f6a80f7cc7d3371
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL pylibsparseir-0.14.0-cp312-cp312-macosx_15_0_arm64.whl
Size 6.2 MB
Tags CPython 3.12 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
595e3f1f504910183a4c6704f19dd98ac1fbc1091a9d60b128f1fc8d5b208292
BLAKE2b-256 checksum
How to use checksums
3ac5d320a1c61ec9ca018b04438d2ff657dc173ae97cbe098cd818a68a59fe96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL pylibsparseir-0.14.0-cp311-cp311-manylinux_2_28_x86_64.whl
Size 7.3 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8b5fb9fc695c07bce4c586ae71262c81efd19ff23f8c95427a575bb3fea4bb54
BLAKE2b-256 checksum
How to use checksums
8df5dc6b84d5328ac41cee867d5fc4db2cf4748a7d0962a04c74da28298226ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL pylibsparseir-0.14.0-cp311-cp311-macosx_15_0_arm64.whl
Size 6.2 MB
Tags CPython 3.11 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
8a49f732dff360c8e98881851a27295794bdc1ba3953b3cb65ec4b62db87f890
BLAKE2b-256 checksum
How to use checksums
d9a0d68355985af781feb1b1f1a34e50d2142412e39fd8928cb69d1db3d99637
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL pylibsparseir-0.14.0-cp310-cp310-manylinux_2_28_x86_64.whl
Size 7.3 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
bbbef53535c949e35c3d5ba813ffc9e87f8e590329132c1e2564ffe0b00473ae
BLAKE2b-256 checksum
How to use checksums
fcf3accebd9a3b079407c5aee0b487b9105445f773fdcc20f674680d8f9f0395
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL pylibsparseir-0.14.0-cp310-cp310-macosx_15_0_arm64.whl
Size 6.2 MB
Tags CPython 3.10 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
39400548874d71518a2194a2e54152a92a3339f92821102e2d2fba049ca2b934
BLAKE2b-256 checksum
How to use checksums
123881b74b50f334357fe9683468d0d5bb993a821dabf5a45f9e67ff849dd483
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Security for pylibsparseir 0.14.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.

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