Skip to main content

uppercut-windows-window-capture

Captures one window on Windows with the Win32 PrintWindow call and saves it as PNG or BMP. It finds the window by title, class name or process id, and works as a Python module and as a command line tool. It uses only ctypes and the standard library, never brings the window to the front, and can take a series of shots to tell whether a window's picture is changing or stuck. The package imports on macOS and Linux, where every call that needs Windows raises UnsupportedPlatformError.

pip install uppercut-windows-window-capture
pip install "uppercut-windows-window-capture[pillow]"   # only needed for Capture.to_pil()
from uppercut_windows_window_capture import capture_window, find_window

window = find_window(title="Untitled - Notepad", timeout=10)
capture_window(window).save("notepad.png")
uppercut-window-capture --title "Untitled - Notepad" --out notepad.png
uppercut-window-capture --pid 4242 --client --out client.bmp
uppercut-window-capture --title "My App" --series 10 --interval 1 --out-dir shots

Functions

Function Returns
list_windows(visible_only=True) every top-level window as a WindowInfo
find_windows(title, class_name, pid, match, visible_only, min_size) the WindowInfo list that matches every given filter
find_window(title, class_name, pid, match, prefer_largest, timeout, interval) one WindowInfo; raises WindowNotFoundError after timeout seconds
capture_window(window, client_only, fallback, full_content, crop_to_frame, restore) a Capture; window is a WindowInfo or a handle
capture_series(window, count, interval, min_changed, **capture_options) a SeriesResult with the shots, the changed-pixel count of each pair and live
watch(grab, count, interval, min_changed) the same SeriesResult, from any function that returns a Capture
enable_dpi_awareness() nothing; call it first on scaled displays so sizes are real pixels
match_text(text, pattern, mode) whether the text matches. Modes: substring, exact, glob, regex, all case-insensitive
select_windows(windows, ...) filters a list of WindowInfo with the same rules as find_windows
frame_crop_box(window_rect, frame_rect) the (left, top, width, height) of the visible frame
encode_png, encode_bmp, bgra_to_rgb, count_changed_pixels helpers on raw top-down BGRA bytes

Capture has width, height, bgra, save(path, fmt=None), to_bytes(fmt), to_rgb(), to_pil(), crop(left, top, width, height), changed_pixels(other) and is_blank().

Capture options

Option Default Meaning
client_only False Capture the client area only, without title bar and borders
fallback "bitblt" If PrintWindow fails: "bitblt" copies from the window's device context, "screen" copies the window's rectangle from the screen (anything covering it shows up), "none" raises CaptureFailedError
full_content True Pass PW_RENDERFULLCONTENT so GPU-composed windows render
crop_to_frame False Trim the invisible resize border that the window rectangle includes on Windows 10 and 11
restore False Show a minimized window again, without activating it, before capturing

Command line

uppercut-window-capture takes --title, --class or --pid (any combination), plus:

Option Meaning
--match substring|exact|glob|regex How --title and --class match; default substring
--largest Use the largest window when several match
--wait SECONDS Keep looking for the window
--list Print the matching windows and exit
--client, --fallback, --no-full-content, --crop-frame, --restore, --dpi-aware The capture options above
--crop X,Y,W,H Keep only this rectangle
--fail-on-blank Exit 4 if the capture is one flat colour
--out FILE, --format png|bmp Output file; the format comes from the extension unless given. Default capture.png
--series N, --interval SECONDS, --min-changed PIXELS, --out-dir DIR Take N shots, save them as cap_00, cap_01 and so on, and print LIVE or FROZEN
Exit code Meaning
0 Captured, or the series is live
2 No window matched
3 The series is frozen: no pair of shots differed by --min-changed pixels
4 The capture failed
5 Not running on Windows
64 Wrong arguments

Errors

All errors derive from WindowCaptureError.

Error Raised when
UnsupportedPlatformError (also a RuntimeError) A window function is used on a system other than Windows
WindowNotFoundError (also a LookupError) No window matches, or the handle no longer exists
CaptureFailedError Windows returns no pixels, or the window has no visible area

Notes

  • Some Direct3D and OpenGL windows come back black from PrintWindow. Use Capture.is_blank() or --fail-on-blank to detect it, and try --fallback screen.
  • Capturing never activates the window or changes its position.

License

MIT

Metadata

Release files for uppercut-windows-window-capture 0.1.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 uppercut-windows-window-capture 0.1.0
File Size Uploaded Provenance Actions
uppercut_windows_window_capture-0.1.0.tar.gz 16.8 kB Without provenance Details for uppercut_windows_window_capture-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for uppercut-windows-window-capture 0.1.0
File Interpreter ABI Platform Actions
uppercut_windows_window_capture-0.1.0-py3-none-any.whl Python 3 none any Details for uppercut_windows_window_capture-0.1.0-py3-none-any.whl

Total release size: 34.4 kB

Release files / uppercut_windows_window_capture-0.1.0.tar.gz

Download URL uppercut_windows_window_capture-0.1.0.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0ea7201f406b9a099b2d0aa4252d6e56a292202301a7189e2d06f860d5e9a20f
BLAKE2b-256 checksum
How to use checksums
739a37828382ecc838b65ff16c46b4c2ebd5e54b88b0d27c5485546063365e6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / uppercut_windows_window_capture-0.1.0-py3-none-any.whl

Download URL uppercut_windows_window_capture-0.1.0-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3cd00a2491e94d8372785552cc5a105fbafe2571d73f5afb7fd58aa9be6ab38
BLAKE2b-256 checksum
How to use checksums
3ffc556ef1ca8fe316e5e7405fcbf887eba232c99da27f1ecfde1496064f97cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for uppercut-windows-window-capture 0.1.0

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.0 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