Skip to main content

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. By default QThreadExecutor is used, but any class implementing the concurrent.futures.Executor interface will do the job.

Basic Example

import asyncio
import sys

from PySide6.QtWidgets import QVBoxLayout, QWidget

from qasync import QApplication, QEventLoop


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)

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

    main_window = MainWindow()
    main_window.show()

    # for 3.11 or older use qasync.run instead of asyncio.run
    # qasync.run(app_close_event.wait())
    asyncio.run(app_close_event.wait(), loop_factory=QEventLoop)

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, <3.14
  • 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.

Metadata

Release files for qasync 0.28.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qasync 0.28.0
File Size Uploaded
qasync-0.28.0.tar.gz 14.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qasync 0.28.0
File Interpreter ABI Platform
qasync-0.28.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.2 kB

Release files / qasync-0.28.0.tar.gz

Download URL qasync-0.28.0.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6f7f1f18971f59cb259b107218269ba56e3ad475ec456e54714b426a6e30b71d
BLAKE2b-256 checksum
How to use checksums
ecb25be08597dbbf331edb69478eae2f8dd511834cebf56a183b442e7437f8e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.3

Release files / qasync-0.28.0-py3-none-any.whl

Download URL qasync-0.28.0-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21faba8d047c717008378f5ac29ea58c32a8128528629e4afd57c59b768dba0f
BLAKE2b-256 checksum
How to use checksums
e5840ce4cd946f6e958428c87d5accac35df70f81607e45ba4919947d0762d63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.3

Release history Release notifications | RSS feed

This release

0.28.0 This release

2 release files

0.27.1

2 release files

0.27.0

2 release files

0.24.2

2 release files

0.24.0

2 release files

0.22.0

2 release files

0.19.0

2 release files

0.18.1

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.10.0

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

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