Python packages – I have worked with so far

    I am acquainted with Python for almost 2 years now. First I worked with around 2013 if I am not mistaken. It was the client requirement that time to use Python. So we started from zero, learned it and delivered the testing framework to the client. Client’s response was satisfactory. But after that there was pause until someone else suggested me to try Python for few of my automation.

    That “someone” was my development manager here, it was brief timeline that I spend with him before he moved, but within that brief time frame he changed my perspective towards to the automation. From that time I started automating things in all possible way. It’s not only UI automation. I have developed different frameworks for my current organization.

    I built one REST API Testing framework (actually cloned from https://github.com/chitamoor/Rester). I build another framework which I named PyRabbit, to help us to test each of our microservices. There is another recently I finished development is called “LocalDeployer”. Purpose of this project is to allow download artifacts from our Bamboo CI and deploy microservices with a single command.

    There are few other projects I have been working with which are out context of this article :).  But, what I want to share is the packages I have used so far while I was/am working with so many versatile projects. The packages I have used so far are as follows:

    Requests

    Title of the doc is “Requests: HTTP for humans”, which is kind of correct. If you ever want to deal with http communication including POST, GET etc and different types of authentication, then should check out this package. Requests API is easy to use. Dig down further details at http://docs.python-requests.org/en/master/.
    Note: if you ever wonder how to do OAuth2 authentication using requests, then please checkout https://requests-oauthlib.readthedocs.io/en/latest/.

    PIKA

    It’s a python implementation for AMQP (Advance Message Queuing Protocol). From the doc and I quote:

    Pika is a pure-Python implementation of the AMQP 0-9-1 protocol that tries to stay fairly independent of the underlying network support library.

    If you want to inject data to RabbitMQ, or want to implement consumer and subscriber for your back-end RabbitMQ then using PIKA would be the perfect choice. It’s fairly simple API saves lots effort. Also nice tutorial can be found in RabbitMQ Tutorial section as well.

    Paramiko

    Again it’s better to quote from the official site:

    Paramiko is a Python (2.6+, 3.3+) implementation of the SSHv2 protocol [1], providing both client and server functionality. 

    So it’s all about SSH. If you want establish the SSH tunneling then it’s definitely what you are looking for.  Please checkout detail at http://www.paramiko.org/.

    Psycopg2

    This is an awesome library to play with your Postgres database. For one of my projects, I needed to work with our database which is in Postgres from Python. Then I found it and it’s actually very easy to use. Official documentation: http://initd.org/psycopg/
    Sample code to create database from python using  Psycopg2 would be as below:

    from psycopg2 import connect
    from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT

    con = connect(database="postgres", user=username, password=password, host=dbhost, port="5432")
    con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
    cur = con.cursor()
    cur.execute("CREATE DATABASE " + dbname)
    cur.close()
    con.close()
    
    
    
    

    subprocess

    This is a python library which allows you to connect to process pool, trigger process, get output from the process, pipe to other process and so many other things to with processes. In one of my projects I needed to trigger java in remote over SSH. I did it with help of paramiko and subprocess. Check out detail of this awesome library in https://docs.python.org/3.6/library/subprocess.html

    python-datemath

    So, one of the test engineers from our testing team approached me with a requirement for our api testing tool. She asked for a feature to do the date arithmetic, For example, adding 1 day to current date or deducting 3 days from current date. 
    Doing it using timdelta or python date time library would have been bit complicated. But python-datemath actually saved me from lots of hassle! Github doc actually described the usage quite nicely to start with.
    Apart from those, I have worked with other libraries as well, namely json, re, psutiltraceback,simpleeval and few others. I am still learning and exploring new libraries, because I am focusing on Python nowadays and I am enjoying it. Probably in future will discuss about new packages.

    Leave a Reply

    Your email address will not be published. Required fields are marked *