Skip to main content

qt-await

This lets you use Python's async & await syntax with PyQt or PySide applications, to wait for Qt signals.

It doesn't integrate Qt with asyncio, trio, or code written for those frameworks.

Usage

To wait for arbitrary signals, wrap them in a SignalQueue. For example, using the QProcess.finished signal:

from PyQt5 import QtCore, QtWidgets
from qt_await import SignalQueue

class MainWindow(QtWidgets.QMainWindow):
    ...

    async def run_subprocess(self):
        proc = QtCore.QProcess()
        sq = SignalQueue(proc.finished)
        proc.start("sleep", ["2"])
        exit_code, exit_status = await sq

There are some helper functions to make common operations easier:

# Pause for 1s (all times are ms, following Qt's convention)
await sleep(1000)

# Pause repeatedly
async for _  in sleep_loop(1000):
    ...

# Wait for something else, with a time limit (also in ms)
await with_timeout(..., 3000)

# Run a QProcess & wait for its finished signal
await run_process(proc, "sleep", ["2"])

# Get streaming bytes from a QIODevice (e.g. a process or a socket)
async for b in read_streaming_bytes(...):
    dest.write(b)

# Similar, but decoding bytes output to strings
async for s in read_streaming_text(...):
    print(s, end='')

All this code needs to be in async def functions, so there are two extra functions to get from normal Qt code into async:

  • start_async(f()) starts an async function immediately.
  • connect_async(signal, f) connects an async function to a PyQt signal, to start whenever the signal is emitted.

Limitations

This is an experiment, which I mostly wrote for fun - use it at your own risk.

This doesn't integrate with asyncio (see qasync for that) or trio (see qtrio), or any other Python async libraries. It assumes you're doing things the Qt way - QProcess for subprocesses, QThread for threads, QNetworkRequest for HTTP, and so on. It aims to fit in with these APIs as much as possible.

It's also not really an async framework itself. If you want to write significant amounts of async code in Python, trio or asyncio will provide more robust machinery & better abstractions. qt_await just lets you sprinkle a bit of await in your Python Qt code.

Another thing you might want is the qt-async-threads package, which lets you wrap arbitrary slow Python functions in a thread and await their completion, to avoid blocking the event loop.

Metadata

Release files for qt_await 0.1

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

Source distribution (sdist)

Source distribution for qt_await 0.1
File Size Uploaded Provenance Actions
qt_await-0.1.tar.gz 8.2 kB Without provenance Details for qt_await-0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qt_await 0.1
File Interpreter ABI Platform Actions
qt_await-0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for qt_await-0.1-py2.py3-none-any.whl

Total release size: 14.9 kB

Release files / qt_await-0.1.tar.gz

Download URL qt_await-0.1.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
16de6fa483fe39d7cd4930c7bffadf5ac04c7ed4900a1d0200e17080b1eab7fb
BLAKE2b-256 checksum
How to use checksums
7f5da811b3ac6a22ae915eb7ebaa107d4638433c354ae9e13d264360e75d9fd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release files / qt_await-0.1-py2.py3-none-any.whl

Download URL qt_await-0.1-py2.py3-none-any.whl
Size 6.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c2b1d5c4f34f86adc7c4cc373a6d6708d047708fd4ff5669bce93443527cceaa
BLAKE2b-256 checksum
How to use checksums
4650cca837b1f2f49d5943172d542cd068237a59968d07cf3bf6c6f9835f4b58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Security for qt_await 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files No provenance

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