Skip to main content

Python library for using asyncio in Qt-based applications

Project description

qasync

Maintenance PyPI PyPI - License PyPI - Python Version PyPI - Download GitHub Workflow Status

Introduction

qasync allows coroutines to be used in PyQt/PySide applications by providing an implementation of the PEP 3156 event loop.

With qasync, you can use asyncio functionalities directly inside Qt app's event loop, in the main thread. Using async functions for Python tasks can be much easier and cleaner than using threading.Thread or QThread.

If you need some CPU-intensive tasks to be executed in parallel, qasync also got that covered, providing QEventLoop.run_in_executor which is functionally identical to that of asyncio.

Basic Example

import sys
import asyncio

from qasync import QEventLoop, QApplication
from PySide6.QtWidgets import QWidget, QVBoxLayout

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()

        self.setLayout(QVBoxLayout())
        self.lbl_status = QLabel("Idle", self)
        self.layout().addWidget(self.lbl_status)

    @asyncClose
    async def closeEvent(self, event):
        pass

    @asyncSlot()
    async def onMyEvent(self):
        pass


if __name__ == "__main__":
    app = QApplication(sys.argv)

    event_loop = QEventLoop(app)
    asyncio.set_event_loop(event_loop)

    app_close_event = asyncio.Event()
    app.aboutToQuit.connect(app_close_event.set)

    main_window = MainWindow()
    main_window.show()

    with event_loop:
        event_loop.run_until_complete(app_close_event.wait())

More detailed examples can be found here.

The Future of qasync

qasync is a fork of asyncqt, which is a fork of quamash. qasync was created because those are no longer maintained. May it live longer than its predecessors.

qasync will continue to be maintained, and will still be accepting pull requests.

Requirements

  • Python >= 3.8
  • PyQt5/PyQt6 or PySide2/PySide6

qasync is tested on Ubuntu, Windows and MacOS.

If you need Python 3.6 or 3.7 support, use the v0.25.0 tag/release.

Installation

To install qasync, use pip:

pip install qasync

License

You may use, modify and redistribute this software under the terms of the BSD License. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qasync-0.27.1.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

qasync-0.27.1-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file qasync-0.27.1.tar.gz.

File metadata

  • Download URL: qasync-0.27.1.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.13 Linux/6.2.0-1015-azure

File hashes

Hashes for qasync-0.27.1.tar.gz
Algorithm Hash digest
SHA256 8dc768fd1ee5de1044c7c305eccf2d39d24d87803ea71189d4024fb475f4985f
MD5 a24350244114dac9f6d61eb0d1b903c8
BLAKE2b-256 1ce07c7c973f52e1765d6ddfc41e9272294f65d5d52b8f5f5eae92adf411ad46

See more details on using hashes here.

File details

Details for the file qasync-0.27.1-py3-none-any.whl.

File metadata

  • Download URL: qasync-0.27.1-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.13 Linux/6.2.0-1015-azure

File hashes

Hashes for qasync-0.27.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d57335723bc7d9b328dadd8cb2ed7978640e4bf2da184889ce50ee3ad2602c7
MD5 1b4b5dd5efa9ecd06f368ff2c190cefb
BLAKE2b-256 5106bc628aa2981bcfd452a08ee435b812fd3eee4ada8acb8a76c4a09d1a5a77

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page