Your DevOps study space

Real explanations. Videos with tests. Fresh exams every time. Keep the streak alive and watch the XP stack up.

Modules, files & Python for DevOps · Python Docs · StackwisePlanDevOps Modules, files & Python for DevOps · Python Docs · StackwiseCodePython Modules, files & Python for DevOps · Python Docs · StackwiseBuildDocker Modules, files & Python for DevOps · Python Docs · StackwiseTestDevOps Modules, files & Python for DevOps · Python Docs · StackwiseReleaseGit Modules, files & Python for DevOps · Python Docs · StackwiseDeployKubernetes Modules, files & Python for DevOps · Python Docs · StackwiseOperateLinux Modules, files & Python for DevOps · Python Docs · StackwiseMonitorDevOps

Pick a topic

Eight tracks, each with docs, a cheat sheet, videos and tests.

How it works

One loop, repeated until it sticks.

Jump back in

Picked up from where you left off.

Free forever

Your DevOps journey starts with one click.

Sign in with Google or GitHub to open every chapter, video, test and challenge. Your progress is saved wherever you learn.

Modules, files & Python for DevOps

Real scripts read files, talk to APIs and use other people's code. This chapter covers how Python pulls in libraries, how it handles files and JSON, and the kinds of automation DevOps engineers actually write with it.

Modules and packages

A module is just a .py file; import loads it so you can use what's inside. Python ships with a big standard library (os, json, datetime, subprocess, pathlib…), and thousands more third-party packages live on PyPI, installed with pip.

monitor.pyyour scriptyour own filesutils.pyfrom utils import ...standard libraryos, json, pathlibcomes with PythonPyPI packagesrequests, boto3pip install firstimport
All three look the same in code: import name. Only PyPI packages need installing first, ideally into the project's virtual environment.
import os                       # use as os.getenv(...)
from datetime import datetime   # import one name directly
import subprocess as sp         # import under a shorter alias

$ pip install requests boto3    # third-party packages from PyPI

Different projects need different package versions, so each project should get its own virtual environment: python3 -m venv .venv, then source .venv/bin/activate. pip freeze > requirements.txt records the exact versions, and pip install -r requirements.txt recreates them on another machine.

When a file is run directly, the special variable __name__ is "__main__"; when it's imported it's the module's name. So code under if __name__ == "__main__": runs only when you execute the file, not when another script imports its functions.

Reading and writing files

with open("hosts.txt") as f:            # "r" (read) is the default
    for line in f:
        print(line.strip())

with open("report.txt", "w") as f:      # "w" overwrites the file
    f.write("all good\n")

with open("app.log", "a") as f:         # "a" appends to the end
    f.write("deploy finished\n")

with closes the file automatically when the block ends, even if an error happens in the middle.

JSON: the format APIs speak

JSON maps straight onto Python: objects become dicts, arrays become lists. json.load(f) / json.dump(data, f) work with files; json.loads(text) / json.dumps(data) work with strings.

What Python is used for in DevOps

  • Scripting and automation: replacing long, fragile shell scripts: rotating logs, cleaning up old backups, renaming thousands of files.
  • Talking to APIs: the requests library calls any REST API. The Nana course ends with a script that lists projects from the GitLab API.
  • Cloud automation: AWS's boto3 library creates and manages resources from code. The Cloud Champ video launches an EC2 server and rotates a database password with it.
  • Glue for tools: Ansible is written in Python, and CI pipelines often call small Python scripts for checks and reports.
  • Monitoring: small web apps (for example with Flask) that report CPU, memory or disk use, or send alerts.
import requests

resp = requests.get("https://api.github.com/repos/python/cpython", timeout=10)
resp.raise_for_status()               # error on 4xx/5xx
data = resp.json()                    # JSON body -> dict
print(data["stargazers_count"])

import boto3
ec2 = boto3.client("ec2", region_name="eu-central-1")
for r in ec2.describe_instances()["Reservations"]:
    for i in r["Instances"]:
        print(i["InstanceId"], i["State"]["Name"])

Questions

Pick an answer. Get it wrong and you can try again right away, no waiting. 10 questions per topic - pick a filter below, then use Recreate questions for a fresh set on that topic.

Fresh questions every time

Exam

A mixed test across the whole site, shuffled so you never know which topic comes next. When you submit, every mistake comes with the reason and a jump to the exact moment in the video that explains it.

30 questions 6 topics 20 minute limit Up to 70 XP
1–4 answer · ←→ move
History

Essay

0 / 200-250 words
Sample answer
History
0:00 / 0:00
Not started

on YouTube
Subscribe

Topic progress

Activity

Achievements

Settings

Your profile and your account.

Profile details

* Required. Saved in this browser until you sign in.

Letters, numbers, dots, dashes and underscores.
0 / 160

Account

Checking…

App

Install Stackwise on your phone or computer. It opens in its own window from your home screen, and the Docs and cheat sheets you've opened keep working without internet.

Only admins can see this

Dashboard

Sign-ups, activity, messages and reviews in one place.

Prove it

Certificates

Pass a topic's test and get a certificate with its own public page you can share or add to LinkedIn. Each test is 10 questions drawn at random and graded on the server; you need 8 right, you have 15 minutes, and you get one try per topic a day.

From first command to production

Linux for DevOps

A path through Linux the way DevOps engineers use it: ten stages, every command explained with its flags, examples, real output and mistakes, the combinations engineers chain together, and incidents worked through step by step. Practise everything in a safe lab folder.

Before the interview

Interview prep

Questions that come up in real DevOps interviews, with the kind of answer that lands. Say yours out loud first, then compare. Each one links to the chapter that goes deeper.

    Private to you

    My notes

    Everything you wrote down while watching and reading, in one place. Saved to your account, never shown to anyone.