Skip to main content

A Python library for capturing and interacting with the desktop screen

Project description

TRAA Python Bindings

Python bindings for the TRAA (Transparent Remote Application Access) library, providing screen capture functionality for Windows, macOS, and Linux.

Features

  • Screen and window enumeration with filtering options
  • High-performance screen capture
  • Support for multiple displays and windows
  • Thumbnail and icon capture
  • Cross-platform compatibility (Windows, macOS, Linux)

Installation

pip install traa

Quick Start

from traa import Size, ScreenSourceFlags, enum_screen_sources, create_snapshot
from PIL import Image

# Enumerate screen sources
sources = enum_screen_sources(
    thumbnail_size=Size(160, 120),  # Optional: Get thumbnails
    icon_size=Size(32, 32),        # Optional: Get icons
    external_flags=ScreenSourceFlags.NONE  # Use default enumeration behavior
)

# Print available sources
for source in sources:
    print(f"Found source: {source}")
    
    # Save thumbnail if available
    if source.thumbnail_data is not None:
        Image.fromarray(source.thumbnail_data).save(f"thumb_{source.id}.png")
    
    # Save icon if available
    if source.icon_data is not None:
        Image.fromarray(source.icon_data).save(f"icon_{source.id}.png")

# Capture from the first source
if sources:
    # Capture at Full HD resolution
    image, actual_size = create_snapshot(sources[0].id, Size(1920, 1080))
    
    # Determine image mode based on shape
    mode = "RGB" if len(image.shape) == 3 and image.shape[2] == 3 else \
           "RGBA" if len(image.shape) == 3 and image.shape[2] == 4 else "L"
    
    # Save the snapshot
    Image.fromarray(image, mode=mode).save("snapshot.png")
    print(f"Captured image size: {actual_size}")

API Reference

Functions

enum_screen_sources(icon_size: Optional[Size] = None, thumbnail_size: Optional[Size] = None, external_flags: ScreenSourceFlags = ScreenSourceFlags.NONE) -> List[ScreenSourceInfo]

Enumerates available screen sources (displays and windows).

  • icon_size: Optional size for source icons
  • thumbnail_size: Optional size for source thumbnails
  • external_flags: Flags to control enumeration behavior
  • Returns: List of ScreenSourceInfo objects

Example:

# Get only non-minimized windows with thumbnails
sources = enum_screen_sources(
    thumbnail_size=Size(160, 120),
    external_flags=ScreenSourceFlags.IGNORE_SCREEN | ScreenSourceFlags.IGNORE_MINIMIZED
)

create_snapshot(source_id: int, size: Size) -> Tuple[np.ndarray, Size]

Creates a snapshot of the specified screen source.

  • source_id: ID of the source to capture
  • size: Requested size of the snapshot
  • Returns: Tuple of (image data as numpy array, actual capture size)

Example:

# Capture a window at 4K resolution
image, size = create_snapshot(window_id, Size(3840, 2160))
Image.fromarray(image, mode="RGB").save("4k_snapshot.png")

Classes

Size

Represents a size with width and height.

# Create a Full HD size
size = Size(width=1920, height=1080)
print(size)  # "1920x1080"

# Create a 4K UHD size
size_4k = Size(3840, 2160)

Rect

Represents a rectangle with left, top, right, and bottom coordinates.

# Create a rectangle
rect = Rect(left=0, top=0, right=1920, bottom=1080)
print(rect)  # "(0, 0, 1920, 1080)"
print(rect.width)  # 1920
print(rect.height)  # 1080

ScreenSourceInfo

Contains information about a screen source.

Properties:

  • id: Unique identifier
  • is_window: Whether this is a window or display
  • rect: Source rectangle
  • title: Source title
  • process_path: Process path (windows only)
  • is_minimized: Window minimized state
  • is_maximized: Window maximized state
  • is_primary: Whether this is the primary display
  • icon_data: Optional icon image data (numpy array)
  • thumbnail_data: Optional thumbnail image data (numpy array)

Example:

# Print detailed information about a source
def print_source_info(source):
    print(f"Source: {source.title}")
    print(f"Type: {'Window' if source.is_window else 'Display'}")
    print(f"Rectangle: {source.rect}")
    if source.is_window:
        print(f"Process: {source.process_path}")
        print(f"Minimized: {source.is_minimized}")
    else:
        print(f"Primary Display: {source.is_primary}")

ScreenSourceFlags

Enumeration flags for controlling screen source enumeration behavior.

class ScreenSourceFlags(IntFlag):
    NONE = 0                        # Default behavior
    IGNORE_SCREEN = 1 << 0          # Ignore display screens
    IGNORE_WINDOW = 1 << 1          # Ignore windows
    IGNORE_MINIMIZED = 1 << 2       # Ignore minimized windows
    NOT_IGNORE_UNTITLED = 1 << 3    # Include untitled windows
    NOT_IGNORE_UNRESPONSIVE = 1 << 4  # Include unresponsive windows
    IGNORE_CURRENT_PROCESS_WINDOWS = 1 << 5  # Ignore windows from current process
    NOT_IGNORE_TOOLWINDOW = 1 << 6  # Include tool windows
    IGNORE_NOPROCESS_PATH = 1 << 7  # Ignore windows without process path
    NOT_SKIP_SYSTEM_WINDOWS = 1 << 8  # Include system windows
    NOT_SKIP_ZERO_LAYER_WINDOWS = 1 << 9  # Include zero layer windows
    ALL = 0xFFFFFFFF                # All flags enabled

Common flag combinations:

# Get only displays (no windows)
displays = enum_screen_sources(
    external_flags=ScreenSourceFlags.IGNORE_WINDOW
)

# Get only active windows (no displays, no minimized)
active_windows = enum_screen_sources(
    external_flags=ScreenSourceFlags.IGNORE_SCREEN | 
                  ScreenSourceFlags.IGNORE_MINIMIZED
)

# Get all sources including system windows
all_sources = enum_screen_sources(
    external_flags=ScreenSourceFlags.NOT_SKIP_SYSTEM_WINDOWS | 
                  ScreenSourceFlags.NOT_IGNORE_TOOLWINDOW
)

Examples

See the examples directory for more detailed examples:

  • basic_usage.py: Demonstrates basic screen capture functionality

    • Enumerating screen sources
    • Selecting a source interactively
    • Capturing and saving screenshots
  • enum_sources.py: Shows advanced source enumeration with filtering

    • Using different flag combinations
    • Getting thumbnails and icons
    • Displaying detailed source information
    • Filtering sources by type and state

Requirements

  • Python 3.7+
  • Pillow (PIL) for image handling
  • NumPy for array operations

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

traa-0.1.4-cp310-cp310-win_arm64.whl (634.1 kB view details)

Uploaded CPython 3.10Windows ARM64

traa-0.1.4-cp310-cp310-win_amd64.whl (634.1 kB view details)

Uploaded CPython 3.10Windows x86-64

traa-0.1.4-cp310-cp310-win32.whl (508.5 kB view details)

Uploaded CPython 3.10Windows x86

traa-0.1.4-cp310-cp310-manylinux2014_x86_64.whl (202.3 kB view details)

Uploaded CPython 3.10

traa-0.1.4-cp310-cp310-manylinux2014_aarch64.whl (202.3 kB view details)

Uploaded CPython 3.10

traa-0.1.4-cp310-cp310-macosx_11_0_arm64.whl (260.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

traa-0.1.4-cp310-cp310-macosx_10_9_x86_64.whl (260.8 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file traa-0.1.4-cp310-cp310-win_arm64.whl.

File metadata

  • Download URL: traa-0.1.4-cp310-cp310-win_arm64.whl
  • Upload date:
  • Size: 634.1 kB
  • Tags: CPython 3.10, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for traa-0.1.4-cp310-cp310-win_arm64.whl
Algorithm Hash digest
SHA256 36b7c7111159b5f0d62b38ef876eba2af45fc4853f3c67818cd5b80d0a413f6f
MD5 9aa6bbc85c51925fe73c8977833bd021
BLAKE2b-256 91d18db4635b8d90284957a49417dbc946b5b41de88508911e590a035616512c

See more details on using hashes here.

File details

Details for the file traa-0.1.4-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: traa-0.1.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 634.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for traa-0.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3c0ea6af50e45bd444d89281a4ff0009401d3c6ac4b1d86a5d87caf733a1e2fc
MD5 11618301f05de3411f6e8652e07eae4f
BLAKE2b-256 d0c348ea534e4dd53e07975e9c0dcad6719b85ead566934be36e1b4d2aad7c5b

See more details on using hashes here.

File details

Details for the file traa-0.1.4-cp310-cp310-win32.whl.

File metadata

  • Download URL: traa-0.1.4-cp310-cp310-win32.whl
  • Upload date:
  • Size: 508.5 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for traa-0.1.4-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 b07213bef1138b6e7a09c9cf1cfa60aba200f1e35ae9196c018fb890ea9acdbc
MD5 6933b10f40d29b372ee1cb0d1f020033
BLAKE2b-256 0746b077a122f5cda787bbd3b4ba4139251aaab2de8a73039930f2cc9dc19371

See more details on using hashes here.

File details

Details for the file traa-0.1.4-cp310-cp310-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for traa-0.1.4-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 46b941bacb7b49688bf63c38e1e24db4240aa09614abfa3805e15c938ac9eebb
MD5 c5e26a33b02841a892a3833ac347ebe3
BLAKE2b-256 a53e5e37a72ea8a1a59a04ff9b5b01f7c184ca80362552891e0c5bd5c8d92839

See more details on using hashes here.

File details

Details for the file traa-0.1.4-cp310-cp310-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for traa-0.1.4-cp310-cp310-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7b8bf367ffc28ece7c98db54efa9e7691f4e7c8e904fee437a378dd9452e532c
MD5 52890b8d9e2515b45fb8ef1a89b8bfe5
BLAKE2b-256 ebb557426740b614963686399579b6f9d5fc53c3f4224c58c79267bbd4befe00

See more details on using hashes here.

File details

Details for the file traa-0.1.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for traa-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b3e22e14296a3aa3f30a54c00533c32341bbe0ff594737a0b32549a851b70722
MD5 b884103326e753ffa4f671256ca2a344
BLAKE2b-256 835ba0db0f82908fd1435690e502bd1ac7aebd2673285d91806f9e5bdcfaf7b6

See more details on using hashes here.

File details

Details for the file traa-0.1.4-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for traa-0.1.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 996abed76c8326263630595758abb9c2d74076852785c571683a54fd0297ee9a
MD5 b7b68c76f10487466e316f90e3a1dcd8
BLAKE2b-256 6a4157028945e3fa0d73f4a741022169a50c34921ccc393a7d63410986be8926

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page