Screeninfo
Screeninfo is a Python library designed to fetch the location and size of physical screens connected to a system. It supports various operating systems including MS Windows, MS Windows (Cygwin), GNU/Linux (via X11 with Xinerama and experimental DRM), and macOS (using AppKit). The current version is 0.8.1, released in September 2022, and while no explicit release cadence is stated, it remains actively maintained.
Warnings
- gotcha Users, especially on macOS or certain Linux desktop environments (like Wayland), may encounter `screeninfo.common.ScreenInfoError: No enumerators available`. This indicates the library could not detect a compatible display backend.
- gotcha The maintainer explicitly states that they do not personally test on OSX or other environments, encouraging pull requests for these platforms. This may lead to slower support or platform-specific quirks being less promptly addressed.
- gotcha Some users have reported `UnicodeDecodeError` during installation on certain Linux distributions (e.g., Arch Linux) when using poetry, potentially related to locale settings or poetry's deprecated `dev-dependencies` section.
Install
-
pip install screeninfo
Imports
- get_monitors
from screeninfo import get_monitors
- get_primary_monitor
from screeninfo import get_primary_monitor
- Enumerator
from screeninfo import get_monitors, Enumerator
- Monitor
from screeninfo.common import Monitor
Quickstart
from screeninfo import get_monitors, get_primary_monitor
print("Detected monitors:")
for m in get_monitors():
print(f" Monitor(x={m.x}, y={m.y}, width={m.width}, height={m.height}, is_primary={m.is_primary}, name={m.name})")
primary = get_primary_monitor()
if primary:
print(f"\nPrimary monitor: Monitor(x={primary.x}, y={primary.y}, width={primary.width}, height={primary.height}, name={primary.name})")
else:
print("\nNo primary monitor detected.")