xvfbwrapper
Manage headless displays with Xvfb (X virtual framebuffer)
About
xvfbwrapper is a Python library for managing X11 virtual displays
with Xvfb (X virtual framebuffer), a virtual X server that runs
without a physical display. It provides the Xvfb class, a Python interface for
configuring and controlling the Xvfb program.
See the module API documentation for more information.
- Copyright (c) 2012-2026 Corey Goldberg
- Development: GitHub
- Releases: PyPI
- License: MIT
Status
| Latest Version |
|
| Tests (CI) |
|
| API Docs (CI) |
|
| Supported Python Versions |
|
What is Xvfb?
Xvfb (X virtual framebuffer) is a display server implementing the X11 display
server protocol. It runs in memory and does not require a physical display or
input device. Only a network layer is necessary.
Xvfb allows GUI applications that use X Windows to run on a headless system.
Installation
Official releases are published on PyPI:
pip install xvfbwrapper
System Requirements
- Python 3.11+
- X Window System
- Xvfb (
sudo apt install xvfb,sudo dnf install xorg-x11-server-Xvfb, etc) - Support for file locking using
fcntl(POSIX systems)
Usage
Always ensure that the virtual display is stopped, even if an exception occurs.
Xvfb can be used as a context manager or managed explicitly with
try/finally.
Context Manager
from xvfbwrapper import Xvfb
with Xvfb():
# Runs inside the virtual display
main()
The virtual display is automatically stopped when the context exits, including if an exception occurs.
Explicit Lifecycle Management
from xvfbwrapper import Xvfb
xvfb = Xvfb()
xvfb.start()
try:
# Runs inside the virtual display
main()
finally:
xvfb.stop()
Specifying Display Geometry
from xvfbwrapper import Xvfb
xvfb = Xvfb(width=1280, height=720)
xvfb.start()
Setting XDG_SESSION_TYPE
When running Xvfb in a Wayland session, GUI toolkits may try to use the
Wayland backend instead of connecting to Xvfb. Setting
set_xdg_session_type=True forces XDG_SESSION_TYPE=x11 in the Python process
and all child processes, ensuring that GUI apps use the X11 backend and can
render on the virtual display.
from xvfbwrapper import Xvfb
xvfb = Xvfb(set_xdg_session_type=True)
xvfb.start()
Specifying Other Xvfb Options
The Xvfb executable accepts several types of command line arguments.
The most common is an argument with a - prefix and a parameter (i.e.
-nolisten tcp). These can be added as keyword arguments when creating an
xvfbwrapper.Xvfb instance. For example:
from xvfbwrapper import Xvfb
xvfb = Xvfb(nolisten="tcp")
# Xvfb will be called with the `-nolisten tcp` argument
xvfb.start()
There are other possible types of arguments:
- unary argument (i.e.
ttyxx) - unary argument with a
+prefix (i.e.+xinerama) - unary argument with a
-prefix (i.e.-nocursor) - argument with a parameter (i.e.
c 100) - argument with a
+prefix and a parameter (i.e.+extension RANDR)
Any type of argument can be added as an extra_args sequence when creating an
xvfbwrapper.Xvfb instance. For example:
from xvfbwrapper import Xvfb
xvfb = Xvfb(extra_args=("ttyxx", "-nocursor", "+extension", "RANDR"))
# Xvfb will be called with the `ttyxx -nocursor +extension RANDR` arguments
xvfb.start()
Running Multiple Displays
When running multiple Xvfb instances concurrently, each instance should have its
own environment dictionary to avoid conflicts. Pass a separate copy of
os.environ to each instance using the environ argument.
Use os.environ.copy() rather than passing os.environ directly. This ensures
each instance has its own environment dictionary.
import os
from xvfbwrapper import Xvfb
xvfb1 = Xvfb(environ=os.environ.copy())
xvfb2 = Xvfb(environ=os.environ.copy())
xvfb1.start()
xvfb2.start()
try:
# Use each Xvfb instance independently
...
finally:
xvfb1.stop()
xvfb2.stop()
Examples
Headless Browser Testing With unittest
The following example uses selenium and xvfbwrapper to run
Chrome tests inside a virtual display.
import unittest
from selenium import webdriver
from xvfbwrapper import Xvfb
class TestPage(unittest.TestCase):
def setUp(self):
xvfb = Xvfb(set_xdg_session_type=True)
xvfb.start()
self.addCleanup(xvfb.stop)
self.driver = webdriver.Chrome()
self.addCleanup(self.driver.quit)
def test_selenium_homepage(self):
self.driver.get("https://www.selenium.dev")
self.assertIn("Selenium", self.driver.title)
Headless Browser Testing With pytest
The same setup can be used with pytest by managing the virtual display and
browser through a fixture.
import pytest
from selenium import webdriver
from xvfbwrapper import Xvfb
@pytest.fixture
def driver():
with Xvfb(set_xdg_session_type=True):
driver = webdriver.Chrome()
yield driver
driver.quit()
def test_selenium_homepage(driver):
driver.get("https://www.selenium.dev")
assert "Selenium" in driver.title
Metadata
Release files for xvfbwrapper 0.2.38
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xvfbwrapper-0.2.38.tar.gz | 13.3 kB | With provenance | Details for xvfbwrapper-0.2.38.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xvfbwrapper-0.2.38-py3-none-any.whl | Python 3 | none | any | Details for xvfbwrapper-0.2.38-py3-none-any.whl |
Total release size: 20.7 kB
Release files / xvfbwrapper-0.2.38.tar.gz
| Download URL | xvfbwrapper-0.2.38.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef0cffe656cb48f63293fec07ea8ad3feb199283f16b33acc5f3195765c2db74
|
|
BLAKE2b-256 checksum How to use checksums |
3dc87977b40fa6dd47bdbe608d4f1fc1848bfbda176e83cc607a8e6a47c336ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / xvfbwrapper-0.2.38-py3-none-any.whl
| Download URL | xvfbwrapper-0.2.38-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d51d726ff8f534445878003e319dc19656ec8d7874294ef046e5e5d101161b37
|
|
BLAKE2b-256 checksum How to use checksums |
ea707f2f3a67bcaff62efe695ba78841674c2d401a28417f0e41cd15389b415b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logSecurity for xvfbwrapper 0.2.38
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for xvfbwrapper-0.2.38.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logA 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.