Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.940 runs
build_error
glibcpy 3.10–3.940 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Object
✓ from winrt.system import Object
SpeechSynthesizer
✓ from winrt.windows.media.speechsynthesis import SpeechSynthesizer
Uri
✓ from winrt.windows.foundation import Uri
✗ import winrt.windows.foundation as wf; wf.Uri
While aliasing works, direct import of specific classes is often preferred for clarity.
This quickstart demonstrates how to use `winrt-runtime` along with specific WinRT namespace packages to synthesize and play speech. It utilizes asynchronous WinRT APIs with Python's `asyncio`. Make sure to install `winrt-Windows.Media.SpeechSynthesis` and `winrt-Windows.Media.Playback` for this example to run.
import asyncio
from winrt.system import Object
from winrt.windows.media.speechsynthesis import SpeechSynthesizer
from winrt.windows.media.playback import MediaPlayer, MediaPlayerAudioCategory
async def speak_hello_world():
synth = SpeechSynthesizer()
# Asynchronous operation, must be awaited
stream = await synth.synthesize_text_to_stream_async("Hello, World from WinRT!")
media_ended_event = asyncio.Event()
loop = asyncio.get_running_loop()
def on_media_ended(sender: MediaPlayer, args: Object):
loop.call_soon_threadsafe(media_ended_event.set)
player = MediaPlayer()
player.audio_category = MediaPlayerAudioCategory.SPEECH
player.set_stream_source(stream)
player.add_media_ended(on_media_ended)
player.play()
await media_ended_event.wait()
print("Speech finished.")
if __name__ == "__main__":
# Ensure required namespace packages are installed:
# pip install winrt-Windows.Media.SpeechSynthesis winrt-Windows.Media.Playback
asyncio.run(speak_hello_world())
Debug
Known issues
breakingStarting with v3.0.0, the Python WinRT bindings transitioned from monolithic `winrt` or `winsdk` packages to a modular distribution. Each WinRT namespace (e.g., `Windows.Foundation`, `Windows.Media.SpeechSynthesis`) now requires its own `winrt-Windows.Namespace` package installation.fixInstead of `pip install winrt` or `pip install winsdk`, install `winrt-runtime` for the base runtime and then `pip install winrt-Windows.MyNamespace` for each specific WinRT namespace you need. Update imports from `winsdk.windows.some_module` or `winrt.windows.some_module` to `from winrt.windows.some_module import SomeClass`.
affects: >=3.0.0
deprecatedThe `winsdk` package, which was a community-maintained fork after the original `winrt` package, is now deprecated in favor of the modular `winrt-runtime` and `winrt-Windows.*` package structure.fixMigrate to `winrt-runtime` and the specific `winrt-Windows.*` namespace packages. This involves adjusting both installation commands and import statements.
affects: All `winsdk` versions
gotchaWinRT APIs often involve asynchronous operations, which require proper integration with Python's `asyncio` event loop. Incorrect handling can lead to blocking or unexpected behavior.fixAlways `await` WinRT asynchronous methods (those ending with `_async`). For events that signal completion (like `MediaEnded`), use `asyncio.Event` and ensure callbacks are scheduled on the event loop with `loop.call_soon_threadsafe`.
affects: All
Upgrade
Version history
3.2.1latest on PyPI · released Jun 6, 2025
Audit
Dependencies
No dependency data recorded yet.