PPFD_3
PPFD_3
(303105257)
Anand Jawdekar
mypackage/
│
├── __init__.py
├── module1.py
└── module2.py
Code Example
# module1.py
def greet(name):
print(f"Hello, {name}!")
# module2.py
def add(a, b):
return a + b
from mypackage import module1, module2
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
2. Panda3D
Description: An open-source game engine developed by Disney for 3D rendering and game
development.
Key Features:
Suitable for both 3D and 2D games.
Built-in physics engine.
Great for rendering complex graphics.
3. Godot (with Python scripting)
Description: Open-source game engine supporting both 2D and 3D games.
Key Features:
Visual scripting and Python-like scripting language (GDScript).
Lightweight and efficient.
Active community support.
4. PyOpenGL
Description: A Python wrapper for the OpenGL API used for 3D graphics rendering.
Key Features:
Direct access to GPU rendering.
Supports complex 3D graphics.
Ideal for creating 3D environments and visual effects.
5. Arcade
Description: A Python library for creating 2D games with an easy-to-learn API.
Key Features:
Ideal for small games and educational purposes.
Simple API for drawing shapes, sprites, and animations.
Better performance for 2D rendering than Pygame.
Example
pip install arcade
import arcade
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.plot(x, y)
plt.show()
Popular Python Libraries for Data Analysis
4. Seaborn
Purpose: Statistical data visualization built on top of Matplotlib.
Key Features:
Beautiful and informative statistical graphs.
Integration with Pandas DataFrames.
Plot distributions, regression models, and heatmaps.
Installation: pip install seaborn
import seaborn as sns
import pandas as pd
print(norm.pdf(0))
Popular Python Libraries for Data Analysis
6. Plotly
Purpose: Interactive and web-based data visualization.
Key Features:
Interactive plots and dashboards.
Supports various chart types (scatter, bar, pie).
Integration with Dash for web applications.
Installation: pip install plotly
import plotly.express as px
data = [1, 2, 3, 4, 5]
model = sm.OLS(data, [1, 2, 3, 4, 5]).fit()
print(model.summary())
Popular Python Libraries for Data Analysis
TensorFlow & PyTorch
Purpose: Machine learning and deep learning.
TensorFlow: For end-to-end machine learning pipelines.
PyTorch: For flexible deep learning model building.
Installation:
pip install tensorflow
pip install torch
Popular Python Libraries for Web Development
Python is a versatile language widely used in web development, offering powerful libraries and
frameworks for building web applications, APIs, and more.
1. Django
Type: Full-Stack Web Framework
Purpose: Build secure, scalable, and robust web applications quickly.
Key Features:
Built-in admin interface
ORM (Object-Relational Mapping)
Authentication and security features
Installation: pip install django
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello, Django!")
Popular Python Libraries for Web Development
2. Flask
Type: Micro Web Framework
Purpose: Lightweight framework for building small to medium-sized web apps and APIs.
Key Features:
Simple and flexible architecture
Support for Jinja2 templating
Integrated unit testing
Installation: pip install flask
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return "Hello, Flask!"
if __name__ == '__main__':
app.run()
Popular Python Libraries for Web Development
3. FastAPI
Type: Web Framework for APIs
Purpose: Build fast and efficient APIs with automatic documentation.
Key Features:
Automatic Swagger documentation
Asynchronous support
Type hints for data validation
Installation: pip install fastapi uvicorn
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello, FastAPI!"}
Popular Python Libraries for Web Development
4. Pyramid
Type: Full-Stack Web Framework
Purpose: Build complex applications with flexibility and modular design.
Key Features:
Highly customizable architecture
Supports both small and large applications
Built-in authentication system
Installation: pip install pyramid
Example
from pyramid.config import Configurator
from wsgiref.simple_server import make_server
def hello_world(request):
return Response('Hello, Pyramid!')
@route('/')
def home():
return "Hello, Bottle!"
run(host='localhost', port=8080)
Popular Python Libraries for Web Development
6. Tornado
Type: Asynchronous Web Framework
Purpose: Build scalable, non-blocking web servers and applications.
Key Features:
Handles thousands of concurrent connections
Ideal for WebSockets
Non-blocking I/O
Installation: pip install tornado
Example
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, Tornado!")
def make_app():
return tornado.web.Application([(r"/", MainHandler)])
if __name__ == "__main__":
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
Popular Python Libraries for Web Development
7. Requests
Type: HTTP Library
Purpose: Simplify making HTTP requests (e.g., REST APIs).
Key Features:
Easy-to-use syntax for API calls
Supports SSL, cookies, sessions
Installation: pip install requests
import requests
response = requests.get('https://api.github.com')
print(response.status_code)
Popular Python Libraries for Web Development
8. SQLAlchemy
Type: Database ORM
Purpose: Handle database operations efficiently.
Key Features:
ORM for mapping Python objects to database tables
Database abstraction
Installation: pip install sqlalchemy
from sqlalchemy import create_engine, Column, Integer, String, Base
engine = create_engine('sqlite:///test.db')
Base.metadata.create_all(engine)
Popular Python Libraries for Web Development
9. BeautifulSoup
Type: Web Scraping Library
Purpose: Parse HTML and XML documents.
Key Features:
Extract data from websites
Parse HTML and XML
Installation: pip install beautifulsoup4
from bs4 import BeautifulSoup
@app.task
def add(x, y):
return x + y
PyCharm IDE
PyCharm makes it seamless to integrate with Git, enabling developers to manage their code versions
directly from the IDE.
PyCharm is a cross-platform IDE that provides consistent experience on the Windows, macOS, and
Linux operating systems.
PyCharm is available in two editions: Professional, and Community. The Community edition is an
open-source project, and it's free, but it has fewer features. The Professional edition is commercial,
and provides an outstanding set of tools and features.
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
Cont..
4. Run Tests in PyCharm
Right-click on the test file.
Select Run 'pytest in test_example.py'
View results in the Run Panel.
5. Debug Tests in PyCharm
Right-click on the test and select Debug 'pytest in test_example.py'
Set breakpoints to inspect variables.
6. Test Coverage
Go to Run > Run with Coverage
Analyze the coverage report to identify untested code.
What is MongoDB?
In today’s data-driven world, the ability to efficiently store and manage large amounts of data is
crucial. MongoDB, a powerful NoSQL database, has become a go-to choice for developers looking for
flexibility, scalability, and performance. MongoDB is a document-oriented NoSQL database system
that provides high scalability, flexibility, and performance. Unlike standard relational databases,
MongoDB stores data in a JSON document structure form. This makes it easy to operate with
dynamic and unstructured data and MongoDB is an open-source and cross-platform database
System.
It means that MongoDB isn’t based on the table-like relational database structure but provides an
altogether different mechanism for the storage and retrieval of data. This format of storage is called
BSON ( similar to JSON format).
Database
Database is a container for collections.
Each database gets its own set of files.
A single MongoDB server can has multiple databases.
Language Support by MongoDB
MongoDB currently provides official driver support for all popular programming languages like C, C++
, Rust, C#, Java, Node.js, Perl, PHP, Python, Ruby, Scala, Go and Erlang.
Collection
Collection is a group of documents.
Collection is equivalent to RDBMS table.
A collection consist inside a single database.
Collections do not enforce a schema.
A Collection can have different fields within a Documents.
Why Use MongoDB?
Document Oriented Storage − Data is stored in the form of JSON documents.
Index on any attribute: Indexing in MongoDB allows for faster data retrieval by creating a searchable
structure on selected attributes, optimizing query performance.
Replication and high availability: MongoDB’s replica sets ensure data redundancy by maintaining
multiple copies of the data, providing fault tolerance and continuous availability even in case of
server failures.
Auto-Sharding: Auto-sharding in MongoDB automatically distributes data across multiple servers,
enabling horizontal scaling and efficient handling of large datasets.
Big Data and Real-time Application: When dealing with massive datasets or applications requiring
real-time data updates, MongoDB’s flexibility and scalability prove advantageous.
Why Use MongoDB?
Rich queries: MongoDB supports complex queries with a variety of operators, allowing you to
retrieve, filter, and manipulate data in a flexible and powerful manner.
Fast in-place updates: MongoDB efficiently updates documents directly in their place, minimizing
data movement and reducing write overhead.
Professional support by MongoDB: MongoDB offers expert technical support and resources to help
users with any issues or challenges they may encounter during their database operations.
Internet of Things (IoT) Applications: Storing and analyzing sensor data with its diverse formats
often aligns well with MongoDB’s document structure.
Where to Use MongoDB?
Mobile and Social Infrastructure
Data Hub
Previous Pag
Big Data
User Data Management
Content Management and Delivery
Prerequisites for the MongoDB
it is suitable if you have some prior knowledge of Databases, Frontend development, Text editor and
execution of programs, etc. It will be beneficial if you have a basic understanding of database
fundamentals because we’ll be developing high-performance databases (RDBMS).
MongoDB database features
Document Oriented: MongoDB stores the main subject in the minimal number of documents and
not by breaking it up into multiple relational structures like RDBMS. For example, it stores all the
information of a computer in a single document called Computer and not in distinct relational
structures like CPU, RAM, Hard disk etc.
Indexing: Without indexing, a database would have to scan every document of a collection to select
those that match the query which would be inefficient. So, for efficient searching Indexing is a must
and MongoDB uses it to process huge volumes of data in very less time.
Scalability: MongoDB scales horizontally using sharding (partitioning data across various servers).
Data is partitioned into data chunks using the shard key and these data chunks are evenly distributed
across shards that reside across many physical servers. Also, new machines can be added to a
running database.
MongoDB database features
Replication and High Availability: MongoDB increases the data availability with multiple copies of
data on different servers. By providing redundancy, it protects the database from hardware failures.
If one server goes down, the data can be retrieved easily from other active servers which also had
the data stored on them.
Aggregation: Aggregation operations process data records and return the computed results. It is
similar to the GROUPBY clause in SQL. A few aggregation expressions are sum, avg, min, max, etc
MongoDB – Database, Collection, and Document
Databases, collections, documents are important parts of MongoDB without them you are not able
to store data on the MongoDB server. A Database contains one or more collections, and a collection
contains documents and the documents contain data, they are related to each other.
Cont..
Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A collection
exists within a single database. Collections do not enforce a schema. Documents within a collection
can have different fields. Typically, all documents in a collection are of similar or related purpose.
A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means
that documents in the same collection do not need to have the same set of fields or structure, and
common fields in a collection's documents may hold different types of data.
Sample document
Employee
{
“name”: amit,
“age”:27,
“city”:Noida,
“Identity”:{
“aadhar”:222211113333,
“pan”: TUFEU5905D”
}
}
Relationship of RDBMS terminology with MongoDB
RDBMS MongoDB
Database Database
Table Collection
Tuple/Row Document
column Field
Table Join Embedded Documents
Primary Key Primary Key (Default key _id provided by MongoDB itself)
mysqld/Oracle mongod
mysql/sqlplus mongo
Install MongoDB On Windows
To install MongoDB on Windows, first download the latest release of MongoDB from
https://www.mongodb.com/download-center.
Install MongoDB On Windows
Enter the required details, select the Server tab, in it you can choose the version of MongoDB,
operating system and, packaging as:
Install MongoDB On Windows
Now install the downloaded file, by default, it will be installed in the folder C:\Program Files\.
MongoDB requires a data folder to store its files. The default location for the MongoDB data
directory is c:\data\db. So you need to create this folder using the Command Prompt. Execute the
following command sequence.
C:\>md data C:\md data\db Then you need to specify set the dbpath to the created directory
in mongod.exe. For the same, issue the following commands.
In the command prompt, navigate to the bin directory current in the MongoDB installation folder.
Suppose my installation folder is C:\Program Files\MongoDB
C:\Users\XYZ>d:cd C:\Program Files\MongoDB\Server\4.2\bin C:\Program Files\MongoDB\Server\
4.2\bin>mongod.exe --dbpath "C:\data"
Install MongoDB On Windows
This will show waiting for connections message on the console output, which indicates that the
mongod.exe process is running successfully.
Now to run the MongoDB, you need to open another command prompt and issue the following
command.
C:\Program Files\MongoDB\Server\4.2\bin>mongo.exe MongoDB shell version v4.2.1 connecting to:
mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session:
session { "id" : UUID("4260beda-f662-4cbe-9bc7-5c1f2242663c") } MongoDB server version: 4.2.1 >
This will show that MongoDB is installed and run successfully. Next time when you run MongoDB,
you need to issue only commands.
C:\Program Files\MongoDB\Server\4.2\bin>mongod.exe --dbpath "C:\data" C:\Program Files\
MongoDB\Server\4.2\bin>mongo.exe
MongoDB CRUD Operations
CRUD Operations (Create, Read, Update, and Delete) are the basic set of operations that allow users
to interact with the MongoDB server.
As we know, to use MongoDB we need to interact with the MongoDB server to perform certain
operations like entering new data into the application, updating data into the application, deleting
data from the application, and reading the application data.
1. Create Operations
The create or insert operations are used to insert or add new documents in the collection. If a
collection does not exist, then it will create a new collection in the database.
You can perform, create operations using the following methods provided by the MongoDB:
Method Description
db.collection.insertOne() It is used to insert a single document in the collection.
Method Description
db.collection.find() It is used to retrieve documents from the collection.
Method Description
db.collection.updateOne() It is used to update a single document in the collection that satisfy the given criteria.
db.collection.updateMany() It is used to update multiple documents in the collection that satisfy the given criteria.
db.collection.replaceOne() It is used to replace single document in the collection that satisfy the given criteria.
4. Delete Operations
The delete operation are used to delete or remove the documents from a collection. You can perform
delete operations using the following methods provided by the MongoDB:
Method Description
It is used to delete a single document from the collection that satisfy the
db.collection.deleteOne() given criteria.
It is used to delete multiple documents from the collection that satisfy the
db.collection.deleteMany() given criteria.