Learn to write Python that survives production: safe scripts, resilient API calls, tests, and CLI tools that SRE teams rely on during incidents.
It is the morning after acme-shop's sale-day incident. Your lead asks a simple question: how much error budget does checkout-service have left?
Python basics you will use in every script Operational scripts lean on a small set of Python building blocks: strings, numbers, lists, dictionaries...
Replacing print with logging The logging module adds a timestamp and a severity level to every message, which print() cannot do.
Calling commands with subprocess The subprocess module runs shell commands from Python.
Making a request and checking the result The requests library is the standard way to call an HTTP API.
Setting a timeout on every call By default, requests waits forever for a response.
It is the morning after acme-shop's sale-day incident.
Python basics you will use in every script Operational scripts lean on a small set of Python building blocks: strings...
Replacing print with logging The logging module adds a timestamp and a severity level to every message, which print()...
Calling commands with subprocess The subprocess module runs shell commands from Python.
Making a request and checking the result The requests library is the standard way to call an HTTP API.
Setting a timeout on every call By default, requests waits forever for a response.
Using sqlite3 for quick local data Python includes SQLite, a database that lives in one file or in memory, which makes...
Writing unit tests with pytest A unit test checks one function in isolation, with no server or database.
Turning a script into a tool with argparse A command-line tool takes its input as arguments, answers --help, and can be...
Why one at a time is too slow Checking a thousand servers one after another takes a thousand times the wait for a...
Isolating dependencies with virtual environments A virtual environment is a private Python installation for one...
Preparing the project and the endpoint You will build budget-report, a tool that reads a success rate from an endpoint...
Quick reference Keep this table next to you when you write your next operational script.
Roles that use the skills in this module.
Site Reliability Engineer
DevOps Engineer
Platform Engineer
Cloud Engineer
Not a software engineer sheet. Every problem comes from real DevOps, SRE, Platform and Cloud interviews, from your first script to a system you build yourself.
Open the Coding SheetBash is great for short one-liners. Once a task needs retries, error handling, structured output, tests, or has to run unattended every night, Python is easier to make safe and to hand to a teammate.
No. Most SRE checks spend their time waiting on the network, and a thread pool handles that well with far less complexity. Reach for asyncio only when you have a real reason, such as thousands of simultaneous connections.
No. Retry temporary problems such as timeouts, connection errors, 429, and 5xx responses. Fail immediately on client errors such as 401 or 404, because they will fail the same way every time.
Read them from environment variables or a secrets manager at run time, and never write them into code, config files, or log lines. If a secret is ever committed to Git, treat it as leaked and rotate it.