Python Overview


Python Modules
A file with reusable Python code
(functions, classes, variables).
Example: custom
.py
files orsys, math
module
Python Package
A
folder with related modules
, including an__init__.py
file.Example:
numpy
or custom module directories.pip
is a tool in Python toinstall & manage Python packages
or libraries from the Python Package Index(PyPI)
.
Python Virtual Environment
Isolated environment
for project-specific dependencies.Create:
python -m venv <env_name>
Activate:
source <env_name>/bin/activate
Command Line Args
Python in build sys module
import sys # python inbuild sys module, which is used for command line args
num1 = float(sys.argv[1])
Environment Variables
Env vars used for sensitive data, which we can’t hardcoded:
API keys
passwords
tokens
certificates
Declare Env vars in terminal:
export password=”pass@123”
Code:
import os
pass = os.getenv("password")
File Operation of Windows
Open:
open()
with modes (r
,w
, etc.), e.g.,open("file.txt", "r")
.Read: Use
read()
,readline()
, orreadlines()
to fetch content.Write: Use
write()
orwritelines()
in modes likew
ora
.Close: Use
close()
orwith
for auto-closing.
Module
Requests
The requests
module in Python simplifies HTTP requests to interact with web servers.
Purpose: Send HTTP methods (GET, POST, etc.) and handle responses via
API
.Features: Manage headers, cookies, auth, and work with
JSON or text
.Install:
pip install requests
import requests
response = requests.get("https://example.com")
print(response.status_code) # Status code
print(response.text) # Response body
Boto3
AWS SDK for Python
to interact programmatically with AWS services.Ideal for
automating AWS workflows
and managing resources efficientlyBuilding serverless applications
with services like Lambda and DynamoDB.
import boto3
# Initialize S3 client
s3 = boto3.client('s3')
# Upload a file to S3
s3.upload_file('local_file.txt', 'my-bucket', 'remote_file.txt')
Flask
It’s a lightweight web framework
in Python used to build web applications
with added functionality.
Decorators:
It’s a
special function
in Python used to modify the behaviour of another function.It written
above function
with@
symbol.
from flask import Flask
app = Flask(__name__)
@app.route("/greet") # Flask decorator that connects a URL('/greet') route to a function
def greet():
return "Greetings from Flask!"
if __name__ == "__main__":
app.run()
Subscribe to my newsletter
Read articles from KALPESH MOHANTA directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

KALPESH MOHANTA
KALPESH MOHANTA
👋 Hi there! Welcome to my DevOps adventure! 🚀 I'm Kalpesh, a DevOps Engineer, and I'm thrilled to share my journey in the dynamic world of DevOps and Cloud Technologies. 🌐 🔧 Tech Arsenal: CI/CD Automation: Streamlining workflows for seamless deployments. Containers & Orchestration: Docker & Kubernetes. Cloud Platforms: Azure, AWS. Version Control: Git. Configuration Management: YAML, Linux commands. 🚀 My Journey: I've had the privilege to work on diverse projects, including a notable deployment for PepsiCo. My expertise spans CI/CD automation, containerization, cloud services, and scripting to enhance system performance and reliability. 💡 Why Follow Me? Join me as I delve into: Cutting-edge DevOps practices. Automation techniques. Cloud innovations. Tips & tricks for aspiring DevOps professionals. 🤝 Connect & Collaborate: Let's build, learn, and innovate together. Whether you're a fellow tech enthusiast, a professional looking to share insights, or someone eager to learn, let's connect and grow in this vibrant community. 📢 Follow my LinkedIn & Hashnode blog for insights, tutorials, and updates. Together, we'll embrace the ever-evolving DevOps landscape!