0% found this document useful (0 votes)
271 views45 pages

MC4103 Python Programming - Unit-Iv

MC4103 PYTHON PROGRAMMING UNIT-IV

Uploaded by

Rathnakumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
271 views45 pages

MC4103 Python Programming - Unit-Iv

MC4103 PYTHON PROGRAMMING UNIT-IV

Uploaded by

Rathnakumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 45

UNIT IV MODULES, PACKAGES AND FRAMEWORKS 10

Modules: Introduction – Module Loading and Execution – Packages – Making Your Own
Module – The Python Libraries for data processing, data mining and visualization- NUMPY,
Pandas, Matplotlib, Plotly-Frameworks- -Django, Flask, Web2Py
Modules

If you quit from the Python interpreter and enter it again, the definitions you have made
(functions and variables) are lost. Therefore, if you want to write a somewhat longer program,
you are better off using a text editor to prepare the input for the interpreter and running it with
that file as input instead. This is known as creating a script. As your program gets longer, you
may want to split it into several files for easier maintenance. You may also want to use a handy
function that you’ve written in several programs without copying its definition into each
program.

To support this, Python has a way to put definitions in a file and use them in a script or in an
interactive instance of the interpreter. Such a file is called a module; definitions from a module
can be imported into other modules or into the main module (the collection of variables that you
have access to in a script executed at the top level and in calculator mode).

A module is a file containing Python definitions and statements. The file name is the module
name with the suffix .py appended. Within a module, the module’s name (as a string) is available
as the value of the global variable __name__. For instance, use your favorite text editor to create
a file called fibo.py in the current directory with the following contents:

# Fibonacci numbers module

def fib(n): # write Fibonacci series up to n


a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()

def fib2(n): # return Fibonacci series up to n


result = []
a, b = 0, 1
while a < n:
result.append(a)
a, b = b, a+b
return result

Now enter the Python interpreter and import this module with the following command:

>>>
>>> import fibo

This does not enter the names of the functions defined in fibo directly in the current symbol
table; it only enters the module name fibo there. Using the module name you can access the
functions:
>>>
>>> fibo.fib(1000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
>>> fibo.fib2(100)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
>>> fibo.__name__
'fibo'

If you intend to use a function often you can assign it to a local name:

>>>
>>> fib = fibo.fib
>>> fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

6.1. More on Modules

A module can contain executable statements as well as function definitions. These statements are
intended to initialize the module. They are executed only the first time the module name is
encountered in an import statement. 1 (They are also run if the file is executed as a script.)

Each module has its own private symbol table, which is used as the global symbol table by all
functions defined in the module. Thus, the author of a module can use global variables in the
module without worrying about accidental clashes with a user’s global variables. On the other
hand, if you know what you are doing you can touch a module’s global variables with the same
notation used to refer to its functions, modname.itemname.

Modules can import other modules. It is customary but not required to place all import
statements at the beginning of a module (or script, for that matter). The imported module names
are placed in the importing module’s global symbol table.

There is a variant of the import statement that imports names from a module directly into the
importing module’s symbol table. For example:

>>>
>>> from fibo import fib, fib2
>>> fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

This does not introduce the module name from which the imports are taken in the local symbol
table (so in the example, fibo is not defined).

There is even a variant to import all names that a module defines:

>>>
>>> from fibo import *
>>> fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

This imports all names except those beginning with an underscore (_). In most cases Python
programmers do not use this facility since it introduces an unknown set of names into the
interpreter, possibly hiding some things you have already defined.

Note that in general the practice of importing * from a module or package is frowned upon, since
it often causes poorly readable code. However, it is okay to use it to save typing in interactive
sessions.

If the module name is followed by as, then the name following as is bound directly to the
imported module.

>>>
>>> import fibo as fib
>>> fib.fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

This is effectively importing the module in the same way that import fibo will do, with the only
difference of it being available as fib.

It can also be used when utilising from with similar effects:

>>>
>>> from fibo import fib as fibonacci
>>> fibonacci(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

Note

For efficiency reasons, each module is only imported once per interpreter session. Therefore, if
you change your modules, you must restart the interpreter – or, if it’s just one module you want
to test interactively, use importlib.reload(), e.g. import importlib; importlib.reload(modulename).

6.1.1. Executing modules as scripts

When you run a Python module with

python fibo.py <arguments>

the code in the module will be executed, just as if you imported it, but with the __name__ set to
"__main__". That means that by adding this code at the end of your module:

if __name__ == "__main__":
import sys
fib(int(sys.argv[1]))

you can make the file usable as a script as well as an importable module, because the code that
parses the command line only runs if the module is executed as the “main” file:

$ python fibo.py 50
0 1 1 2 3 5 8 13 21 34

If the module is imported, the code is not run:

>>>
>>> import fibo
>>>

This is often used either to provide a convenient user interface to a module, or for testing
purposes (running the module as a script executes a test suite).

6.1.2. The Module Search Path

When a module named spam is imported, the interpreter first searches for a built-in module with
that name. If not found, it then searches for a file named spam.py in a list of directories given by
the variable sys.path. sys.path is initialized from these locations:

 The directory containing the input script (or the current directory when no file is
specified).
 PYTHONPATH (a list of directory names, with the same syntax as the shell variable
PATH).
 The installation-dependent default (by convention including a site-packages directory,
handled by the site module).

Note

On file systems which support symlinks, the directory containing the input script is calculated
after the symlink is followed. In other words the directory containing the symlink is not added to
the module search path.

After initialization, Python programs can modify sys.path. The directory containing the script
being run is placed at the beginning of the search path, ahead of the standard library path. This
means that scripts in that directory will be loaded instead of modules of the same name in the
library directory. This is an error unless the replacement is intended. See section Standard
Modules for more information.

6.1.3. “Compiled” Python files

To speed up loading modules, Python caches the compiled version of each module in the
__pycache__ directory under the name module.version.pyc, where the version encodes the
format of the compiled file; it generally contains the Python version number. For example, in
CPython release 3.3 the compiled version of spam.py would be cached as
__pycache__/spam.cpython-33.pyc. This naming convention allows compiled modules from
different releases and different versions of Python to coexist.

Python checks the modification date of the source against the compiled version to see if it’s out
of date and needs to be recompiled. This is a completely automatic process. Also, the compiled
modules are platform-independent, so the same library can be shared among systems with
different architectures.

Python does not check the cache in two circumstances. First, it always recompiles and does not
store the result for the module that’s loaded directly from the command line. Second, it does not
check the cache if there is no source module. To support a non-source (compiled only)
distribution, the compiled module must be in the source directory, and there must not be a source
module.

Some tips for experts:

 You can use the -O or -OO switches on the Python command to reduce the size of a
compiled module. The -O switch removes assert statements, the -OO switch removes
both assert statements and __doc__ strings. Since some programs may rely on having
these available, you should only use this option if you know what you’re doing.
“Optimized” modules have an opt- tag and are usually smaller. Future releases may
change the effects of optimization.
 A program doesn’t run any faster when it is read from a .pyc file than when it is read
from a .py file; the only thing that’s faster about .pyc files is the speed with which they
are loaded.
 The module compileall can create .pyc files for all modules in a directory.
 There is more detail on this process, including a flow chart of the decisions, in PEP 3147.

6.2. Standard Modules

Python comes with a library of standard modules, described in a separate document, the Python
Library Reference (“Library Reference” hereafter). Some modules are built into the interpreter;
these provide access to operations that are not part of the core of the language but are
nevertheless built in, either for efficiency or to provide access to operating system primitives
such as system calls. The set of such modules is a configuration option which also depends on
the underlying platform. For example, the winreg module is only provided on Windows systems.
One particular module deserves some attention: sys, which is built into every Python interpreter.
The variables sys.ps1 and sys.ps2 define the strings used as primary and secondary prompts:

>>>
>>> import sys
>>> sys.ps1
'>>> '
>>> sys.ps2
'... '
>>> sys.ps1 = 'C> '
C> print('Yuck!')
Yuck!
C>

These two variables are only defined if the interpreter is in interactive mode.

The variable sys.path is a list of strings that determines the interpreter’s search path for modules.
It is initialized to a default path taken from the environment variable PYTHONPATH, or from a
built-in default if PYTHONPATH is not set. You can modify it using standard list operations:

>>>
>>> import sys
>>> sys.path.append('/ufs/guido/lib/python')

6.3. The dir() Function

The built-in function dir() is used to find out which names a module defines. It returns a sorted
list of strings:

>>>
>>> import fibo, sys
>>> dir(fibo)
['__name__', 'fib', 'fib2']
>>> dir(sys)
['__breakpointhook__', '__displayhook__', '__doc__', '__excepthook__',
'__interactivehook__', '__loader__', '__name__', '__package__', '__spec__',
'__stderr__', '__stdin__', '__stdout__', '__unraisablehook__',
'_clear_type_cache', '_current_frames', '_debugmallocstats', '_framework',
'_getframe', '_git', '_home', '_xoptions', 'abiflags', 'addaudithook',
'api_version', 'argv', 'audit', 'base_exec_prefix', 'base_prefix',
'breakpointhook', 'builtin_module_names', 'byteorder', 'call_tracing',
'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_info',
'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info',
'float_repr_style', 'get_asyncgen_hooks', 'get_coroutine_origin_tracking_depth',
'getallocatedblocks', 'getdefaultencoding', 'getdlopenflags',
'getfilesystemencodeerrors', 'getfilesystemencoding', 'getprofile',
'getrecursionlimit', 'getrefcount', 'getsizeof', 'getswitchinterval',
'gettrace', 'hash_info', 'hexversion', 'implementation', 'int_info',
'intern', 'is_finalizing', 'last_traceback', 'last_type', 'last_value',
'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks',
'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'pycache_prefix',
'set_asyncgen_hooks', 'set_coroutine_origin_tracking_depth', 'setdlopenflags',
'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr',
'stdin', 'stdout', 'thread_info', 'unraisablehook', 'version', 'version_info',
'warnoptions']

Without arguments, dir() lists the names you have defined currently:

>>>
>>> a = [1, 2, 3, 4, 5]
>>> import fibo
>>> fib = fibo.fib
>>> dir()
['__builtins__', '__name__', 'a', 'fib', 'fibo', 'sys']

Note that it lists all types of names: variables, modules, functions, etc.

dir() does not list the names of built-in functions and variables. If you want a list of those, they
are defined in the standard module builtins:

>>>
>>> import builtins
>>> dir(builtins)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException',
'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning',
'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError',
'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning',
'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False',
'FileExistsError', 'FileNotFoundError', 'FloatingPointError',
'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError',
'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError',
'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError',
'MemoryError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented',
'NotImplementedError', 'OSError', 'OverflowError',
'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError',
'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning',
'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError',
'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError',
'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError',
'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning',
'ValueError', 'Warning', 'ZeroDivisionError', '_', '__build_class__',
'__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs',
'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable',
'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits',
'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit',
'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr',
'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass',
'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview',
'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property',
'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice',
'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars',
'zip']

6.4. Packages

Packages are a way of structuring Python’s module namespace by using “dotted module names”.
For example, the module name A.B designates a submodule named B in a package named A.
Just like the use of modules saves the authors of different modules from having to worry about
each other’s global variable names, the use of dotted module names saves the authors of multi-
module packages like NumPy or Pillow from having to worry about each other’s module names.

Suppose you want to design a collection of modules (a “package”) for the uniform handling of
sound files and sound data. There are many different sound file formats (usually recognized by
their extension, for example: .wav, .aiff, .au), so you may need to create and maintain a growing
collection of modules for the conversion between the various file formats. There are also many
different operations you might want to perform on sound data (such as mixing, adding echo,
applying an equalizer function, creating an artificial stereo effect), so in addition you will be
writing a never-ending stream of modules to perform these operations. Here’s a possible
structure for your package (expressed in terms of a hierarchical filesystem):

sound/ Top-level package


__init__.py Initialize the sound package
formats/ Subpackage for file format conversions
__init__.py
wavread.py
wavwrite.py
aiffread.py
aiffwrite.py
auread.py
auwrite.py
...
effects/ Subpackage for sound effects
__init__.py
echo.py
surround.py
reverse.py
...
filters/ Subpackage for filters
__init__.py
equalizer.py
vocoder.py
karaoke.py
...

When importing the package, Python searches through the directories on sys.path looking for the
package subdirectory.
The __init__.py files are required to make Python treat directories containing the file as
packages. This prevents directories with a common name, such as string, unintentionally hiding
valid modules that occur later on the module search path. In the simplest case, __init__.py can
just be an empty file, but it can also execute initialization code for the package or set the __all__
variable, described later.

Users of the package can import individual modules from the package, for example:

import sound.effects.echo

This loads the submodule sound.effects.echo. It must be referenced with its full name.

sound.effects.echo.echofilter(input, output, delay=0.7, atten=4)

An alternative way of importing the submodule is:

from sound.effects import echo

This also loads the submodule echo, and makes it available without its package prefix, so it can
be used as follows:

echo.echofilter(input, output, delay=0.7, atten=4)

Yet another variation is to import the desired function or variable directly:

from sound.effects.echo import echofilter

Again, this loads the submodule echo, but this makes its function echofilter() directly available:

echofilter(input, output, delay=0.7, atten=4)

Note that when using from package import item, the item can be either a submodule (or
subpackage) of the package, or some other name defined in the package, like a function, class or
variable. The import statement first tests whether the item is defined in the package; if not, it
assumes it is a module and attempts to load it. If it fails to find it, an ImportError exception is
raised.

Contrarily, when using syntax like import item.subitem.subsubitem, each item except for the last
must be a package; the last item can be a module or a package but can’t be a class or function or
variable defined in the previous item.

6.4.1. Importing * From a Package

Now what happens when the user writes from sound.effects import *? Ideally, one would hope
that this somehow goes out to the filesystem, finds which submodules are present in the package,
and imports them all. This could take a long time and importing sub-modules might have
unwanted side-effects that should only happen when the sub-module is explicitly imported.

The only solution is for the package author to provide an explicit index of the package. The
import statement uses the following convention: if a package’s __init__.py code defines a list
named __all__, it is taken to be the list of module names that should be imported when from
package import * is encountered. It is up to the package author to keep this list up-to-date when a
new version of the package is released. Package authors may also decide not to support it, if they
don’t see a use for importing * from their package. For example, the file
sound/effects/__init__.py could contain the following code:

__all__ = ["echo", "surround", "reverse"]

This would mean that from sound.effects import * would import the three named submodules of
the sound package.

If __all__ is not defined, the statement from sound.effects import * does not import all
submodules from the package sound.effects into the current namespace; it only ensures that the
package sound.effects has been imported (possibly running any initialization code in
__init__.py) and then imports whatever names are defined in the package. This includes any
names defined (and submodules explicitly loaded) by __init__.py. It also includes any
submodules of the package that were explicitly loaded by previous import statements. Consider
this code:

import sound.effects.echo
import sound.effects.surround
from sound.effects import *

In this example, the echo and surround modules are imported in the current namespace because
they are defined in the sound.effects package when the from...import statement is executed. (This
also works when __all__ is defined.)

Although certain modules are designed to export only names that follow certain patterns when
you use import *, it is still considered bad practice in production code.

Remember, there is nothing wrong with using from package import specific_submodule! In fact,
this is the recommended notation unless the importing module needs to use submodules with the
same name from different packages.

6.4.2. Intra-package References

When packages are structured into subpackages (as with the sound package in the example), you
can use absolute imports to refer to submodules of siblings packages. For example, if the module
sound.filters.vocoder needs to use the echo module in the sound.effects package, it can use from
sound.effects import echo.
You can also write relative imports, with the from module import name form of import
statement. These imports use leading dots to indicate the current and parent packages involved in
the relative import. From the surround module for example, you might use:

from . import echo


from .. import formats
from ..filters import equalizer

Note that relative imports are based on the name of the current module. Since the name of the
main module is always "__main__", modules intended for use as the main module of a Python
application must always use absolute imports.

6.4.3. Packages in Multiple Directories

Packages support one more special attribute, __path__. This is initialized to be a list containing
the name of the directory holding the package’s __init__.py before the code in that file is
executed. This variable can be modified; doing so affects future searches for modules and
subpackages contained in the package.

While this feature is not often needed, it can be used to extend the set of modules found in a
package.
Packages in Python

A package is a hierarchical file directory structure that defines a single Python application
environment that consists of modules and subpackages and sub-subpackages, and so on.

Consider a file Pots.py available in Phone directory. This file has following line of source code −

#!/usr/bin/python
def Pots():
print "I'm Pots Phone"

Similar way, we have another two files having different functions with the same name as above

 Phone/Isdn.py file having function Isdn()


 Phone/G3.py file having function G3()

Now, create one more file __init__.py in Phone directory −

 Phone/__init__.py

To make all of your functions available when you've imported Phone, you need to put explicit
import statements in __init__.py as follows −

from Pots import Pots


from Isdn import Isdn
from G3 import G3

After you add these lines to __init__.py, you have all of these classes available when you import
the Phone package.

#!/usr/bin/python
# Now import your Phone Package.
import Phone
Phone.Pots()
Phone.Isdn()
Phone.G3()

When the above code is executed, it produces the following result −

I'm Pots Phone


I'm 3G Phone
I'm ISDN Phone
In the above example, we have taken example of a single functions in each file, but you can keep
multiple functions in your files. You can also define different Python classes in those files and
then you can create your packages out of those classes.
Create and Access a Python Package

Packages help us to structure packages and modules in an organized hierarchy. Let's see how to
create packages in Python.

Creating Packages

We have included a __init__.py, file inside a directory to tell Python that the current directory is
a package. Whenever you want to create a package, then you have to include __init__.py file in
the directory. You can write code inside or leave it as blank as your wish. It doesn't bothers
Python.

Follow the below steps to create a package in Python

 Create a directory and include a __init__.py file in it to tell Python that the current
directory is a package.
 Include other sub-packages or files you want.
 Next, access them with the valid import statements.

Let's create a simple package that has the following structure.

Package (university)

 __init__.py
 student.py
 faculty.py

Go to any directory in your laptop or desktop and create the above folder structure. After
creating the above folder structure include the following code in respective files.

Example

# student.py
class Student:

def __init__(self, student):


self.name = student['name']
self.gender = student['gender']
self.year = student['year']

def get_student_details(self):
return f"Name: {self.name}\nGender: {self.gender}\nYear: {self.year}"

# faculty.py
class Faculty:
def __init__(self, faculty):
self.name = faculty['name']
self.subject = faculty['subject']

def get_faculty_details(self):
return f"Name: {self.name}\nSubject: {self.subject}"

We have the above in the student.py and faculty.py files. Let's create another file to access
those classed inside it. Now, inside the package directory create a file named testing.py and
include the following code.

Example

# testing.py
# importing the Student and Faculty classes from respective files
from student import Student
from faculty import Faculty

# creating dicts for student and faculty


student_dict = {'name' : 'John', 'gender': 'Male', 'year': '3'}
faculty_dict = {'name': 'Emma', 'subject': 'Programming'}

# creating instances of the Student and Faculty classes


student = Student(student_dict)
faculty = Faculty(faculty_dict)

# getting and printing the student and faculty details


print(student.get_student_details())
print()
print(faculty.get_faculty_details())

If you run the testing.py file, then you will get the following result.

Output

Name: John
Gender: Male
Year: 3

Name: Emma
Subject: Programming

We have seen how to create and to access a package in Python. And this is a simple package.
There might be plenty of sub-packages and files inside a package. Let's see how to access
subpackage modules.
Create a directory with the following structure

 Package (university)
o __init__.py
o Subpackage (student)
 __init__.py
 main.py
 ...
o testing.py

Copy the above student code and place it here. Now, let's see how to access it in the testing.py
file. Add the following in the testing.py file.

Example

# testing.py
from student.main import Student

# creating dicts for student


student_dict = {'name' : 'John', 'gender': 'Male', 'year': '3'}

# creating instances of the Student class


student = Student(student_dict)

# getting and printing the student details


print(student.get_student_details())

If you run the testing.py file, then you will get the following result.

Output

Name: John
Gender: Male
Year: 3

We have accessed the Student class from the main.py file inside the subpackage student using
a dot (.). You can go to as much deeper as you want based on the package structure.
Python Pandas - Introduction

Pandas is an open-source Python Library providing high-performance data manipulation and


analysis tool using its powerful data structures. The name Pandas is derived from the word Panel
Data – an Econometrics from Multidimensional data.

In 2008, developer Wes McKinney started developing pandas when in need of high performance,
flexible tool for analysis of data.

Prior to Pandas, Python was majorly used for data munging and preparation. It had very little
contribution towards data analysis. Pandas solved this problem. Using Pandas, we can
accomplish five typical steps in the processing and analysis of data, regardless of the origin of
data — load, prepare, manipulate, model, and analyze.

Python with Pandas is used in a wide range of fields including academic and commercial
domains including finance, economics, Statistics, analytics, etc.

Key Features of Pandas

 Fast and efficient DataFrame object with default and customized indexing.
 Tools for loading data into in-memory data objects from different file formats.
 Data alignment and integrated handling of missing data.
 Reshaping and pivoting of date sets.
 Label-based slicing, indexing and subsetting of large data sets.
 Columns from a data structure can be deleted or inserted.
 Group by data for aggregation and transformations.
 High performance merging and joining of data.
 Time Series functionality.

Python Pandas - Environment Setup

Standard Python distribution doesn't come bundled with Pandas module. A lightweight
alternative is to install NumPy using popular Python package installer, pip.

pip install pandas

If you install Anaconda Python package, Pandas will be installed by default with the following −

Windows

 Anaconda (from https://www.continuum.io) is a free Python distribution for SciPy stack.


It is also available for Linux and Mac.
 Canopy (https://www.enthought.com/products/canopy/) is available as free as well as
commercial distribution with full SciPy stack for Windows, Linux and Mac.
 Python (x,y) is a free Python distribution with SciPy stack and Spyder IDE for Windows
OS. (Downloadable from http://python-xy.github.io/)

Linux

Package managers of respective Linux distributions are used to install one or more packages in
SciPy stack.

For Ubuntu Users

sudo apt-get install python-numpy python-scipy python-matplotlibipythonipythonnotebook


python-pandas python-sympy python-nose

For Fedora Users

sudo yum install numpyscipy python-matplotlibipython python-pandas sympy


python-nose atlas-devel
NumPy - Introduction

NumPy is a Python package. It stands for 'Numerical Python'. It is a library consisting of


multidimensional array objects and a collection of routines for processing of array.

Numeric, the ancestor of NumPy, was developed by Jim Hugunin. Another package Numarray
was also developed, having some additional functionalities. In 2005, Travis Oliphant created
NumPy package by incorporating the features of Numarray into Numeric package. There are
many contributors to this open source project.

Operations using NumPy

Using NumPy, a developer can perform the following operations −

 Mathematical and logical operations on arrays.


 Fourier transforms and routines for shape manipulation.
 Operations related to linear algebra. NumPy has in-built functions for linear algebra and
random number generation.

NumPy – A Replacement for MatLab

NumPy is often used along with packages like SciPy (Scientific Python) and Mat−plotlib
(plotting library). This combination is widely used as a replacement for MatLab, a popular
platform for technical computing. However, Python alternative to MatLab is now seen as a more
modern and complete programming language.

It is open source, which is an added advantage of NumPy.


Scikit Learn - Introduction

In this chapter, we will understand what is Scikit-Learn or Sklearn, origin of Scikit-Learn and
some other related topics such as communities and contributors responsible for development and
maintenance of Scikit-Learn, its prerequisites, installation and its features.

What is Scikit-Learn (Sklearn)

Scikit-learn (Sklearn) is the most useful and robust library for machine learning in Python. It
provides a selection of efficient tools for machine learning and statistical modeling including
classification, regression, clustering and dimensionality reduction via a consistence interface in
Python. This library, which is largely written in Python, is built upon NumPy, SciPy and
Matplotlib.

Origin of Scikit-Learn

It was originally called scikits.learn and was initially developed by David Cournapeau as a
Google summer of code project in 2007. Later, in 2010, Fabian Pedregosa, Gael Varoquaux,
Alexandre Gramfort, and Vincent Michel, from FIRCA (French Institute for Research in
Computer Science and Automation), took this project at another level and made the first public
release (v0.1 beta) on 1st Feb. 2010.

Let’s have a look at its version history −

 May 2019: scikit-learn 0.21.0


 March 2019: scikit-learn 0.20.3
 December 2018: scikit-learn 0.20.2
 November 2018: scikit-learn 0.20.1
 September 2018: scikit-learn 0.20.0
 July 2018: scikit-learn 0.19.2
 July 2017: scikit-learn 0.19.0
 September 2016. scikit-learn 0.18.0
 November 2015. scikit-learn 0.17.0
 March 2015. scikit-learn 0.16.0
 July 2014. scikit-learn 0.15.0
 August 2013. scikit-learn 0.14

Community & contributors

Scikit-learn is a community effort and anyone can contribute to it. This project is hosted on
https://github.com/scikit-learn/scikit-learn. Following people are currently the core contributors
to Sklearn’s development and maintenance −
 Joris Van den Bossche (Data Scientist)
 Thomas J Fan (Software Developer)
 Alexandre Gramfort (Machine Learning Researcher)
 Olivier Grisel (Machine Learning Expert)
 Nicolas Hug (Associate Research Scientist)
 Andreas Mueller (Machine Learning Scientist)
 Hanmin Qin (Software Engineer)
 Adrin Jalali (Open Source Developer)
 Nelle Varoquaux (Data Science Researcher)
 Roman Yurchak (Data Scientist)

Various organisations like Booking.com, JP Morgan, Evernote, Inria, AWeber, Spotify and
many more are using Sklearn.

Prerequisites

Before we start using scikit-learn latest release, we require the following −

 Python (>=3.5)
 NumPy (>= 1.11.0)
 Scipy (>= 0.17.0)li
 Joblib (>= 0.11)
 Matplotlib (>= 1.5.1) is required for Sklearn plotting capabilities.
 Pandas (>= 0.18.0) is required for some of the scikit-learn examples using data structure
and analysis.

Installation

If you already installed NumPy and Scipy, following are the two easiest ways to install scikit-
learn −

Using pip

Following command can be used to install scikit-learn via pip −

pip install -U scikit-learn


Using conda

Following command can be used to install scikit-learn via conda −

conda install scikit-learn

On the other hand, if NumPy and Scipy is not yet installed on your Python workstation then, you
can install them by using either pip or conda.
Another option to use scikit-learn is to use Python distributions like Canopy and Anaconda
because they both ship the latest version of scikit-learn.

Features

Rather than focusing on loading, manipulating and summarising data, Scikit-learn library is
focused on modeling the data. Some of the most popular groups of models provided by Sklearn
are as follows −

Supervised Learning algorithms − Almost all the popular supervised learning algorithms, like
Linear Regression, Support Vector Machine (SVM), Decision Tree etc., are the part of scikit-
learn.

Unsupervised Learning algorithms − On the other hand, it also has all the popular
unsupervised learning algorithms from clustering, factor analysis, PCA (Principal Component
Analysis) to unsupervised neural networks.

Clustering − This model is used for grouping unlabeled data.

Cross Validation − It is used to check the accuracy of supervised models on unseen data.

Dimensionality Reduction − It is used for reducing the number of attributes in data which can
be further used for summarisation, visualisation and feature selection.

Ensemble methods − As name suggest, it is used for combining the predictions of multiple
supervised models.

Feature extraction − It is used to extract the features from data to define the attributes in image
and text data.

Feature selection − It is used to identify useful attributes to create supervised models.

Open Source − It is open source library and also commercially usable under BSD license
Python Libraries for Data Processing and Modeling

1. Pandas

Pandas is a free Python software library for data analysis and data handling. It was created as a
community library project and initially released around 2008. Pandas provides various high-
performance and easy-to-use data structures and operations for manipulating data in the form of
numerical tables and time series. Pandas also has multiple tools for reading and writing data
between in-memory data structures and different file formats. In short, it is perfect for quick and
easy data manipulation, data aggregation, reading, and writing the data as well as data
visualization. Pandas can also take in data from different types of files such as CSV, excel etc.or
a SQL database and create a Python object known as a data frame. A data frame contains rows
and columns and it can be used for data manipulation with operations such as join, merge,
groupby, concatenate etc.

2. NumPy

NumPy is a free Python software library for numerical computing on data that can be in the form
of large arrays and multi-dimensional matrices. These multidimensional matrices are the main
objects in NumPy where their dimensions are called axes and the number of axes is called a rank.
NumPy also provides various tools to work with these arrays and high-level mathematical
functions to manipulate this data with linear algebra, Fourier transforms, random number
crunchings, etc. Some of the basic array operations that can be performed using NumPy include
adding, slicing, multiplying, flattening, reshaping, and indexing the arrays. Other advanced
functions include stacking the arrays, splitting them into sections, broadcasting arrays, etc.

3. SciPy

SciPy is a free software library for scientific computing and technical computing on the data. It
was created as a community library project and initially released around 2001. SciPy library is
built on the NumPy array object and it is part of the NumPy stack which also includes other
scientific computing libraries and tools such as Matplotlib, SymPy, pandas etc. This NumPy
stack has users which also use comparable applications such as GNU Octave, MATLAB, GNU
Octave, Scilab, etc. SciPy allows for various scientific computing tasks that handle data
optimization, data integration, data interpolation, and data modification using linear algebra,
Fourier transforms, random number generation, special functions, etc. Just like NumPy, the
multidimensional matrices are the main objects in SciPy, which are provided by the NumPy
module itself.

4. Scikit-learn

Scikit-learn is a free software library for Machine Learning coding primarily in the Python
programming language. It was initially developed as a Google Summer of Code project by
David Cournapeau and originally released in June 2007. Scikit-learn is built on top of other
Python libraries like NumPy, SciPy, Matplotlib, Pandas, etc. and so it provides full
interoperability with these libraries. While Scikit-learn is written mainly in Python, it has also
used Cython to write some core algorithms in order to improve performance. You can implement
various Supervised and Unsupervised Machine learning models on Scikit-learn like
Classification, Regression, Support Vector Machines, Random Forests, Nearest Neighbors,
Naive Bayes, Decision Trees, Clustering, etc. with Scikit-learn.

5. TensorFlow

TensorFlow is a free end-to-end open-source platform that has a wide variety of tools, libraries,
and resources for Artificial Intelligence. It was developed by the Google Brain team and initially
released on November 9, 2015. You can easily build and train Machine Learning models with
high-level API’s such as Keras using TensorFlow. It also provides multiple levels of abstraction
so you can choose the option you need for your model. TensorFlow also allows you to deploy
Machine Learning models anywhere such as the cloud, browser, or your own device. You should
use TensorFlow Extended (TFX) if you want the full experience, TensorFlow Lite if you want
usage on mobile devices, and TensorFlow.js if you want to train and deploy models in JavaScript
environments. TensorFlow is available for Python and C APIs and also for C++, Java,
JavaScript, Go, Swift, etc. but without an API backward compatibility guarantee. Third-party
packages are also available for MATLAB, C#, Julia, Scala, R, Rust, etc.

6. Keras

Keras is a free and open-source neural-network library written in Python. It was primarily
created by François Chollet, a Google engineer, and initially released on 27 March 2015. Keras
was created to be user friendly, extensible, and modular while being supportive of
experimentation in deep neural networks. Hence, it can be run on top of other libraries and
languages like TensorFlow, Theano, Microsoft Cognitive Toolkit, R, etc. Keras has multiple
tools that make it easier to work with different types of image and textual data for coding in deep
neural networks. It also has various implementations of the building blocks for neural networks
such as layers, optimizers, activation functions, objectives, etc. You can perform various actions
using Keras such as creating custom function layers, writing functions with repeating code
blocks that are multiple layers deep, etc.

Python Libraries for Data Visualization

1. Matplotlib

Matplotlib is a data visualization library and 2-D plotting library of Python It was initially
released in 2003 and it is the most popular and widely-used plotting library in the Python
community. It comes with an interactive environment across multiple platforms. Matplotlib can
be used in Python scripts, the Python and IPython shells, the Jupyter notebook, web application
servers etc. It can be used to embed plots into applications using various GUI toolkits like
Tkinter, GTK+, wxPython, Qt, etc. So you can use Matplotlib to create plots, bar charts, pie
charts, histograms, scatterplots, error charts, power spectra, stemplots, and whatever other
visualization charts you want! The Pyplot module also provides a MATLAB-like interface that is
just as versatile and useful as MATLAB while being totally free and open source.
2. Seaborn

Seaborn is a Python data visualization library that is based on Matplotlib and closely integrated
with the numpy and pandas data structures. Seaborn has various dataset-oriented plotting
functions that operate on data frames and arrays that have whole datasets within them. Then it
internally performs the necessary statistical aggregation and mapping functions to create
informative plots that the user desires. It is a high-level interface for creating beautiful and
informative statistical graphics that are integral to exploring and understanding data. The
Seaborn data graphics can include bar charts, pie charts, histograms, scatterplots, error charts,
etc. Seaborn also has various tools for choosing color palettes that can reveal patterns in the data.

3. Plotly

Plotly is a free open-source graphing library that can be used to form data visualizations. Plotly
(plotly.py) is built on top of the Plotly JavaScript library (plotly.js) and can be used to create
web-based data visualizations that can be displayed in Jupyter notebooks or web applications
using Dash or saved as individual HTML files. Plotly provides more than 40 unique chart types
like scatter plots, histograms, line charts, bar charts, pie charts, error bars, box plots, multiple
axes, sparklines, dendrograms, 3-D charts, etc. Plotly also provides contour plots, which are not
that common in other data visualization libraries. In addition to all this, Plotly can be used offline
with no internet connection.

4. GGplot

Ggplot is a Python data visualization library that is based on the implementation of ggplot2
which is created for the programming language R. Ggplot can create data visualizations such as
bar charts, pie charts, histograms, scatterplots, error charts, etc. using high-level API. It also
allows you to add different types of data visualization components or layers in a single
visualization. Once ggplot has been told which variables to map to which aesthetics in the plot, it
does the rest of the work so that the user can focus on interpreting the visualizations and take less
time in creating them. But this also means that it is not possible to create highly customised
graphics in ggplot. Ggplot is also deeply connected with pandas so it is best to keep the data in
DataFrames.
Data Mining
1. Scrapy

One of the most popular Python data science libraries, Scrapy helps to build crawling programs
(spider bots) that can retrieve structured data from the web – for example, URLs or contact info.
It’s a great tool for scraping data used in, for example, Python machine learning models.

Developers use it for gathering data from APIs. This full-fledged framework follows the Don’t
Repeat Yourself principle in the design of its interface. As a result, the tool inspires users to
write universal code that can be reused for building and scaling large crawlers.

2. BeautifulSoup

BeautifulSoup is another really popular library for web crawling and data scraping. If you want
to collect data that’s available on some website but not via a proper CSV or API, BeautifulSoup
can help you scrape it and arrange it into the format you need.

Data Processing and Modeling


3. NumPy

NumPy (Numerical Python) is a perfect tool for scientific computing and performing basic and
advanced array operations.

The library offers many handy features performing operations on n-arrays and matrices in
Python. It helps to process arrays that store values of the same data type and makes performing
math operations on arrays (and their vectorization) easier. In fact, the vectorization of
mathematical operations on the NumPy array type increases performance and accelerates the
execution time.

4. SciPy

This useful library includes modules for linear algebra, integration, optimization, and statistics.
Its main functionality was built upon NumPy, so its arrays make use of this library. SciPy works
great for all kinds of scientific programming projects (science, mathematics, and engineering). It
offers efficient numerical routines such as numerical optimization, integration, and others in
submodules. The extensive documentation makes working with this library really easy.

5. Pandas

Pandas is a library created to help developers work with “labeled” and “relational” data
intuitively. It’s based on two main data structures: “Series” (one-dimensional, like a list of items)
and “Data Frames” (two-dimensional, like a table with multiple columns). Pandas allows
converting data structures to DataFrame objects, handling missing data, and adding/deleting
columns from DataFrame, imputing missing files, and plotting data with histogram or plot box.
It’s a must-have for data wrangling, manipulation, and visualization.

(Want to learn pandas? Check out Dataquest’s NumPy and Pandas fundamentals course, or one
of our many free pandas tutorials.)

6. Keras

Keras is a great library for building neural networks and modeling. It’s very straightforward to
use and provides developers with a good degree of extensibility. The library takes advantage of
other packages, (Theano or TensorFlow) as its backends. Moreover, Microsoft integrated CNTK
(Microsoft Cognitive Toolkit) to serve as another backend. It’s a great pick if you want to
experiment quickly using compact systems – the minimalist approach to design really pays off!

7. SciKit-Learn

This is an industry-standard for data science projects based in Python. Scikits is a group of
packages in the SciPy Stack that were created for specific functionalities – for example, image
processing. Scikit-learn uses the math operations of SciPy to expose a concise interface to the
most common machine learning algorithms.

Data scientists use it for handling standard machine learning and data mining tasks such as
clustering, regression, model selection, dimensionality reduction, and classification. Another
advantage? It comes with quality documentation and offers high performance.

8. PyTorch

PyTorch is a framework that is perfect for data scientists who want to perform deep learning
tasks easily. The tool allows performing tensor computations with GPU acceleration. It’s also
used for other tasks – for example, for creating dynamic computational graphs and calculating
gradients automatically. PyTorch is based on Torch, which is an open-source deep learning
library implemented in C, with a wrapper in Lua.

9. TensorFlow

TensorFlow is a popular Python framework for machine learning and deep learning, which was
developed at Google Brain. It’s the best tool for tasks like object identification, speech
recognition, and many others. It helps in working with artificial neural networks that need to
handle multiple data sets. The library includes various layer-helpers (tflearn, tf-slim, skflow),
which make it even more functional. TensorFlow is constantly expanded with its new releases –
including fixes in potential security vulnerabilities or improvements in the integration of
TensorFlow and GPU.

10. XGBoost
Use this library to implement machine learning algorithms under the Gradient Boosting
framework. XGBoost is portable, flexible, and efficient. It offers parallel tree boosting that helps
teams to resolve many data science problems. Another advantage is that developers can run the
same code on major distributed environments such as Hadoop, SGE, and MPI.

Data Visualization
11. Matplotlib

This is a standard data science library that helps to generate data visualizations such as two-
dimensional diagrams and graphs (histograms, scatterplots, non-Cartesian coordinates graphs).
Matplotlib is one of those plotting libraries that are really useful in data science projects — it
provides an object-oriented API for embedding plots into applications.

It’s thanks to this library that Python can compete with scientific tools like MatLab or
Mathematica. However, developers need to write more code than usual while using this library
for generating advanced visualizations. Note that popular plotting libraries work seamlessly with
Matplotlib.

12. Seaborn

Seaborn is based on Matplotlib and serves as a useful Python machine learning tool for
visualizing statistical models – heatmaps and other types of visualizations that summarize data
and depict the overall distributions. When using this library, you get to benefit from an extensive
gallery of visualizations (including complex ones like time series, joint plots, and violin
diagrams).

13. Bokeh

This library is a great tool for creating interactive and scalable visualizations inside browsers
using JavaScript widgets. Bokeh is fully independent of Matplotlib. It focuses on interactivity
and presents visualizations through modern browsers – similarly to Data-Driven Documents
(d3.js). It offers a set of graphs, interaction abilities (like linking plots or adding JavaScript
widgets), and styling.

14. Plotly

This web-based tool for data visualization that offers many useful out-of-box graphics – you can
find them on the Plot.ly website. The library works very well in interactive web applications. Its
creators are busy expanding the library with new graphics and features for supporting multiple
linked views, animation, and crosstalk integration.

15. pydot

This library helps to generate oriented and non-oriented graphs. It serves as an interface to
Graphviz (written in pure Python). You can easily show the structure of graphs with the help of
this library. That comes in handy when you’re developing algorithms based on neural networks
and decision trees.
What Are Frameworks In Python?

A framework is a collection of modules or packages which helps in writing web applications.


While working on frameworks in python we don’t have to worry about the low level details such
as protocols, sockets or thread management.

Frameworks automate the common implementation of common solutions which gives the
flexibility to the users to focus on the application logic instead of the basic routine processes.

Frameworks make the life of web developers easier by giving them a structure for app
development. They provide common patterns in a web application that are fast, reliable and
easily maintainable.

Lets take a look at a few operations involved in a web application using a web framework:

 Url Routing – Routing is the mechanism of mapping the URL directly to the code that
creates the web page.
 Input form handling and validation – Suppose you have a form which takes some
input, the idea is to validate the data and then save it.
 Output formats with template engine – A template engine allows the developers to
generate desired content types like HTML, XML, JSON.
 Database connection – Database connection configuration and persistent data
manipulation through an ORM.
 Web security – Frameworks give web security against cross-site request forgery aka
CSRF, sql injection, cross-site scripting and other common malicious attacks.
 Session storage and retrieval – Data stored in the session storage gets cleared when the
page session ends.

Advantages Of Frameworks

1. Open-source
2. Good documentation
3. Efficient
4. Secure
5. Integration

Why Use A Framework?

Frameworks make it easier to reuse the code for common HTTP operations. They structure the
projects in a way so that the other developers with the knowledge of the framework can easily
maintain and build the application.
Library vs Framework

Library Framework
Less complex More complex
When you call a method from a library, you are The control is inverted, the frameworks calls
in control. you.
A framework contains the basic flow, the rest is
A library performs specific operations.
build by the user.

The key advantage of using a framework instead of a library is the flexibility. They are
extensible and provides us with the necessary tools to extend its features.

When you have a library, you have to learn each functionality to perform certain operations. But
with frameworks it becomes relatively easy due to the structured control of the flow. We just
have to direct our operations using a certain operation using the functionalities already existing
in the framework.

Although there are a lot of frameworks available in the market for web development, below are
the top 5 frameworks in python.
Top 5 Frameworks In Python

Depending upon the sort of functionalities and key features they provide to the user, these are top
5 frameworks in python, both micro-frameworks and full-stack frameworks.

 Django
 Web2Py
 Flask
 Bottle
 CherryPy

Before we move any further, let us take a quick look at the difference between the terms
mentioned below:

Difference between a micro-framework and a full-stack framework?

Python Django Certification Training Course

Micro-framework Full-stack framework


simple and easy to use Complex and does the heavy lifting
url routing is RESTful often Need not be RESTful
A good choice for small applications Can be used to make any applications
Provide libraries, template engines, database ma
Use WSGI and work through HTTP request/response.
etc.
Django

Django is a free and open-source full-stack python framework, it includes all the necessary
features by default.

It follows the DRY principle, which says don’t repeat yourselves. Django uses its ORM mappers
to map objects to database tables. An ORM or object relational mapper is a code library which
helps you manipulate the data from a database using the object-oriented paradigm.

The main databases that django works on are PostgreSQL, MySQL, SQLite, Oracle. It can also
work with other databases using the third party drivers.

Some of the exemplary features of django web frameworks are following:

 Authentication
 URL routing
 Template engine
 ORM
 Database Schema migrations

Django also follows MVC-MVT architecture,

MVC-MVT architecture:

MVT is slightly different from MVC, Although Django takes care of the controller part which is
the code that controls the interactions between the model and the view. And the template is
HTML file mixed with Django template language.

Developer provides the model, view and the template. User then maps it to the url and then the
rest is done by django to serve it to the user.
Web2Py

Web2Py is open source, scalable and a full-stack framework . It does not support python 3
and comes with its own web based IDE which also includes a separate code editor, debugger and
one click deployment.

Programming & Frameworks Training

Following are the features of Web2Py framework:

 It does not have any prerequisites for installation and configuration


 It has the ability to run on different platforms. Example- windows, mac, linux etc.
 Comes with an ability to read multiple protocols
 Web2Py provides data security against vulnerabilities like cross site scripting, sql
injection and other malicious attacks.
 It has an error tracking mechanism through an error logging and ticketing system.
 Also has role based access control
 There is backward compatibility which ensures user oriented advancement without the
need to lose any ties with earlier versions.

Flask

Flask is a micro-framework. It is lightweight and its modular design makes it easily adaptable to
developer’s needs. It has a number of out of the box features listed below:
 Built-in development server
 A fast debugger
 Integrated support for unit testing
 RESTful request dispatching
 Jinja2 templating
 Secure cookies support
 Unicode-based
 WSGI compliance
 Ability to plug any ORM
 HTTP request handling

Bottle

Bottle is a micro-framework which is originally meant for building APIs , bottle implements
everything in a single source file. It has no dependencies whatsoever apart from the python
standard library.

The default features include the following:

 Routing
 Templating
 Access to form data, file uploads, cookies, headers etc.
 Abstraction layer over the WSGI standard
 A built-in development server that supports any other WSGI-capable HTTP server.

Bottle is perfect for building simple personal applications, prototyping and learning the
organisation of web frameworks.
CherryPy

CherryPy is an open-source framework. It follows the minimalist approach in building web


applications. It makes building web applications similar to writing an object oriented program.

CherryPy allows us to use any type of technology for creating templates and data access. It is
still able to handle sessions, cookies, statics, file uploads and everything else a web framework
typically can.

Following are some key features of CherryPy:

Python Django Certification Training Course

Weekday / Weekend Batches

 An HTTP WSGI compliant thread pooled web server


 It has simplicity of running multiple HTTP servers at once
 A flexible plugin system
 Caching
 Encoding
 Authentication
 Built-in support for profiling, coverage and testing
 Ability to run on different platforms

While choosing a framework for any project you must keep in mind the functionalities and
features that it comes with. The specifications and the ability of a framework to cope up with
those requirements will determine the performance of your project. In this blog, we have
discussed the key features of top 5 frameworks in python which will help you determine the
necessity of any of these frameworks while you are working on a web development project.
Python Frameworks

Python is one of the most acceptable languages among web and application developers because
of its strong emphasis on efficiency and readability. There are numerous outstanding Python web
frameworks, each with their own specialities and features.

Django
Here, we will outline some necessary details and features of Django framework.

Category − Django belongs to the full-stack Python framework.

Release − Latest release – 2.1 version, commonly used release – 1.8, 1.6 version.

About − Built by experienced developers, Django is a high level Python web framework which
allows rapid, clean and pragmatic design development. Django handles much of the complexities
of web development, so you can focus on writing your app without a need to reinvent the wheel.
It’s free and open source.

To map objects to database table, Django uses ORM and the same is used to transfer from one
database to other.

It works with mostly all important databases like Oracle, MySQL, PostgreSQL, SQLite, etc.

There are numerous websites in the industry which uses Django as their primary framework for
backend development.

Features of Django

Some of the exemplary features of this Python web framework are −

 URL routing
 Authentication
 Database schema migrations
 ORM (Object-relational mapper)
 Template engine

The Official Website for Django framework is −https://www.djangoproject.com/


Flask
Category − Flask belongs to Non Full-stack frameworks.

Release − 1.0.2 released on 2018-05-02

About − It is classified as a micro-framework as we don’t require any particular libraries or


tools. It has no form validation or database abstraction layer or any other components where pre-
existing third party libraries provide common functions. However, flask support multiple
extensions which extended the application features as if they were implemented in Flask itself.
Extensions exist for object-relational mappers, form validation, upload handling, various open
authentication technologies and several common frameworks related tools.

Features of Flask

 Integrated support for unit testing


 Restful request dispatching
 Contains development server and debugger
 Uses Jinja2 templating
 Support for secure cookies
 Unicode-based
 100% WSGI 1.0 compliant
 Extensive documentation
 Google App Engine compatibility
 Extensions available to enhance features desired
Web2py
Category − Web2py belongs to Full-stack framework family.

Release − 2.17.1, released on 2018-08-06

About − Python 2.6, 2.7 to Python 3.x version. With no further dependencies, it’s a complete
package in itself. Development, database administration, debugging, deployment, testing, and
maintenance of applications all can be done through web interface, but generally not required. It
is a scalable open source framework that comes with its own web-based IDE alongside a code
editor, one-click deployment and debugger.

Features of Web2py

This framework comes with many developing tools and built-in features that eliminate the hassle
of complexity to the developers.

 With no installation and configuration, it is easy to run.


 Supports almost all major operating system, like Windows, Unix/Linux, Mac, Google
App Engine and almost all web hosting platform through Python 2.7/3.5/3.6/ version.
 Easy to communicate with MySQL, MSSQL, IBM DB2, Informix, Ingres, MongoDB,
SQLite, PostgreSQL, Sybase, Oracle and Google App Engine.
 It prevents the most common types of vulnerabilities including Cross Site Scripting,
Injection Flaws, and Malicious File Execution.
 Supports error tracking and internationalization.
 Multiple protocols readability.
 Employs successful software engineering practices that makes code easy to read and
maintain.
 Ensure user-oriented advancements through backward compatibility.
Pyramid
Category − Pyramid is a non-Full Stack Frameworks

Release − 1.9.2, released on 2018-04-23

About − Pyramid is a small, fast, down-to-earth Python web framework. It is developed as part
of the Pylons Project. It is licensed under a BSD-like license. It makes real-world web
application development and deployment more fun, more predictable and more productive.

Features of Pyramid

Python Pyramid is an open sourced framework with the following features −

 Simplicity − Anyone can start to work with it without any prior knowledge about it.
 Minimalism − Quite out of the box, Pyramid comes with only some important tools,
which are needed for almost every web application, may it be security or serving static
assets like JavaScript and CSS or attaching URLs to code.
 Documentation − Includes exclusive and up to date documentation.
 Speed − Very fast and accurate.
 Reliability − It is developed, keeping in mind that it is conservative and tested
exhaustively. If not tested properly, it will be considered as broke.
 Openness − It’s sold with a permissive and open license.
Dash
Category − The Dash framework belongs to “other” Python web frameworks.

Release − 0.24.1, core dash backend.

About − Dash as an open source library for creating interactive web-based visualizations. The
plotly team created Dash – an open source framework that leverages Flask, React.js and plotly.js
to build custom data visualization apps. Key highlight of this library is that you can build highly
interactive web application only through Python code. Data scientists love dash framework,
specially all those who are less familiar with web development.

With Dash, developers get access to all the configurable properties and underlying Flask
instance. The applications developed using Dash framework can be deployed to servers and are
eventually rendered in the web browser.

Dash applications are inherently cross-platform (Linux/Win/Mac) and mobile friendly and the
capabilities of applications can be extended by the rich set of Flask Plugins.
Features of Dash

 Provides access to configurable properties and Flask instance


 Through Flash plugins, we can extend the capabilities of the Dash application
 Mobile-ready

You might also like