Automation and scripting with Python

If you copy the same files, fill the same spreadsheet or click the same buttons every week, a script can do it for you. We learn just enough Python to be autonomous, then spend the rest of the time on what automation really needs: files, formats, other programs, databases and the web.

Duration: 3 or 4 days · Level: beginner

For: people with little programming experience who want to automate tasks, or who have scripting needs (system administration, test benches, etc.).

Prerequisites: understanding what automation is about. Having written a few scripts is a plus.

Automation and scripting with Python

Day 1 — Discovering Python

  • A refresher on the terminal
  • Installing Python: good practices
  • Using the interpreter
  • A first "Hello World" program
  • Variables: declaration and assignment
  • Basic types: int, float, str, bool
  • Arithmetic operators
  • Conditions and control flow
  • Understanding errors and the stack trace
  • Lists and tuples
  • Looping with while and for
  • Dictionaries and sets

Day 2 — Structuring a program

  • Functions
  • The import system
  • Writing your own modules
  • Reading and writing a file
  • Walking the file system with pathlib
  • Accumulating and counting
  • Filtering, with and without list comprehensions
  • Ordering your data
  • Exceptions
  • try/except/finally
  • Using a debugger

Day 3 — Automation

  • uv to manage your scripts
  • Installing third-party libraries
  • Parsing arguments with argparse
  • Environment variables
  • Running another program with subprocess
  • Keeping secrets in a keyring
  • CSV, JSON, TOML, YAML and XML files
  • Connecting to an SQL database
  • A refresher on the HTTP protocol
  • The basics of web requests
  • Querying a remote API

Day 4 — Optional: going further

  • Keeping a journal of your scripts with logging
  • Clean and safe data with Pydantic
  • Generating files from jinja templates
  • Normalising database queries with an ORM
  • Generating fake data with Faker
  • Reacting to file system changes with watchfiles
  • Running long tasks in queues with huey
  • Caching big datasets with diskcache

Elevate Your Python Proficiency!