python for devops/sre/platform engineer
Agar tumhara goal DevOps + SRE + Automation hai, to modules random order me mat seekho. Ek roadmap follow karo. Har module ka real-world use hona chahiye.
Phase 1: File & System Automation (Must Know)
Ye modules har DevOps engineer use karta hai.
| Module | Kyu seekhna hai? | Example |
|---|---|---|
✅ pathlib |
Files/Folders manage karna | Logs, configs, backups |
✅ os |
Environment variables, process info | os.environ, os.chdir() |
✅ shutil |
Copy, move, zip, delete | Backup scripts |
✅ subprocess |
Linux commands run karna | kubectl, docker, git |
✅ glob |
Pattern se files find karna | *.log, *.yaml |
✅ tempfile |
Temporary files | Installers, scripts |
✅ zipfile / tarfile |
Archives banana | Log rotation |
Phase 2: Data Handling
Automation scripts me data bahut aata hai.
| Module | Use |
|---|---|
✅ json |
APIs aur config files |
✅ yaml (PyYAML) |
Kubernetes, Ansible |
✅ csv |
Reports |
✅ configparser |
INI config files |
✅ tomllib (Python 3.11+) |
TOML configs |
Example:
import json
with open("config.json") as f:
config = json.load(f)
Phase 3: Dates & Logging
Har automation script me logging honi chahiye.
| Module | Use |
|---|---|
✅ datetime |
Time calculations |
✅ time |
Sleep, timestamps |
✅ logging |
Professional logging |
Instead of:
print("Deployment started")
Use:
import logging
logging.info("Deployment started")
Ye production-level approach hai.
Phase 4: Shell Automation (Most Important)
⭐ subprocess
Ye DevOps ki backbone hai.
Example:
import subprocess
result = subprocess.run(
["kubectl", "get", "pods"],
capture_output=True,
text=True
)
print(result.stdout)
Isse tum Python se:
Docker
Kubernetes
Terraform
Git
Linux commands
AWS CLI
sab chala sakte ho.
Phase 5: HTTP APIs
Almost har cloud tool API provide karta hai.
requests
import requests
response = requests.get("https://api.github.com")
print(response.status_code)
Use cases:
GitHub API
Jira
Jenkins
Grafana
Prometheus
AWS APIs
Slack notifications
Phase 6: CLI Scripts
Professional scripts arguments lete hain.
argparse
Example:
python deploy.py --env prod --region us-east-1
Python:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--env")
args = parser.parse_args()
print(args.env)
Phase 7: Environment Variables
Secrets kabhi code me nahi likhte.
import os
token = os.getenv("GITHUB_TOKEN")
Ye DevOps ka standard practice hai.
Phase 8: Regex
re
Logs parse karne ke liye.
Example:
ERROR
WARNING
INFO
Python:
import re
re.findall(r"ERROR", log)
Phase 9: Concurrency
SRE me multiple servers ek saath check karne padte hain.
Modules:
threadingconcurrent.futuresasyncio
Example:
100 servers ka health check parallel me karna.
Phase 10: Cloud SDKs
After Python basics:
AWS
boto3
Azure
azure-sdk
Google Cloud
google-cloud
Libraries Every DevOps Engineer Should Know
requestsPyYAMLboto3paramiko(SSH)fabricjinja2(templates)clickortyper(CLI tools)rich(beautiful terminal output)python-dotenv
Agar main tumhare liye roadmap banaun to ye hoga:
Python Basics
│
▼
pathlib
│
▼
os
│
▼
shutil
│
▼
subprocess ⭐⭐⭐⭐⭐
│
▼
json
│
▼
logging
│
▼
datetime
│
▼
argparse
│
▼
requests ⭐⭐⭐⭐⭐
│
▼
PyYAML ⭐⭐⭐⭐⭐
│
▼
Regex
│
▼
Threading
│
▼
boto3
│
▼
Docker Automation
│
▼
Kubernetes Automation
Mere suggestion ke hisaab se next module subprocess hona chahiye.
Reason simple hai: DevOps aur SRE me 80% automation existing command-line tools (kubectl, docker, git, systemctl, helm, terraform, aws) ko automate karne se hi hoti hai. subprocess seekhne ke baad tum Python se almost har CLI tool control kar paoge.
Uske baad sequence rakho:
subprocessjsonloggingargparserequestsPyYAML
Ye sequence follow karoge to tum production-grade automation scripts likhne ke liye strong foundation bana loge.