DEV Community

schnipdip
schnipdip

Posted on • Edited on

2

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.

Sentry image

Make it make sense

Only the context you need to fix your broken code with Sentry.

Start debugging →

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay