Descriptors: Adding Super Powers Python Classes

Satyam Soni (~satyamsoni2211)


9

Votes

Description:

In the world of Python programming, Classes are powerful tools that allow us to encapsulate data and functionality into neat and reusable structures. However, there are times when we want to enhance the capabilities of our classes and imbue them with extraordinary abilities.

That's where descriptors come in. Descriptors provide a powerful mechanism for controlling and customizing attribute access in Python classes. They allow us to define the behavior of attribute access, such as getting, setting, and deleting values, by intercepting the corresponding operations.

In this workshop, we will dive deep into the world of descriptors and explore how they can empower our classes with superpowers. We will begin by understanding the fundamental concepts of descriptors and how they fit into the overall Python class model. We will explore various types of descriptors, including data descriptors, non-data descriptors, and get-only descriptors, each serving different purposes.

Throughout the workshop, we will demonstrate practical examples and real-world use cases where descriptors can be applied effectively. You will learn how to use descriptors to enforce data validation, create computed attributes, implement lazy loading, enable attribute-level access control, and much more. By the end of this workshop, you will have a solid understanding of how descriptors work and how to leverage them to unlock new possibilities in your Python classes.

Whether you are a beginner seeking to expand your Python knowledge or an experienced developer looking to level up your class design skills, this workshop will provide valuable insights and hands-on experience with descriptors. Our aim is to equip you with the tools and knowledge necessary to harness the true potential of Python's descriptor protocol.

So, join us on this exciting journey as we delve into the world of descriptors and unlock the superpowers of Python classes. Let's elevate our programming skills and discover new dimensions of class design together. Get ready to add superpowers to your code!

Topics to be covered in the Workshop

  • Descriptors Introduction
  • Applications of Descriptors
    • Validations
    • Data Transform
    • Data Attributes
    • Property getter and setters
    • ... many more
  • Types of Descriptors and deepdive.
    • Data Descriptors
    • Non-Data Descriptors
    • Descriptor methods - get, set, delete
    • Descriptor __set_name__ hook
  • Live hands on descriptors
    • Data Descriptors
    • Non-Data Descriptors
    • Descriptors as Validators
    • property descriptor
    • Lazy loading using Descriptors
    • Descriptors walkthrough in libraries like SQLAlchemy, Django ORM etc.

Prerequisites:

  • Python3 (>=3.9)
    • Editor of Choice ( VSCode Preferred, PyCharm )
    • Poetry ( Dependency Management )

Speaker Info:

A Python Enthusiast with 7+ years of experience working across multiple domains, verticals, and Frameworks. I am an active Open-Source contributor, with multiple libraries published over PyPI (lazy-alchemy, py-lambda-warmer, flask-dantic etc.), and currently working as Technology Lead with SenecaGlobal, delivering Python Based Full Stack Solutions to clients.

Speaker Links:

Previous Talks

Pyconf Hyderabad 2022 - Decorators And Generators - Control Your Code With Ease

Published Libraries

PyLambda Warmer - Utility to warm Lambda

Flask-Dantic - Pydantic Validations for Flask

Lazy Alchemy - Loading SQLAlchemy Tables Lazily

Lazy Env Configurator - Loading Env Configuration Lazily

Many More ...


Profile Info

Github Contributions - https://github.com/satyamsoni2211?tab=repositories

LinkedIn - Satyam Soni

Twitter - Satyam Soni

Section: Core Python
Type: Workshops
Target Audience: Intermediate
Last Updated: