qtpy

Provides an uniform layer to support PyQt5, PySide2, PyQt6, PySide6 with a single codebase

https://github.com/spyder-ide/qtpy

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    4 of 69 committers (5.8%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.7%) to scientific vocabulary

Keywords

closember pyqt pyqt6 pyside pyside2 pyside6 python qt-gui qtpy spyder

Keywords from Contributors

qt gtk tk wx flexible alignment notebooks docs ipython spec-0
Last synced: 6 months ago · JSON representation

Repository

Provides an uniform layer to support PyQt5, PySide2, PyQt6, PySide6 with a single codebase

Basic Info
  • Host: GitHub
  • Owner: spyder-ide
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 1010 KB
Statistics
  • Stars: 1,049
  • Watchers: 32
  • Forks: 156
  • Open Issues: 43
  • Releases: 15
Topics
closember pyqt pyqt6 pyside pyside2 pyside6 python qt-gui qtpy spyder
Created almost 11 years ago · Last pushed 8 months ago
Metadata Files
Readme Changelog Contributing Funding License Security Authors

README.md

QtPy: Abstraction layer for PyQt5/PySide2/PyQt6/PySide6

license pypi version conda version download count OpenCollective Backers Join the chat at https://gitter.im/spyder-ide/public
PyPI status Github build status Coverage Status

Copyright © 2009– The Spyder Development Team

Description

QtPy is a small abstraction layer that lets you write applications using a single API call to either PyQt or PySide.

It provides support for PyQt5, PySide2, PyQt6 and PySide6 using the Qt5 layout (where the QtGui module has been split into QtGui and QtWidgets).

Basically, you can write your code as if you were using PyQt or PySide directly, but import Qt modules from qtpy instead of PyQt5, PySide2, PyQt6 or PySide6.

Accordingly, when porting code between different Qt bindings (PyQt vs PySide) or Qt versions (Qt5 vs Qt6), QtPy makes this much more painless, and allows you to easily and incrementally transition between them. QtPy handles incompatibilities and differences between bindings or Qt versions for you while keeping your project running, so you can focus more on your own code and less on keeping track of supporting every Qt version and binding. Furthermore, when you do want to upgrade or support new bindings, it allows you to update your project module by module rather than all at once. You can check out examples of this approach in projects using QtPy, like git-cola.

Attribution and acknowledgments

This project is based on the pyqode.qt project and the spyderlib.qt module from the Spyder project, and also includes contributions adapted from qt-helpers, developed as part of the glue project.

Unlike pyqode.qt this is not a namespace package, so it is not tied to a particular project or namespace.

License

This project is released under the MIT license.

Requirements

You need PyQt5, PySide2, PyQt6 or PySide6 installed in your system to make use of QtPy. If several of these packages are found, PyQt5 is used by default unless you set the QT_API environment variable.

QT_API can take the following values:

  • pyqt5 (to use PyQt5).
  • pyside2 (to use PySide2).
  • pyqt6 (to use PyQt6).
  • pyside6 (to use PySide6).

Module aliases and constants

  • QtCore.pyqtSignal, QtCore.pyqtSlot and QtCore.pyqtProperty (available on PyQt5/6) are instead exposed as QtCore.Signal, QtCore.Slot and QtCore.Property, respectively, following the Qt5 module layout.

  • The Qt version being used can be checked with QtCore.__version__ (instead of QtCore.QT_VERSION_STR) as well as from qtpy.QT_VERSION.

  • For PyQt6 enums, unscoped enum access was added by promoting the enums of the QtCore, QtGui, QtTest and QtWidgets modules.

  • Compatibility is added between the QtGui and QtOpenGL modules for the QOpenGL* classes.

  • To check the current binding version, you can use qtpy.PYSIDE_VERSION for PySide2/6 and qtpy.PYQT_VERSION for PyQt5/6. If the respective binding is not being used, the value of its attribute will be None.

  • To check the current selected binding, you can use qtpy.API_NAME

  • There are boolean values to check if Qt5/6, PyQt5/6 or PySide2/6 are being used: qtpy.QT5, qtpy.QT6, qtpy.PYQT5, qtpy.PYQT6, qtpy.PYSIDE2 and qtpy.PYSIDE6. True if currently being used, False otherwise.

Compat module

In the qtpy.compat module, you can find wrappers for QFileDialog static methods and SIP/Shiboken functions, such as:

  • QFileDialog.getExistingDirectory wrapped with qtpy.compat.getexistingdirectory

  • QFileDialog.getOpenFileName wrapped with qtpy.compat.getopenfilename

  • QFileDialog.getOpenFileNames wrapped with qtpy.compat.getopenfilenames

  • QFileDialog.getSaveFileName wrapped with qtpy.compat.getsavefilename

  • sip.isdeleted and shiboken.isValid wrapped with qtpy.compat.isalive

Installation

bash pip install qtpy

or

bash conda install qtpy

Type checker integration

Type checkers have no knowledge of installed packages, so these tools require additional configuration.

A Command Line Interface (CLI) is offered to help with usage of QtPy (to get MyPy and Pyright/Pylance args/configurations).

Mypy

The mypy-args command helps you to generate command line arguments for Mypy that will enable it to process the QtPy source files with the same API as QtPy itself would have selected.

If you run

bash qtpy mypy-args

QtPy will output a string of Mypy CLI args that will reflect the currently selected Qt API. For example, in an environment where PyQt5 is installed and selected (or the default fallback, if no binding can be found in the environment), this would output the following:

text --always-true=PYQT5 --always-false=PYSIDE2 --always-false=PYQT6 --always-false=PYSIDE6

Using Bash or a similar shell, this can be injected into the Mypy command line invocation as follows:

bash mypy --package mypackage $(qtpy mypy-args)

Pyright/Pylance

In the case of Pyright, instead of runtime arguments, it is required to create a config file for the project, called pyrightconfig.json or a pyright section in pyproject.toml. See here for reference. In order to set this configuration, QtPy offers the pyright-config command for guidance.

If you run

bash qtpy pyright-config

you will get the necessary configs to be included in your project files. If you don't have them, it is recommended to create the latter. For example, in an environment where PyQt5 is installed and selected (or the default fallback, if no binding can be found in the environment), this would output the following:

```text pyrightconfig.json: {"defineConstant": {"PYQT5": true, "PYSIDE2": false, "PYQT6": false, "PYSIDE6": false}}

pyproject.toml: [tool.pyright.defineConstant] PYQT5 = true PYSIDE2 = false PYQT6 = false PYSIDE6 = false ```

Note: These configurations are necessary for the correct usage of the default VSCode's type checking feature while using QtPy in your source code.

Testing matrix

Currently, QtPy runs tests for different bindings on Linux, Windows and macOS, using Python 3.7 and 3.11, and installing those bindings with conda and pip. For the PyQt bindings, we also check the installation of extra packages via pip.

Following this, the current test matrix looks something like this:

| | Python | 3.7 | | 3.11 | | |---------|-----------------|--------------------------------------------|------|--------------------|----------------------------| | OS | Binding / manager | conda | pip | conda | pip | | Linux | PyQt5 | 5.12 | 5.15 | 5.15 | 5.15 (with extras) | | | PyQt6 | skip (unavailable) | 6.3 | skip (unavailable) | 6.5 (with extras) | | | PySide2 | 5.13 | 5.12 | 5.15 | skip (no wheels available) | | | PySide6 | 6.4 | 6.3 | 6.5 | 6.5 | | Windows | PyQt5 | 5.9 | 5.15 | 5.15 | 5.15 (with extras) | | | PyQt6 | skip (unavailable) | 6.2 | skip (unavailable) | 6.5 (with extras) | | | PySide2 | 5.13 | 5.12 | 5.15 | skip (no wheels available) | | | PySide6 | skip (test hang with 6.4. 6.5 unavailable) | 6.2 | 6.5 | 6.5 | | MacOS | PyQt5 | 5.12 | 5.15 | 5.15 | 5.15 (with extras) | | | PyQt6 | skip (unavailable) | 6.3 | skip (unavailable) | 6.5 (with extras) | | | PySide2 | 5.13 | 5.12 | 5.15 | skip (no wheels available) | | | PySide6 | 6.4 | 6.3 | 6.5 | 6.5 |

Note: The mentioned extra packages for the PyQt bindings are the following:

  • PyQt3D and PyQt6-3D
  • PyQtChart and PyQt6-Charts
  • PyQtDataVisualization and PyQt6-DataVisualization
  • PyQtNetworkAuth and PyQt6-NetworkAuth
  • PyQtPurchasing
  • PyQtWebEngine and PyQt6-WebEngine
  • QScintilla and PyQt6-QScintilla

Contributing

Everyone is welcome to contribute! See our Contributing guide for more details.

Sponsors

QtPy is funded thanks to the generous support of

Chan Zuckerberg InitiativeNumfocus

and the donations we have received from our users around the world through Open Collective:

Sponsors

Owner

  • Name: Spyder IDE
  • Login: spyder-ide
  • Kind: organization

The Scientific Python Development Environment

GitHub Events

Total
  • Create event: 2
  • Release event: 2
  • Issues event: 16
  • Watch event: 74
  • Delete event: 1
  • Issue comment event: 41
  • Push event: 10
  • Pull request review event: 4
  • Pull request event: 15
  • Fork event: 5
Last Year
  • Create event: 2
  • Release event: 2
  • Issues event: 16
  • Watch event: 74
  • Delete event: 1
  • Issue comment event: 41
  • Push event: 10
  • Pull request review event: 4
  • Pull request event: 15
  • Fork event: 5

Committers

Last synced: 8 months ago

All Time
  • Total Commits: 887
  • Total Committers: 69
  • Avg Commits per committer: 12.855
  • Development Distribution Score (DDS): 0.772
Past Year
  • Commits: 19
  • Committers: 6
  • Avg Commits per committer: 3.167
  • Development Distribution Score (DDS): 0.368
Top Committers
Name Email Commits
Carlos Cordoba c****2@g****m 202
dalthviz d****0@u****o 155
Gonzalo Peña-Castellanos g****a@g****m 83
C.A.M. Gerlach C****h@G****M 74
David Kincaid d****a@g****m 57
stsav012 s****2@g****m 54
Thomas Robitaille t****e@g****m 51
Julien Schueller s****r@p****m 17
Rafael Laverde l****1@g****m 16
Grzegorz Bokota b****b@g****m 12
kumattau k****u@g****m 12
pre-commit-ci[bot] 6****] 10
David Aguilar d****d@g****m 9
Joseph Martinot-Lagarde c****e@g****m 8
Dhruv Govil d****l@g****m 7
Dennis Goeries d****s@x****u 6
René Fritze r****e@w****e 6
Daniel Edler d****r@w****e 5
Eric Larson l****d@g****m 5
Talley Lambert t****t@g****m 5
Matthieu Dartiailh m****h@g****m 4
Tobias Gehring t****g@f****k 4
Kyle Altendorf s****a@f****t 4
Kurt Jacobson k****r@g****m 4
Almar Klein a****n@g****m 4
stonebig s****4@g****m 4
Antonio Valentino a****o@t****t 3
Damon Lynch d****h@g****m 3
Julian Gilbey j****t@d****t 3
Karthikeyan Singaravelan t****i@g****m 3
and 39 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 92
  • Total pull requests: 103
  • Average time to close issues: 4 months
  • Average time to close pull requests: 18 days
  • Total issue authors: 53
  • Total pull request authors: 28
  • Average comments per issue: 3.05
  • Average comments per pull request: 3.33
  • Merged pull requests: 79
  • Bot issues: 0
  • Bot pull requests: 4
Past Year
  • Issues: 14
  • Pull requests: 18
  • Average time to close issues: 19 days
  • Average time to close pull requests: 3 days
  • Issue authors: 10
  • Pull request authors: 7
  • Average comments per issue: 0.36
  • Average comments per pull request: 1.94
  • Merged pull requests: 12
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • dalthviz (15)
  • StSav012 (11)
  • yurivict (5)
  • CAM-Gerlach (4)
  • th3w1zard1 (3)
  • adam-grant-hendry (2)
  • ccordoba12 (2)
  • owillebo (2)
  • goanpeca (2)
  • hannesdelbeke (2)
  • ZeeD (2)
  • dhkimmm (1)
  • Savita-Panwar (1)
  • oscargus (1)
  • niklashenning (1)
Pull Request Authors
  • dalthviz (21)
  • StSav012 (18)
  • CAM-Gerlach (11)
  • jschueller (6)
  • Czaki (4)
  • hmaarrfk (4)
  • zjp (4)
  • pre-commit-ci[bot] (4)
  • DaelonSuzuka (3)
  • ccordoba12 (3)
  • rear1019 (3)
  • Bzero (2)
  • PatriceJada (2)
  • juliangilbey (2)
  • davvid (2)
Top Labels
Issue Labels
type:Task (19) type:Enhancement (17) type:Bug (13) type:Question (12) type:Awaiting followup (11) reso:noQtPy (6) reso:duplicate (3) community:help wanted (3) reso:invalid (2) type:Discussion (2) reso:wontfix (1) type:Feature (1)
Pull Request Labels
type:Task (36) type:Enhancement (30) type:Bug (20) type:Feature (3) type:Discussion (2)

Packages

  • Total packages: 18
  • Total downloads:
    • pypi 6,617,073 last-month
  • Total docker downloads: 1,063,133
  • Total dependent packages: 608
    (may contain duplicates)
  • Total dependent repositories: 7,742
    (may contain duplicates)
  • Total versions: 151
  • Total maintainers: 5
pypi.org: qtpy

Provides an abstraction layer on top of the various Qt bindings (PyQt5/6 and PySide2/6).

  • Versions: 42
  • Dependent Packages: 438
  • Dependent Repositories: 6,552
  • Downloads: 6,617,073 Last month
  • Docker Downloads: 1,063,133
Rankings
Dependent packages count: 0.1%
Dependent repos count: 0.1%
Downloads: 0.1%
Docker downloads count: 0.8%
Average: 1.2%
Stargazers count: 2.1%
Forks count: 4.0%
Maintainers (3)
Last synced: 6 months ago
alpine-v3.18: py3-qtpy-pyc

Precompiled Python bytecode for py3-qtpy

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 4.5%
Forks count: 8.9%
Stargazers count: 9.0%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.18: py3-qtpy

QtPy: Abstraction layer for PyQt5/PySide2/PyQt6/PySide6

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 4.5%
Forks count: 8.9%
Stargazers count: 9.0%
Maintainers (1)
Last synced: 6 months ago
proxy.golang.org: github.com/spyder-ide/qtpy
  • Versions: 36
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 2.2%
Forks count: 2.2%
Average: 6.2%
Dependent packages count: 9.6%
Dependent repos count: 10.8%
Last synced: 6 months ago
alpine-edge: py3-qtpy

QtPy: Abstraction layer for PySide2/PyQt6/PySide6

  • Versions: 9
  • Dependent Packages: 1
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 6.0%
Average: 6.6%
Forks count: 9.8%
Stargazers count: 10.6%
Maintainers (1)
Last synced: 6 months ago
spack.io: py-qtpy

QtPy: Abtraction layer for PyQt5/PyQt4/PySide/PySide2

  • Versions: 3
  • Dependent Packages: 6
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 7.1%
Forks count: 8.4%
Stargazers count: 8.5%
Dependent packages count: 11.6%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.17: py3-qtpy

QtPy: Abstraction layer for PyQt5/PySide2/PyQt6/PySide6

  • Versions: 1
  • Dependent Packages: 3
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 7.5%
Forks count: 8.5%
Stargazers count: 8.7%
Dependent packages count: 12.7%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: qtpy

QtPy is a small abstraction layer that lets you write applications using a single API call to either PyQt or PySide. It provides support for PyQt5, PyQt6, PySide6, PySide2 (using the Qt5 layout), so you can write your code as if you were using PyQt or PySide directly, but import Qt modules from qtpy instead of PyQt5, PySide2, PyQt6 or PySide6. Accordingly, when porting code between different Qt bindings (PyQt vs PySide) or Qt versions (Qt5 vs Qt6), QtPy makes this much more painless, and allows you to easily and incrementally transition between them. QtPy handles incompatibilities and differences between bindings or Qt versions for you while keeping your project running, so you can focus more on your own code and less on keeping track of supporting every Qt version and binding. Furthermore, when you do want to upgrade or support new bindings, it allows you to update your project module by module rather than all at once.

  • Versions: 26
  • Dependent Packages: 148
  • Dependent Repositories: 595
Rankings
Dependent packages count: 0.5%
Dependent repos count: 1.1%
Average: 7.8%
Stargazers count: 14.5%
Forks count: 15.0%
Last synced: 6 months ago
alpine-edge: py3-qtpy-pyc

Precompiled Python bytecode for py3-qtpy

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 8.8%
Forks count: 10.2%
Stargazers count: 10.8%
Dependent packages count: 14.1%
Maintainers (1)
Last synced: 6 months ago
anaconda.org: qtpy

QtPy is a small abstraction layer that lets you write applications using a single api call to either PyQt or PySide.

  • Versions: 17
  • Dependent Packages: 12
  • Dependent Repositories: 595
Rankings
Dependent packages count: 3.7%
Dependent repos count: 6.6%
Average: 15.9%
Stargazers count: 26.2%
Forks count: 27.0%
Last synced: 6 months ago
alpine-v3.21: py3-qtpy-pyc

Precompiled Python bytecode for py3-qtpy

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.22: py3-qtpy

QtPy: Abstraction layer for PyQt5/PySide2/PyQt6/PySide6

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.22: py3-qtpy-pyc

Precompiled Python bytecode for py3-qtpy

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.20: py3-qtpy-pyc

Precompiled Python bytecode for py3-qtpy

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.19: py3-qtpy

QtPy: Abstraction layer for PyQt5/PySide2/PyQt6/PySide6

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Last synced: 6 months ago
alpine-v3.20: py3-qtpy

QtPy: Abstraction layer for PyQt5/PySide2/PyQt6/PySide6

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.21: py3-qtpy

QtPy: Abstraction layer for PyQt5/PySide2/PyQt6/PySide6

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.19: py3-qtpy-pyc

Precompiled Python bytecode for py3-qtpy

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Last synced: 6 months ago

Dependencies

.github/workflows/ci.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • conda-incubator/setup-miniconda v2 composite