Provides an abstraction layer on top of the various Qt bindings (PyQt5/6 and PySide2/6).
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Main QtPy package constants, exception classes, and binding information that provide the foundation for Qt binding abstraction and compatibility management.
Access to QtPy and underlying Qt binding version information.
__version__: str
"""QtPy version string (e.g., "2.4.3")"""
QT_VERSION: str | None
"""Version of Qt framework being used"""
PYQT_VERSION: str | None
"""Version of PyQt binding if being used, None otherwise"""
PYSIDE_VERSION: str | None
"""Version of PySide binding if being used, None otherwise"""Usage example:
import qtpy
print(f"QtPy version: {qtpy.__version__}")
print(f"Qt version: {qtpy.QT_VERSION}")
if qtpy.PYQT_VERSION:
print(f"PyQt version: {qtpy.PYQT_VERSION}")Information about the currently selected Qt binding and available bindings.
API: str
"""Currently selected API name ('pyqt5', 'pyside2', 'pyqt6', 'pyside6')"""
API_NAME: str
"""Display name of currently selected API ('PyQt5', 'PySide2', 'PyQt6', 'PySide6')"""
QT5: bool
"""True if Qt5 is being used"""
QT6: bool
"""True if Qt6 is being used"""
PYQT5: bool
"""True if PyQt5 is being used"""
PYQT6: bool
"""True if PyQt6 is being used"""
PYSIDE2: bool
"""True if PySide2 is being used"""
PYSIDE6: bool
"""True if PySide6 is being used"""Usage example:
import qtpy
# Check which binding is active
print(f"Using {qtpy.API_NAME}")
# Conditional logic based on binding
if qtpy.QT6:
print("Using Qt6 features")
elif qtpy.QT5:
print("Using Qt5 features")
# Check specific binding
if qtpy.PYQT5:
print("PyQt5 specific code")
elif qtpy.PYSIDE6:
print("PySide6 specific code")Constants for configuring and working with different Qt bindings.
QT_API: str
"""Environment variable name for selecting Qt API ('QT_API')"""
PYQT5_API: list[str]
"""Names of the expected PyQt5 api (['pyqt5'])"""
PYQT6_API: list[str]
"""Names of the expected PyQt6 api (['pyqt6'])"""
PYSIDE2_API: list[str]
"""Names of the expected PySide2 api (['pyside2'])"""
PYSIDE6_API: list[str]
"""Names of the expected PySide6 api (['pyside6'])"""
API_NAMES: dict[str, str]
"""Mapping of API names to display names"""
binding_specified: bool
"""True if a binding was explicitly specified via QT_API environment variable"""
initial_api: str
"""The initially requested API before any fallback logic"""Minimum supported versions for Qt and bindings.
QT5_VERSION_MIN: str
"""Minimum supported Qt5 version"""
QT6_VERSION_MIN: str
"""Minimum supported Qt6 version"""
PYQT5_VERSION_MIN: str
"""Minimum supported PyQt5 version"""
PYQT6_VERSION_MIN: str
"""Minimum supported PyQt6 version"""
PYSIDE2_VERSION_MIN: str
"""Minimum supported PySide2 version"""
PYSIDE6_VERSION_MIN: str
"""Minimum supported PySide6 version"""
QT_VERSION_MIN: str
"""Minimum supported Qt version (alias for QT5_VERSION_MIN)"""
PYQT_VERSION_MIN: str
"""Minimum supported PyQt version (alias for PYQT5_VERSION_MIN)"""
PYSIDE_VERSION_MIN: str
"""Minimum supported PySide version (alias for PYSIDE2_VERSION_MIN)"""Comprehensive error handling for different binding and module availability scenarios.
class PythonQtError(RuntimeError):
"""Generic error superclass for QtPy."""
class PythonQtWarning(RuntimeWarning):
"""Warning class for QtPy."""
class PythonQtValueError(ValueError):
"""Error raised if an invalid QT_API is specified."""
class QtBindingsNotFoundError(PythonQtError, ImportError):
"""Error raised if no bindings could be found."""
def __init__(self): ...
class QtModuleNotFoundError(ModuleNotFoundError, PythonQtError):
"""Raised when a Python Qt binding submodule is not installed/supported."""
def __init__(self, *, name: str, msg: str | None = None, **msg_kwargs): ...
class QtModuleNotInOSError(QtModuleNotFoundError):
"""Raised when a module is not supported on the current operating system."""
class QtModuleNotInQtVersionError(QtModuleNotFoundError):
"""Raised when a module is not implemented in the current Qt version."""
class QtBindingMissingModuleError(QtModuleNotFoundError):
"""Raised when a module is not supported by a given binding."""
class QtModuleNotInstalledError(QtModuleNotFoundError):
"""Raise when a module is supported by the binding, but not installed."""
def __init__(self, *, missing_package: str | None = None, **superclass_kwargs): ...Usage example:
import qtpy
try:
from qtpy import QtWebEngine
except qtpy.QtModuleNotFoundError as e:
print(f"Module not available: {e}")
# Handle missing module gracefully
try:
from qtpy import QtMacExtras
except qtpy.QtModuleNotInOSError as e:
print(f"Module not supported on this OS: {e}")Install with Tessl CLI
npx tessl i tessl/pypi-qtpy