Xvfbwrapper

0.2.23 · active · verified Mon Apr 13

xvfbwrapper is a Python library for controlling X11 virtual displays with Xvfb (X virtual framebuffer). Xvfb is a display server implementing the X11 protocol that runs entirely in memory, without requiring a physical screen or input devices. This enables GUI applications designed for X Windows to execute on headless systems, which is particularly useful for automated testing. The current version is 0.2.23, and it is actively maintained.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the recommended way to use `xvfbwrapper` with a context manager. It automatically starts and stops the Xvfb display, ensuring proper cleanup. The `DISPLAY` environment variable is set for child processes within the `with` block. Note that the system-level `Xvfb` package must be installed first.

import os
from xvfbwrapper import Xvfb

# Ensure Xvfb is available on your system (e.g., sudo apt-get install xvfb)

# Using Xvfb as a context manager is recommended for safe cleanup
with Xvfb(width=1280, height=720, colordepth=24):
    print("Xvfb virtual display started.")
    print(f"DISPLAY environment variable is: {os.environ.get('DISPLAY')}")
    # Your application that needs a display runs here
    # Example: launch a headless browser or GUI application
    # The display will be stopped automatically when exiting the 'with' block
    print("Application finished, Xvfb will stop.")

print("Xvfb virtual display stopped.")

view raw JSON →