
Python's xdo module lets you programmatically simulate keyboard input and mouse activity, move and resize windows, etc. It does this using libxdo, which uses X11's XTEST extension and other Xlib functions.
This is the Python 3 version of this package.