A Python bindings generator for C and C++ libraries
npx @tessl/cli install tessl/pypi-sip@5.5.0A comprehensive tool for creating Python bindings for C and C++ libraries. SIP originally developed to create PyQt but is applicable to any C/C++ library, providing build tools that process specification files and generate optimized C/C++ code compiled into extension modules.
pip install sipimport sipbuildFor specific functionality:
from sipbuild import Project, Bindings, Builder
from sipbuild import AbstractProject, AbstractBuilder
from sipbuild import Buildable, BuildableBindings, BuildableExecutable
from sipbuild import BuildableFromSources, BuildableModule
from sipbuild import Installable, Option
from sipbuild import UserException, UserParseException, handle_exception
from sipbuild import import_callable, resolve_abi_version
from sipbuild import SIP_VERSION, SIP_VERSION_STRfrom sipbuild import Project, Bindings
# Create a project for building Python bindings
project = Project()
# Configure bindings
bindings = Bindings(
sip_files=['mymodule.sip'],
include_dirs=['/usr/include'],
libraries=['mylib']
)
# Build the project
project.build()Command-line usage:
# Build project in current directory
sip-build
# Install the project
sip-install
# Create wheel distribution
sip-wheel
# Generate legacy SIP v5 compatible bindings
sip5 -c . mymodule.sipSIP follows a configurable build pipeline architecture:
This design enables creation of Python wheels that are version-independent (compatible with Python 3.5+), supports multiple extension modules within the same package, and provides sophisticated configuration and build management capabilities.
The primary programmatic interface for creating and managing Python binding projects, including project configuration, bindings generation, and build orchestration.
class Project:
def build(self): ...
def build_sdist(self, sdist_directory): ...
def build_wheel(self, wheel_directory): ...
def install(self): ...
class Bindings:
def generate(self): ...
def is_buildable(self): ...
def verify_configuration(self): ...
class Builder:
def build(self): ...
def install(self): ...Seven command-line tools for building, installing, and managing SIP projects from the shell, providing complete project lifecycle management without requiring Python code.
sip-build # Build project in-situ
sip-install # Build and install project
sip-wheel # Build wheel distribution
sip-sdist # Build source distribution
sip-module # Generate sip module source
sip-distinfo # Create .dist-info directories
sip5 # Legacy SIP v5 compatibilityComprehensive configuration management supporting pyproject.toml files, command-line overrides, and environment markers for flexible project setup.
class Option:
def __init__(self, name, option_type, default=None, choices=None): ...
class Configurable:
def add_options(self, parser): ...
def apply_options(self, options): ...PEP 517 build backend support and integration with modern Python packaging workflows, enabling seamless integration with pip and other build tools.
def build_sdist(sdist_directory, config_settings=None): ...
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None): ...class UserException(Exception):
"""Base exception for user-friendly errors."""
pass
class UserFileException(UserException):
"""Base class for file-related user errors."""
pass
class UserParseException(UserException):
"""Exception for parsing errors in specification files."""
pass
class PyProjectException(UserFileException):
"""Exception related to pyproject.toml files."""
pass
class PyProjectOptionException(PyProjectException):
"""Configuration option errors in pyproject.toml."""
pass
class PyProjectUndefinedOptionException(PyProjectOptionException):
"""Exception for undefined required options."""
pass
def handle_exception(exception):
"""Standard exception handler for SIP tools."""
pass
class Installable:
"""Manages file installation to target directories."""
def install(self): ...
def get_full_target_dir(self): ...
def import_callable(callable_name, expected_type):
"""
Import callable from module for factory pattern support.
Args:
callable_name (str): Name of callable to import
expected_type (type): Expected type of the callable
Returns:
callable: Imported callable
"""
pass
def resolve_abi_version(version_spec):
"""
Resolve ABI version specification to actual version.
Args:
version_spec (str): Version specification (e.g., '12.8')
Returns:
tuple: (major, minor) version numbers
"""
pass
SIP_VERSION: int
"""Numeric version identifier."""
SIP_VERSION_STR: str
"""String version identifier (e.g., '5.5.0')."""