Registry / http-networking / pywinctl

pywinctl

JSON →
library0.4.1pypypi✓ verified 86d ago

PyWinCtl is a cross-platform Python library (Windows, macOS, Linux with X11/Wayland) for getting information about and controlling on-screen windows. Version 0.4.1 supports Python 3.9+ and provides window enumeration, activation, resizing, moving, and property retrieval. Release cadence is irregular, with major features added every few months.

pip install pywinctl
INSTALL
IMPORT
SIG · PYWINCTL
P
pywinctl
http-networkingpythonv0.4.1
Install
2.0s avg
Import
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 21MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.0s · import 0.000s · 21MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PyWinCtl
import pywinctl as pwc
from pywinctl import PyWinCtl
PyWinCtl is the library name, not a class; use module-level functions and the Window class.
Window
import pywinctl; win = pywinctl.getAllWindows()[0]
from pywinctl import Window; win = Window()
Window objects are returned by functions like getAllWindows(), getActiveWindow(), etc. They are not instantiated directly.
getAllWindows
import pywinctl; pywinctl.getAllWindows()
import pywinctl; pywinctl.getWindows()
The function is named getAllWindows; getWindows does not exist.

Basic usage: enumerate windows, get active window, move/resize.

import pywinctl # Get all windows windows = pywinctl.getAllWindows() for win in windows: print(f'{win.title}: {win.bbox}') # Get active window active = pywinctl.getActiveWindow() if active: print('Active window title:', active.title) # Move and resize window win = windows[0] win.moveTo(100, 100) win.resizeTo(800, 600) # Check if window is visible print('Visible:', win.isVisible)
Debug
Known issues
gotchaOn Linux with Wayland, getActiveWindow() may return None unless 'unsafe mode' is enabled. Enable by setting environment variable PYWNCTL_WAYLAND_UNSAFE=1 before import.
fix
os.environ['PYWNCTL_WAYLAND_UNSAFE'] = '1' before importing pywinctl.
affects: >=0.1,<=0.4.0
deprecatedThe method getDisplay() is deprecated in v0.4 and replaced by getMonitor().
fix
Use getMonitor() instead of getDisplay().
affects: 0.4.0
breakingMacOS: MacOSNSWindow was removed in v0.4. All window operations now use AppleScript. Code that directly references MacOSNSWindow will break.
fix
Use the standard pywinctl API; class MacOSNSWindow no longer exists.
affects: 0.4.0 and later
gotchaWindow.moveTo() and resizeTo() expect integer coordinates. Passing floats may cause silent failure or unexpected behavior.
fix
Always convert to int: win.moveTo(int(x), int(y)).
affects: all
Errors
Common errors & fixes
AttributeError: module 'pywinctl' has no attribute 'PyWinCtl'
Attempting to import 'PyWinCtl' as a class when it is the module name.
fix
Use 'import pywinctl' and then call functions like pywinctl.getAllWindows().
TypeError: 'NoneType' object is not iterable
getAllWindows() returns None on unsupported platforms or if the backend fails.
fix
Check if the result is None before iterating: windows = pywinctl.getAllWindows() or []
OSError: [WinError 5] Access is denied
On Windows, trying to manipulate a window owned by another process (e.g., UIPI) without proper privileges.
fix
Run the script with elevated permissions (admin) or target windows that allow external control.
ModuleNotFoundError: No module named 'pywinctl._pywinctl_osx'
Trying to import internal submodules directly; they are platform-specific and not intended for direct use.
fix
Use the public API: 'import pywinctl' and let the library handle the backend selection.
Upgrade
Version history
0.4.1latest on PyPI · released Sep 23, 2024
Audit
Dependencies
pygetwindowrequiredCore dependency for basic window management
pyrectrequiredUsed for rectangle geometry operations
pymonctlrequiredMulti-monitor support (added in v0.0.50)
Agent activity
22 hits · last 30 days
node
16
Resources
pywinctl — pip install pywinctl · libregistry