Data AnalyticsPython foundations for analysts

Separate configuration from analysis code

PK
Pankit Kumar
Sr. Data Scientist at Parexel (a Goldman Sachs–backed company) · 20 September 2026 · 3 min read
Technically reviewed by Ishaan Sharma
In this article (5 sections)

Move values that legitimately vary between runs into configuration: input path, output location and reporting month are good examples. Keep the calculation's meaning explicit and versioned. Turning every business rule into a freely editable setting can make two reports with the same name measure different things.

Configuration should help reproduce a run, not provide a hidden route around validation.

Classify what is allowed to vary

In the Python reporting lab, the caller chooses a source, destination and month. The report definition remains paid orders within that month, after validation and duplicate handling.

Changing January to February is a normal run parameter. Changing whether Pending orders count as paid changes the metric itself. Such a change requires review, documentation and new expected results, even if implemented through a configuration value.

ValueSuggested treatment in this lab
Reporting monthValidated run parameter
Input/output pathsExplicit run parameters
Paid-order definitionVersioned business logic
Customer ID formatSource schema contract
Password or API tokenSecret mechanism, never a committed example

The lab uses no credentials. A production connector should keep secret values out of report manifests and ordinary logs.

Validate configuration before processing data

This small example rejects unknown options and invalid months rather than silently ignoring them:

python
from dataclasses import dataclass
from report import month_bounds

@dataclass(frozen=True)
class ReportConfig:
    month: str
    allow_partial: bool

def parse_config(raw):
    if set(raw) != {"month", "allow_partial"}:
        raise ValueError("unexpected_config_keys")
    if not isinstance(raw["month"], str):
        raise ValueError("month_must_be_text")
    month_bounds(raw["month"])
    if type(raw["allow_partial"]) is not bool:
        raise ValueError("allow_partial_must_be_boolean")
    return ReportConfig(**raw)

config = parse_config({"month": "2026-01", "allow_partial": False})
assert config.month == "2026-01" and config.allow_partial is False
for bad in [
    {"month": "2026-13", "allow_partial": False},
    {"month": "2026-01", "allow_partial": "false"},
    {"month": "2026-01", "allow_partial": False, "mont": "2026-02"},
]:
    try:
        parse_config(bad)
    except ValueError:
        pass
    else:
        raise AssertionError("Invalid configuration accepted")
print("Configuration schema and types verified")

The string "false" is not a Boolean false value. Converting it with bool() would produce True because the string is nonempty. Explicit type validation prevents that surprising behavior.

This example validates a proposed option; it does not add allow_partial to the supplied report.py. The actual CLI continues to use its documented partial-result exit convention.

Make precedence visible

If a program supports a file, environment variables and CLI overrides, define their precedence. For example, defaults can be overridden by a configuration file and then explicit CLI arguments. Record the resolved nonsecret values so a reviewer knows what the program actually used.

Avoid silent fallback after a malformed configuration file. A typo that causes the program to use last month's default is harder to discover than an immediate validation error.

The argparse reference covers command-line values and defaults. The dataclasses reference explains the container used above; freezing the object discourages later reassignment but does not replace input validation.

Version the definition as well as the input

The lab records a source hash and Python version. A fuller run manifest should also identify the code revision and resolved reporting parameters. Identical input bytes can produce different results after a logic change, so a source hash alone is insufficient.

When configuration controls a threshold, include the threshold's unit and purpose. A value of 5 could mean five rupees, five percent or five records. A meaningful name and a documented range reduce that ambiguity.

Exercise: design a configuration file for January and February runs, including an explicit rule for handling partial quality. Explain which changes merely select a period and which require a new metric definition.

NeuraPath's Data Analytics with Generative AI course connects reusable scripts with controlled reporting. A clear configuration contract makes variation visible while preserving the meaning of the calculation.

Continue learning

This article is part of the Python foundations for analysts sequence. Use the neighbouring tasks when you need the prerequisite or the next application.

PK
Pankit Kumar
Lead Instructor, NeuraPath Academy

Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.

This article is part of our Data Analytics with Generative AI programme — 3–4 months. The full analyst stack — Excel, SQL, Power BI and Python pipelines — then a generative-AI layer you can prove is right.

Explore Data Analytics with Generative AI
Counselling is free · no obligation

Not sure which programme fits?

Tell us your background and we will map it to the right entry point — including saying so when a cheaper programme is the better fit. A counsellor replies within one working day.