Thursday, 29 September 2016

Most interesting modules for Python 2016

Python is often compared to other interpreted languages such as Java, JavaScript, Perl, Tcl, or Smalltalk.Comparisons to C++, Common Lisp and Scheme can also be enlightening.Python has a relative small quantity of lines of code, which makes it less prone to issues, easier to debug, and more maintainable.It is used in a wide industries and for a long list of different usages from websites and web applications to systems administration and desktop apps. It is the ideal language for the beginners and its simple and straight-forward syntax also encourages good programming habits, especially through its focus on white space indentation, which contributes to the development of neat looking code.

Python Modules

In this article i'm going to show some useful python libraries and i won't give a brief introduction of these libarary because it would blow-up the boundaries and for this article also.

mypy : Mypy is an experimental optional static type checker for Python and its aims to combine the benefits of dynamic typing and static typing. It combines the expressive power and convenience of Python with a powerful type system and compile time type checking. Mypy type checks standard Python programs run them using any Python VM with basically no runtime overhead.


def fib(n):
    a, b = 0, 1
    while a < n:
        yield a
        a, b = b, a+b

statically typed Python:

def fib(n: int) -> Iterator[int]:
    a, b = 0, 1
    while a < n:
        yield a
        a, b = b, a+b

matplotlib : If you want to show some graph experiance to your user than Matplotlib for you.Matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. matplotlib can be used in python scripts.

import matplotlib.pyplot as plt

author__ = 'GHajba'

x_axis = [x for x in range(-3,4)]
y_axis = [x * x for x in x_axis]

plt.plot(x_axis, y_axis)

Requests :  The most famous http library written by kenneth reitz. It’s a must have for every python developer.

r = requests.get('')

Scrapy : An open source and collaborative framework for extracting the data you need from websites.
In a fast, simple, yet extensible way.If you are intrested in webscraping then this is a must have library for you. After using this library you won’t use any other.

pip install scrapy
 cat > <<EOF

import scrapy

class BlogSpider(scrapy.Spider):
    name = 'blogspider'
    start_urls = ['']

    def parse(self, response):
        for title in response.css('h2.entry-title'):
            yield {'title': title.css('a ::text').extract_first()}

        next_page = response.css('div.prev-post > a ::attr(href)').extract_first()
        if next_page:
            yield scrapy.Request(response.urljoin(next_page), callback=self.parse)
 scrapy runspider

wxPython : A gui toolkit for python. I have primarily used it in place of tkinter. You will really love it.

Pygame : Which developer does not like to play games and develop them ? This library will help you achieve your goal of 2d game development.

nose:  A testing framework for python. It is used by millions of python developers. It is a must have if you do test driven development.

Pyglet : A 3d animation and game creation engine. This is the engine in which the famous python port of minecraft was made.

PeeWee :  It is an ORM (ORM) framework which comes in handy if you have an application where you have to fill data from objects (from class representations) to a relational database and vice versa.

import peewee

__author__ = 'GHajba'

db = peewee.SqliteDatabase('my_app.db')

class Book(peewee.Model):
    author = peewee.CharField()
    title = peewee.TextField()

    class Meta:
        database = db

if __name__ == '__main__':
    book = Book(author='Gabor Laszlo Hajba', title='Python 3 in Anger')
    for book in Book.filter(author="Gabor Laszlo Hajba"):

db = peewee.SqliteDatabase('my_app.db') 

In above example we create database table fill with data and extract the content.

I hope you liked this article. share your views in the comments below. Stay tuned for the next post.

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts