Configuration is the settings of one run: the batch date, the input path, the reject limit. A batch date is the day of data that the run handles.
If these values sit as fixed text in many functions, you cannot see what a run used. Put them in one object instead.
A dataclass is a short way to make a class that holds named values. With frozen=True, nobody can change the values after you create the object:
One frozen config objectworked example
from dataclasses import dataclass, replace
@dataclass(frozen=True)
class JobConfig:
batch_date: str
input_path: str
reject_limit: int = 10
config = JobConfig(batch_date="2026-06-19",
input_path="incoming/2026-06-19.csv")
print(config)
Result · 1 row
| output |
|---|
| JobConfig(batch_date='2026-06-19', input_path='incoming/2026-06-19.csv', reject_limit=10) |
incoming/2026-06-19.csv is the dated file from chapter 4. reject_limit has a default of 10.
Pass config to the functions that need it. Then the settings of a run are in one place, and you can save them next to the result.
You cannot change a frozen object. To run again with one setting changed, replace() makes a new object:
Change one setting for a rerunworked example
rerun = replace(config, reject_limit=0)
print(rerun.reject_limit, config.reject_limit)
config.reject_limit = 5
Result · 2 rows
| output |
|---|
| 0 10 |
| dataclasses.FrozenInstanceError: cannot assign to field 'reject_limit' |
The rerun has the new limit. The original config is unchanged, and trying to change it raises an error.
Chapter 17, Functions, Decorators, Context Managers & Dataclasses, shows more about dataclasses.