Jae Wilson @DataCrew

Python - building configurable scripts with a factory process

March 21, 2024

Hook (1-2 sentences): Every integration you build follows the same chain — upsert the role, create the user, upsert the group, add the user — and somewhere around the third time you write that chain, you realize you've been copying and pasting the same scaffolding across scripts.

Why It Matters

Without a factory pattern, business logic gets tangled into your class methods, error handling gets duplicated across integrations, and every new automation task starts from scratch. The factory approach separates what steps to run from how each step works, so the same sequence logic can be driven entirely from a config document. This unlocks reusable pipelines where the only thing that changes between deployments is a JSON or YAML config — not your code.

What You'll Learn

  • Understand why route functions and class methods should stay thin and logic-free
  • Recognize the failure mode that emerges when integration logic bleeds into class definitions
  • Build a factory process that executes a configurable list of functions in sequence
  • Drive multi-step automation workflows from a config document without rewriting the chain
  • Apply consistent logging patterns that make script runs auditable and reproducible