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.15.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.15.0
File Actions
pylibsparseir-0.15.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.15.0-cp314-cp314-manylinux_2_28_x86_64.whl
pylibsparseir-0.15.0-cp314-cp314-macosx_15_0_arm64.whl CPython 3.14 CPython 3.14 macOS 15.0+ ARM64 Details for pylibsparseir-0.15.0-cp314-cp314-macosx_15_0_arm64.whl
pylibsparseir-0.15.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.15.0-cp313-cp313-manylinux_2_28_x86_64.whl
pylibsparseir-0.15.0-cp313-cp313-macosx_15_0_arm64.whl CPython 3.13 CPython 3.13 macOS 15.0+ ARM64 Details for pylibsparseir-0.15.0-cp313-cp313-macosx_15_0_arm64.whl
pylibsparseir-0.15.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.15.0-cp312-cp312-manylinux_2_28_x86_64.whl
pylibsparseir-0.15.0-cp312-cp312-macosx_15_0_arm64.whl CPython 3.12 CPython 3.12 macOS 15.0+ ARM64 Details for pylibsparseir-0.15.0-cp312-cp312-macosx_15_0_arm64.whl
pylibsparseir-0.15.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.15.0-cp311-cp311-manylinux_2_28_x86_64.whl
pylibsparseir-0.15.0-cp311-cp311-macosx_15_0_arm64.whl CPython 3.11 CPython 3.11 macOS 15.0+ ARM64 Details for pylibsparseir-0.15.0-cp311-cp311-macosx_15_0_arm64.whl
pylibsparseir-0.15.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.15.0-cp310-cp310-manylinux_2_28_x86_64.whl
pylibsparseir-0.15.0-cp310-cp310-macosx_15_0_arm64.whl CPython 3.10 CPython 3.10 macOS 15.0+ ARM64 Details for pylibsparseir-0.15.0-cp310-cp310-macosx_15_0_arm64.whl

Total release size: 66.9 MB

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

Download URL pylibsparseir-0.15.0-cp314-cp314-manylinux_2_28_x86_64.whl
Size 7.2 MB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
d6f0c1427f260576e8350f72cd556e7c88138f0e4c91e39e1596b72240d2996f
BLAKE2b-256 checksum
How to use checksums
55ea7353375868526f0dac2d34b4a2bcb81d5ffddf02d15b9544ea33b9c863bc
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.15.0-cp314-cp314-macosx_15_0_arm64.whl

Download URL pylibsparseir-0.15.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
84c32c4763da4de6d917e2d0e1b4fdf1de5fa48f3925dec20df2abdd9cf16dc2
BLAKE2b-256 checksum
How to use checksums
c4da34cf0e7c21424a3d2958b4188cd6788b1a93851acb8b3453ce3ce7a1545f
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.15.0-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL pylibsparseir-0.15.0-cp313-cp313-manylinux_2_28_x86_64.whl
Size 7.2 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
02ee58f8895ee21cee6292ff64ff4927c653c1f1013ab5ff939ca02160fb6ad0
BLAKE2b-256 checksum
How to use checksums
ccc4f7bfe63df7fc080fcaeb099d5f7bdc47d0bdc571f1b17005d75d36782f52
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.15.0-cp313-cp313-macosx_15_0_arm64.whl

Download URL pylibsparseir-0.15.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
fa7680e8343c62ce5c34ffefbd902e3d04cc942b126cae4054e774857f447bdc
BLAKE2b-256 checksum
How to use checksums
a52f835852b33ac812bfb93c234ac1c4fb4cabf37d949180108d394dfbb642bb
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.15.0-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL pylibsparseir-0.15.0-cp312-cp312-manylinux_2_28_x86_64.whl
Size 7.2 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
2fb182bdf76a7420f7269906d2dcbeae5b1382becb066ab024c9cfa495029223
BLAKE2b-256 checksum
How to use checksums
0902a9428974c9d60533f1e179eae9b0ad462f978988658c3c0786b5eeab78e2
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.15.0-cp312-cp312-macosx_15_0_arm64.whl

Download URL pylibsparseir-0.15.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
18099c4899e17cbe0158f15822e57d3353815629abe7cd9187111977d5194d3f
BLAKE2b-256 checksum
How to use checksums
57d0cabcb9ac4178beba87d2ac025b82a368ace204930a08d527a5fbc0925565
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.15.0-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL pylibsparseir-0.15.0-cp311-cp311-manylinux_2_28_x86_64.whl
Size 7.2 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8e82e1281f39d752a3dc0a375c031edcfae14a360bb6cc6867329443cb6d6a2f
BLAKE2b-256 checksum
How to use checksums
18b7e1380c06bb5ddd2bbb67483b72650a81b7f3c5b9a0ed358ed313b9f5d1b3
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.15.0-cp311-cp311-macosx_15_0_arm64.whl

Download URL pylibsparseir-0.15.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
54ee9491d948b21d30dfaf9bc9a5751f0e98c500d35c0e3714de24672236dbd0
BLAKE2b-256 checksum
How to use checksums
435990ad5e475ad08e4137b9353502d54437288976ff441fd507e34258fce9db
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.15.0-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL pylibsparseir-0.15.0-cp310-cp310-manylinux_2_28_x86_64.whl
Size 7.2 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
46491ac93251339ca6839ffcd23bb2fc0c00dd7797db2bf4ec2f37ea28e7e93a
BLAKE2b-256 checksum
How to use checksums
52a69176962f1e5d3a7e0a350a38511af41e272ae5cee362ccd43236197b839e
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.15.0-cp310-cp310-macosx_15_0_arm64.whl

Download URL pylibsparseir-0.15.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
43cd23e3d289a22cb405faa05ab197b700e0be0087ddf2320bfc410f72054235
BLAKE2b-256 checksum
How to use checksums
06e386aa4f8801498b3d9f5922c847cb7077e23241c63819868bcd29e34f1422
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.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.

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