DEV Community

schnipdip
schnipdip

Posted on • Updated on

Python: Subprocess or Paramiko?

Has anyone done a performance test on either of these for SSH? From what I have read, subprocess seems to perform better

Top comments (2)

Collapse
 
iblancasa profile image
Israel Blancas

I think you want to compare the use of subprocess calling the ssh command, right? In that case, the performance degradation makes all the sense. Why? If you go to the official Paramiko's website it says:

Paramiko is a Python (2.7, 3.4+) implementation of the SSHv2 protocol [1], providing both client and server functionality. While it leverages a Python C extension for low level cryptography (Cryptography), Paramiko itself is a pure Python interface around SSH networking concepts.

So, it means Paramiko is implemented in pure Python and ssh in pure C. So, ssh performance will be better than the one in Paramiko.

But, why should I use Paramiko? Because Paramiko:

  • Provides you will all the methods to interact with your ssh/sftp/... session:
  • You can get the errors without needing to parse the commandline output or to check the exit code

We can say it is more... Python friendly :).

Collapse
 
schnipdip profile image
schnipdip

Yeah I was thinking about the sftp since I need to push a file. I'd have to implement both, which would require more resources. Subprocess I think is better for ssh strictly speaking.