Building Reusable Python Packages for Data Scientists 2026

Software Engineering For Data Scientists Mar 20, 2026

Building Reusable Python Packages for Data Scientists 2026

Stop copying the same utility functions, feature engineering code, and validation logic across multiple projects. In 2026, professional data scientists build and maintain reusable Python packages that can be installed with a single uv add or pip install. This article shows you exactly how to create, structure, test, document, and publish production-grade Python packages tailored for data science work.

TL;DR — Modern Package Creation 2026

  • Use pyproject.toml + uv (the new standard)
  • Follow the src layout for clean imports
  • Include type hints, comprehensive docstrings, and tests
  • Automate with Ruff, Pyright, pytest, and GitHub Actions
  • Publish to PyPI or your private index for team-wide reuse

1. Project Structure (2026 Standard)

my_data_utils/
├── pyproject.toml
├── README.md
├── LICENSE
├── src/
│   └── my_data_utils/
│       ├── __init__.py
│       ├── data_loader.py
│       ├── feature_engineering.py
│       └── validation.py
├── tests/
│   └── test_feature_engineering.py
└── examples/
    └── usage.ipynb

2. Modern pyproject.toml Setup

[project]
name = "my-data-utils"
version = "1.2.0"
description = "Reusable utilities for data science pipelines"
requires-python = ">=3.11"
dependencies = [
    "polars>=1.0.0",
    "pydantic>=2.0.0",
    "pyarrow>=15.0.0"
]

[tool.uv]
dev-dependencies = ["pytest", "ruff", "pyright"]

[tool.ruff]
line-length = 100

3. Real-World Example: Reusable Feature Engineering

# src/my_data_utils/feature_engineering.py
from pydantic import BaseModel
import polars as pl

class FeatureConfig(BaseModel):
    target: str
    categorical_cols: list[str]

def engineer_features(df: pl.DataFrame, config: FeatureConfig) -> pl.DataFrame:
    """Apply common feature engineering steps used across projects."""
    df = df.with_columns([
        (pl.col("amount") * 1.1).alias("taxed_amount"),
        pl.col(config.target).log().alias("log_target")
    ])
    return df

4. Testing, Linting & Automation

# tests/test_feature_engineering.py
def test_engineer_features():
    df = pl.DataFrame({"amount": [100, 200]})
    config = FeatureConfig(target="amount", categorical_cols=[])
    result = engineer_features(df, config)
    assert "taxed_amount" in result.columns

5. Best Practices in 2026

  • Use uv for dependency management and packaging
  • Always include type hints and Pydantic models for configuration
  • Write tests for every public function
  • Automate linting, type checking, and testing with GitHub Actions
  • Publish to PyPI or your company’s private index
  • Keep packages small and focused (one responsibility per package)

Conclusion

Building reusable Python packages is the highest-leverage skill for data scientists in 2026. Instead of copying code between projects, you install your own package with one command and get consistent, tested, documented utilities everywhere. This practice dramatically increases productivity, reduces bugs, and makes collaboration with software engineers seamless.

Next steps:

  • Create your first reusable package today using the structure above
  • Move your most-used utility functions into it and install it across all projects
  • Continue the “Software Engineering For Data Scientists” series to learn more production skills
Share:
Last updated: March 2026
Built-in Functions in Python 2026 str() in Python 2026: String Conversion + Modern Formatting & Best Practices memoryview with JAX in Python 2026: Zero-Copy NumPy → JAX Array Interop + Efficient ML Examples memoryview with TensorFlow in Python 2026: Zero-Copy NumPy → Tensor Interop + GPU Pinning & ML Examples memoryview with TensorFlow in Python 2026: Zero-Copy NumPy → Tensor Interop + ML Examples memoryview with NumPy & PyTorch in Python 2026: Zero-Copy Views, Efficient Slicing & ML Interop Examples memoryview with NumPy in Python 2026: Zero-Copy Views, Efficient Slicing & Real ML Examples memoryview() in Python 2026: Zero-Copy Magic for Large Binary Data + Real Examples import() in Python 2026: How It Works, Security Risks & Modern Alternatives (importlib) zip() in Python 2026: How to Use It, strict=True Behavior & Real-World Examples vars() in Python 2026: Accessing Object Namespace + Modern Introspection Patterns type() in Python 2026: Dynamic Type Inspection & Object Creation + Modern Patterns tuple() in Python 2026: Immutable Sequences + Modern Patterns & Best Practices super() in Python 2026: Method Resolution & Modern Inheritance Patterns sum() in Python 2026: Summing Iterables + Modern Numeric Patterns & Best Practices staticmethod() in Python 2026: Static Methods, Utility Functions & Modern Best Practices sorted() in Python 2026: Sorting Iterables + Modern Patterns & Best Practices slice() in Python 2026: Creating Slice Objects + Modern Patterns & Best Practices setattr() in Python 2026: Dynamic Attribute Setting + Modern Patterns & Safety set() in Python 2026: Mutable Sets Creation + Modern Patterns & Best Practices