CC Unit - 4
CC Unit - 4
CC Unit - 4
BENEFITS OF PYTHON
Benefits of Python include:
Developers can easily read and understand a Python program because it has basic, English-like syntax.
Python makes developers more productive because they can write a Python program using fewer lines of code
compared to many other languages.
Python has a large standard library that contains reusable codes for almost any task. As a result, developers do
not have to write code from scratch.
Developers can easily use Python with other popular programming languages such as Java, C, and C++.
The active Python community includes millions of supportive developers around the globe. If you face an issue,
you can get quick support from the community.
Plenty of helpful resources are available on the internet if you want to learn Python. For example, you can easily
find videos, tutorials, documentation, and developer guides.
Python is portable across different computer operating systems such as Windows, macOS, Linux, and Unix.
PYTHON USED
The Python language has several use cases in application development, including the following examples:
S OFTWARE DEVELOPMENT
Software developers often use Python for different development tasks and software applications such as the following:
Keeping track of bugs in the software code
Automatically building the software
Handling software project management
Developing software prototypes
Developing desktop applications using Graphical User Interface (GUI) libraries
Developing simple text-based games to more complex video games
Software testing is the process of checking whether the actual results from the software match the expected results to
ensure that the software is error-free.
Developers use Python unit test frameworks, such as Unittest, Robot, and PyUnit, to test the functions they write.
Software testers use Python to write test cases for various test scenarios. For example, they use it to test the user
interface of a web application, multiple software components, and new features.
Developers can use several tools to automatically run test scripts. These tools are known as Continuous
Integration/Continuous Deployment (CI/CD) tools. Software testers and developers use CI/CD tools such as Travis CI
and Jenkins to automate tests. The CI/CD tool automatically runs the Python test scripts and reports the test results
whenever developers introduce new code changes.
HISTORY OF PYTHON
Guido Van Rossum, a computer programmer in the Netherlands, created Python. He started it in 1989 at Centrum
Wiskunde & Informatica (CWI), initially as a hobby project to stay busy during Christmastime. The name for the
language was inspired by the BBC TV show Monty Python’s Flying Circus because Guido Van Rossum was a big fan of
the show.
FEATURES OF PYTHON
PYTHON LIBRARIES
A library is a collection of frequently used codes that developers can include in their Python programs to avoid writing
code from scratch. By default, Python comes with the Standard Library, which contains a lot of reusable functions. In
addition, more than 137,000 Python libraries are available for various applications, including web development, data
science, and machine learning (ML).
PYTHON FRAMEWORKS
A Python framework is a collection of packages and modules. A module is a set of related code, and a package is a set of
modules. Developers can use Python frameworks to build Python applications more quickly because they do not have to
worry about low-level details such as how communications happen in the web application or how Python will make the
program faster. Python has two types of frameworks:
A full-stack framework includes almost everything that is required to build a large application.
A microframework is a basic framework that provides minimal functionalities for building simple Python
applications. It also provides extensions if applications need more sophisticated functions.
Developers can use multiple Python frameworks to make their development efficient, including the following
frameworks:
Django
Django is one of the most widely used full-stack Python web frameworks for developing large-scale web applications. It
provides several useful features, including a web server for development and testing, a template engine to build the
website frontend, and various security mechanisms.
Flask
Flask is a micro-framework for developing small web applications. Its features include strong community support, well-
written documentation, a template engine, unit testing, and a built-in web server. It also provides extensions for validation
support, database mapping layers, and web security.
TurboGears
TurboGears is a framework designed to build web applications faster and easier. These are some of its popular features:
A specific database table structure
Tools for creating and managing projects
PYTHON IDES?
An integrated development environment (IDE) is software that gives developers the tools they need to write, edit, test,
and debug code in one place.
IDLE
Integrated Development and Learning Environment (IDLE) is the Python IDE installed by default. It has been developed
only with Python using the Tkinter GUI toolkit and offers the following features:
Works across many operating systems such as Windows, Unix, and macOS
Provides a shell window to run commands and display the output
Offers a multiple-window text editor that provides code syntax highlighting and automatic code completion
Has its own debugger
Spyder
Spyder is an open-source IDE that many scientists and data analysts use. It provides a comprehensive development
experience with features for advanced data analysis, data visualization, and debugging. It also includes the following
features:
A rich code editor that supports multiple languages
An interactive IPython console
A basic debugger
Scientific libraries such as Matplotlib, SciPy, and NumPy
Ability to explore variables in the code
Ability to view documentation in real time
Atom
Atom is a free editor developed by GitHub that supports coding in many programming languages, including Python.
Using Atom, developers can directly work with GitHub, the website where you can save your code centrally. Atom offers
the following features:
Ability to use with many operating systems
PYTHON SDKS
A software development kit (SDK) is a collection of software tools that developers can use to create software
applications in a particular language. Most SDKs are specific to different hardware platforms and operating systems.
Python SDKs include many tools such as libraries, code samples, and developer guides that developers find helpful when
writing applications.
BOTO3 IN PYTHON
Boto3 is the AWS SDK for Python. You can use it to create, configure, and manage AWS services such as Amazon
Elastic Compute Cloud (EC2), Amazon Simple Storage Service (S3), and Amazon DynamoDB. Boto3 also provides two
types of APIs: low-level APIs and Resource APIs for developers.
AWS PYCHARM
The AWS Toolkit for PyCharm is the plug-in for the PyCharm IDE that makes it easier to create, debug, and deploy
Python applications on AWS. Using the AWS Toolkit for PyCharm, developers can easily get started with Python
development. It provides several useful features for developers, including start guides, step-through debugging, and IDE
deployment.
RESULT IN CHARGES TO YOUR AWS ACCOUNT . THESE INCLUDE POSSIBLE CHARGES FOR SERVICES SUCH AS
AMAZON ELASTIC COMPUTE CLOUD (A MAZON EC2) AND AMAZON SIMPLE STORAGE SERVICE (AMAZON S3). F OR
MORE INFORMATION , SEE A MAZON EC2 P RICING AND A MAZON S3 P RICING .
PREREQUISITES
Before you use this tutorial, be sure to meet the following requirements.
You have an AWS Cloud9 EC2 development environment
This tutorial assumes that you have an EC2 environment, and that the environment is connected to an Amazon EC2
instance running Amazon Linux or Ubuntu Server. See Creating an EC2 Environment for details.
If you have a different type of environment or operating system, you might need to adapt this tutorial's instructions.
You have opened the AWS Cloud9 IDE for that environment
When you open an environment, AWS Cloud9 opens the IDE for that environment in your web browser. See Opening an
environment in AWS Cloud9 for details.
STEP 4: INSTALL AND CONFIGURE THE AWS SDK FOR PYTHON (BOTO3)
The AWS SDK for Python (Boto3) enables you to use Python code to interact with AWS services like Amazon S3. For
example, you can use the SDK to create an Amazon S3 bucket, list your available buckets, and then delete the bucket you
just created.
INSTALL PIP
In the AWS Cloud9 IDE, confirm whether pip is already installed for the active version of Python by running the python
-m pip --version command. If pip is installed, skip to the next section.
To install pip, run the following commands. Because sudo is in a different environment from your user, you must specify
the version of Python to use if it differs from the current aliased version.
INSTALL THE AWS SDK FOR P YTHON (B OTO 3)
After you install pip, install the AWS SDK for Python (Boto3) by running the pip install command.
S ET UP CREDENTIALS IN YOUR ENVIRONMENT
Each time you use the AWS SDK for Python (Boto3) to call an AWS service, you must provide a set of credentials with
the call. These credentials determine whether the SDK has the necessary permissions to make the call. If the credentials
don't cover the necessary permissions, the call fails.
To store your credentials within the environment, follow the instructions in Calling AWS services from an environment
in AWS Cloud9, and then return to this topic.
For additional information, see Credentials in the AWS SDK for Python (Boto3).
STEP 7: CLEAN UP
To prevent ongoing charges to your AWS account after you're done with this tutorial, delete the AWS Cloud9
environment. For instructions, see Deleting an environment in AWS Cloud9.
introducing additional AWS services that demonstrate how to manage and deploy an application in the AWS Cloud. The
updated workflow includes the following additions: Continuous Integration / Continuous Deployment (CI / CD) pipeline,
applications tests, Blue / Green application deployment pattern, and updated Terraform modules. This additional
functionality enables developers to automatically test and deploy new versions of the Flask application. Using Python
Flask, Terraform, and Docker in conjunction with several AWS services, you configure a CI/CD pipeline for deploying a
Python Flask application.
After going through this exercise, readers will know how to use AWS services and open source tools for managing an
open source application in the AWS Cloud.
PREREQUISITES
An AWS account with local credentials properly configured (typically under ~/.aws/credentials).
The latest version of the AWS Command Line Interface (AWS CLI). For more information, refer to the
documentation for installing, updating, and uninstalling the AWS CLI.
Terraform14.7+ installed on local workstation.
Docker Desktop 3.1.0+ installed on local workstation.
A Git client to clone the source code provided and a GitHub repository.
Python6+ installed on local workstation.
Boto3 installed on local workstation.
SOLUTION OVERVIEW
There is a sample Python Flask application that is deployed by AWS CodePipeline. The pipeline uses Docker to build
and deploy the image to the Amazon Elastic Container Registry (Amazon ECR). Unit tests are run during the Docker
image build. Next, the appspec file is updated to point to the latest ECS task Definition. AWS CodeDeploy kicks off
a Blue / Green deployment and deploys the latest Docker image to Elastic Container Service running on EC2 instances.
Once traffic is shifted to the new version of the application, CodeDeploy completes successfully and the latest version of
the Flask application is running on ECS.
After that, You need to create the virtual machine instance with google compute engine first.
Here are the steps to create VM instance on Google Console :
SSH Window
Here is a step by step guidance for you:
1. Update The Debian Package list: Sudo apt-get update
2. Install Git: Sudo apt-get install git
3. Install python :
sudo apt-get install python3-setuptools python3-dev build-essential
4. Install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Sudo python3 get-pip.py
SSH Window
SSH Window
SAMPLE APP
The Python sample app is a restaurant review app that saves restaurant and review data in MongoDB. For an example of
a web app using PostgreSQL, see Deploy a Python web app to Azure with managed identity.
At the end of the tutorial, you'll have a restaurant review app deployed and running in Azure that looks like the
screenshot below.
When we deal with “BIG” data, as the name suggests dealing with a large amount of data is a daunting task.MapReduce is
a built-in programming model in Apache Hadoop. It will parallel process your data on the cluster.
This article will look into how MapReduce works with an example dataset using Python.
M APREDUCE: A NALYSE BIG DATA
MapReduce will transform the data using Map by dividing data into key/value pairs, getting the output from a map as an
input, and aggregating data together by Reduce.MapReduce will deal with all your cluster failures.
HOW M APREDUCE WORKS
To understand MapReduce, let’s take a real-world example. You have a dataset that consists of hotel reviews and
ratings. Now you need to find out how many reviews each rating.
Client node will submit MapReduce Jobs to The resource manager Hadoop YARN.
PREREQUISITES
1. Install Python
2. Install Hadoop
3. Install MRJob
pip install mrjoborpython setup.py test && python setup.py install
Here we are having a Job called ‘NoRatings’ consisting of a Mapper function, a Reducer function, and
a definition. A Step function is used to define our functions for mappers and reducers in our job.
Note: Used yield to return statement in a function.
Here is the full code which is saved as NoRatings.py
from mrjob.job import MRJob
from mrjob.step import MRStep
import csv#split by ,
columns = 'Review,Rating'.split(',')class NoRatings(MRJob):
def steps(self):
return[
MRStep(mapper=self.mapper_get_ratings,
reducer=self.reducer_count_ratings)
]
CONCLUSION
As you have seen MapReduce is necessary to deal with a large amount of data.
A. DJANGO
Django Python is a framework for perfectionists with deadlines. With it, you can build better Web apps in much less time,
and in less code. Django is known for how it focusses on automating. It also believes in the DRY (Don’t Repeat Yourself)
principle.
Django was originally developed for content-management systems, but is now used for many kinds of web applications.
This is because of its templating, automatic database generation, DB access layer, and automatic admin interface
generation. It also provides a web server for development use.
Giant companies that use Django Python are- Instagram, Pinterest, Disqus, Mozilla, The Washington Times, and
Bitbucket. In fact, when we think of the terms ‘framework’ and ‘Python’, the first thing that comes to our minds is Django.
A Python non full-stack framework will provide the base application server. This either runs as its own independent
process, upon Apache, or in other environments. Let’s look at the most popular ones.
A . P YTHON B OTTLE
Bottle is a simple and fast microframework that you can use to create small Web applications. It provides request-
dispatching routes with URL-parameter support, templates, key/value databases, and a built-in HTTP server. It also offers
adapters for third-party WSGI/HTTP-server and template engines. This is all in a single file; there are no dependencies
except the Python Standard Library.
B . C HERRY PY