Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Python for admin automation

Python for the daily work of an admin: files and folders, regex, CSV, JSON and YAML, system commands, APIs, logging, command-line tools and schedules.

Course by
Python Software Foundation
Course code
Python
Version
Python 3.12
Lessons
48

These summaries follow the public outline of the course. I wrote every lesson in my own words and tested the commands on RHEL 10. They are not Red Hat training material. Take the official course for the full content and the hands-on labs.

Next course: MLOps

Parts and chapters

Part 1

Language basics

  1. 1Write your first Python scriptsPython basics6 lessons
    Lessons
    1. 1.1 Run Python
    2. 1.2 Isolate packages with a virtual environment
    3. 1.3 Use values and variables
    4. 1.4 Decide with if
    5. 1.5 Repeat with for and while
    6. 1.6 Write functions
  2. 2Work with lists, dictionaries and stringsData structures6 lessons
    Lessons
    1. 2.1 Use lists
    2. 2.2 Use dictionaries
    3. 2.3 Use sets and tuples
    4. 2.4 Handle strings
    5. 2.5 Write comprehensions
    6. 2.6 Count and group with collections

Part 2

Work with the system

  1. 3Read, write and organise files and foldersFiles and folders5 lessons
    Lessons
    1. 3.1 Work with paths
    2. 3.2 Read and write text files
    3. 3.3 Copy, move and delete
    4. 3.4 Clean up old files
    5. 3.5 Make archives
  2. 4Find and extract text with regular expressionsPattern matching with regular expressions4 lessons
    Lessons
    1. 4.1 Search and match
    2. 4.2 Find all matches
    3. 4.3 Use named groups
    4. 4.4 Replace and split
  3. 5Read and write CSV, JSON and YAMLData formats4 lessons
    Lessons
    1. 5.1 Read and write CSV
    2. 5.2 Read and write JSON
    3. 5.3 Read and write YAML
    4. 5.4 Use TOML and INI
  4. 6Run commands and read the systemSystem administration with Python5 lessons
    Lessons
    1. 6.1 Run commands with subprocess
    2. 6.2 Read environment and arguments
    3. 6.3 Check disks, memory and processes
    4. 6.4 Check the network
    5. 6.5 Return exit codes

Part 3

Real tools

  1. 7Talk to web APIsWeb requests and REST APIs5 lessons
    Lessons
    1. 7.1 Make GET requests
    2. 7.2 Send data and use tokens
    3. 7.3 Handle pages
    4. 7.4 Retry on errors
    5. 7.5 Check many websites
  2. 8Handle errors and write logsExceptions and logging5 lessons
    Lessons
    1. 8.1 Catch exceptions
    2. 8.2 Raise your own errors
    3. 8.3 Write logs with logging
    4. 8.4 Log to the journal
    5. 8.5 Rotate log files
  3. 9Build command-line tools and schedule themCommand-line tools and scheduling4 lessons
    Lessons
    1. 9.1 Parse arguments with argparse
    2. 9.2 Install the tool for everyone
    3. 9.3 Schedule it with a systemd timer
    4. 9.4 Test your code
  4. 10Build a daily server reportHands-on project4 lessons
    Lessons
    1. 10.1 Plan the report
    2. 10.2 Write the main script
    3. 10.3 Run it every morning
    4. 10.4 Publish it