from ewmh import EWMH
import random
ewmh = EWMH()
wins = ewmh.getClientList()
ewmh.setActiveWindow(random.choice(wins))
ewmh.display.flush()
X11 - How to raise another application's window using Python