GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - CabbageDevelopment/qasync: Python library for using asyncio in Qt-based applications.

BranchesTags
Open more actions menu

Latest commit

 

History

229 Commits
229 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
examples
examples
 
 
src/qasync
src/qasync
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.pre-commit-config.yaml
.pre-commit-config.yaml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pyproject.toml
pyproject.toml
 
 
uv.lock
uv.lock
 
 

Repository files navigation

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.QtGui import QCloseEvent
from PySide6.QtWidgets import QApplication, QPushButton, QVBoxLayout, QWidget

import qasync
from qasync import QEventLoop, asyncClose, asyncSlot


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

        layout = QVBoxLayout()
        self.button = QPushButton("Load", self)
        self.button.clicked.connect(self.onButtonClicked)
        layout.addWidget(self.button)
        self.setLayout(layout)

    @asyncSlot()
    async def onButtonClicked(self):
        """
        Use async code in a slot by decorating it with @asyncSlot.
        """
        self.button.setText("Loading...")
        await asyncio.sleep(1)
        self.button.setText("Load")

    @asyncClose
    async def closeEvent(self, event: QCloseEvent):
        """
        Use async code in a closeEvent by decorating it with @asyncClose.
        """
        self.button.setText("Closing...")
        await asyncio.sleep(1)


async def main(app):
    app_close_event = asyncio.Event()
    app.aboutToQuit.connect(app_close_event.set)
    main_window = MainWindow()
    main_window.show()
    await app_close_event.wait()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    # for python 3.11 or newer
    asyncio.run(main(app), loop_factory=QEventLoop)
    # for python 3.10 or older
    # qasync.run(main(app))

More detailed examples can be found in the examples directory.

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 using uv:

uv add qasync

To install using pip:

pip install qasync

License

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

About

Python library for using asyncio in Qt-based applications.

Topics

asynciolibraryqt

Resources

Readme
BSD-2-Clause license
Activity
Custom properties

Stars

410 stars

Watchers

6 watching

Forks

59 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.