Simplest answer is to open a port forwarding to the remote server.
This works best in bash, but you can subprocess, or whatever you prefer to run it through python.
Suppose the IPs are:
- jumpserver IP is 151.121.121.121
- finalserver IP is 10.1.2.3
Like follows
# Open a local port 13000 that will map through jumpserver and
# connect to finalserver on port 22
ssh -L 13000:10.1.2.3:22 username@151.121.121.121
# Then open an ssh session to localhost:13000 (which will forward to the
# finalserver.com and run your command)
ssh username@localhost -p 13000 'rpm -qa | grep package'
Aside: looking at your expect script and remembering the old days. Python has some ssh wrappers. Paramiko is used with Fabric.