Skip to main content

One post tagged with "software-architecture"

software-architecture tag description

View All Tags

The Wrapper Pattern in Python: Definition and Strategic Use Cases

· 7 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

The Wrapper Pattern (often referred to in design literature as the Decorator Pattern or Adapter Pattern when applied to classes, but used here in the broader sense of wrapping functionality or data) involves encapsulating an object or a function within another object.

In the context of Python, particularly with frameworks like FastAPI and Pydantic, the Wrapper Pattern is primarily used to:

  1. Enhance or Extend Functionality without modifying the original object (Decorator/Adapter).
  2. Validate and Centralize Logic for a simple data type, turning it into a Value Object (as seen with Pydantic).