Python training — advanced

Object-oriented, functional and metaprogramming

⏱ 3 days 👥 ≤ 10 people 📍 On site or remote 🌐 English or French 🎯 Advanced 👤 Experienced Python developers 🏢 In-company ★ 4.93/5

A module offered as a complement to the data science courses, or as a standalone course depending on your needs.

Most Python developers reach a plateau after a few years: they write code that works, but do not master the mechanisms that make Python so expressive. When they read the source code of Pandas, Polars, SQLAlchemy or pytest, they run into decorators, descriptors, metaclasses — and they lose track.

This course takes them past that point. It explores the advanced paradigms of the language: custom generators and iterators, decorators and closures, descriptors, metaclasses. These are the notions that let you understand the major Python libraries and write generic, reusable and maintainable code.

After this course, your staff will be able to

  • Distinguish and use static, class and instance methods in the right context
  • Implement decorators using closures and function attributes
  • Design custom iterators with generator functions
  • Control attribute access with properties and descriptors
  • Understand the metaclass protocol and its relation to Python's type system
  • Read and understand the source code of the major libraries of the Python ecosystem

Detailed program

Module 1 — Static and class methods

A refresher on classes and instances. Functions and bound methods. Static methods: uses and limits. Class methods: canonical uses (alternative constructors, polymorphism). Choosing the right form for the context.

Module 2 — Decorators

Callables, functions and closures: the underlying mechanisms. Designing decorators as functions, then as classes. Function attributes and preserving metadata with functools.wraps. Class decorators. Concrete applications: timer, watchdog, memoization.

Module 3 — Iterators and generators

The iteration protocol in depth: __iter__ and __next__. Generator functions and the yield keyword. Generator expressions and their memory footprint. Designing custom iterators for your own data structures. Application: composable processing chains.

Module 4 — Advanced attribute management

Properties (@property, setter, deleter). The descriptor protocol: __get__, __set__, __delete__. Data vs non-data descriptors. Attribute hooks: __getattr__, __setattr__, __getattribute__. Applications: automatic validation, computed attributes, hooks.

Module 5 — Metaclasses

The instance/class/metaclass relationship in Python's object model. The type metaclass and dynamic class creation. Defining a custom metaclass with __new__ and __init__. Use cases: automatic registration, class validation, singletons.

Audience and prerequisites

Target audience

Developers, engineers and researchers who want to deepen their command of Python beyond the basics and understand the inner mechanisms of the language.

Prerequisites

Having taken the “Python — level 1” course or having an equivalent level: a command of shared references, dynamic typing, namespaces and iteration. A good understanding of classes and instances.

Teaching method

The course alternates short theoretical presentations and hands-on exercises in Jupyter notebooks. Each concept is put into practice immediately. Particular attention is paid to the most recent techniques and to best practices drawn from field experience — in particular those I come across in the source code of the major libraries of the ecosystem.

The material is given to the participants at the end of the course, along with the exercise notebooks and their solutions.

A course for every mature Python team

This course is particularly suited to teams that develop their own internal libraries, contribute to open source projects, or must maintain complex production Python code. It combines naturally with the data science courses for teams that want both performance and architectural quality.

Official documentation

The Python data model (metaclasses, descriptors), PEP 318 (decorators), PEP 255 (generators).

Frequently asked questions

What are the concrete prerequisites for this course?

You need to master shared references, dynamic typing, namespaces and iteration — either by having taken the Python level 1 course, or by having an equivalent level. A good understanding of classes and instances is also required.

What is the concrete use of knowing metaclasses?

Metaclasses let you understand Python's object model in depth, and write generic code: automatic class registration, validation at definition time, singletons. They appear regularly in the source code of Pandas, SQLAlchemy and pytest — libraries that many teams use without being able to read their code.

What is the difference between a decorator written as a function and one written as a class?

Both forms are covered in module 2. Class-based decorators may look simpler and more powerful at first, but they have important limitations — in particular when decorating class methods. Function-based decorators, relying on closures and nonlocal attributes (or function attributes), make it possible to build powerful and fully generic decorators. This is the approach favored in the course.

Is this course useful for teams that do not write libraries?

Yes. Understanding descriptors, generators and decorators lets you read and maintain complex Python code, even without writing it. It is useful for any team that works with third-party libraries or takes over existing production code.

Is the remote format suitable for this kind of training?

Yes. 90% of participants rate the remote format as equivalent or better than in-person. I have been running remote training since 2020 and have built a solid practice of online teaching. I use Zoom, which makes it possible to record the sessions and share them with participants if desired, and CoCalc, an online platform that gives access to preconfigured servers with all the training material and libraries installed. CoCalc also lets me follow each participant's progress in real time and step in directly to correct or unblock.

Can this course be combined with a data science course?

Yes, it is a natural combination for teams that want both performance (Polars, Numba) and architectural quality (decorators, descriptors, metaclasses).