python-dual-mode

Refactor Python scripts into dual-mode modules with CLI and import support.

1|Updated Jan 26, 2026
One-click install
npx skills add https://github.com/Victory-Hugo/S2-Agent-Skill --skill python-dual-mode
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-dual-mode
Source: https://github.com/Victory-Hugo/S2-Agent-Skill/tree/main/skills/code/python-dual-mode
Command: npx skills add https://github.com/Victory-Hugo/S2-Agent-Skill --skill python-dual-mode

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers convert existing or new Python scripts into a robust dual-mode module that can run as a CLI tool and be imported as a library, enabling stable, maintainable data processing pipelines.

Core Features & Use Cases

  • Dual-mode architecture: A single module that works both as a library and as a standalone CLI.
  • Structured interface: Exposes a run(...) function with explicit, fully overridable inputs.
  • Safe, parameterized operations: All hard-coded paths and environment dependencies are avoided in favor of configurable arguments.
  • Use Case: Convert a long-running ETL script into a reusable module that can be integrated into job schedulers and used by other projects via import.

Quick Start

To begin, place your Python script into the project, run the scaffolder to generate the dual-mode module, and then execute or import the resulting module. Example: python -m dual_mode_wrapper --input input.py --output output_module

Frequently Asked Questions about python-dual-mode

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make a Python script importable as a library and runnable from the command line?

To make a Python script importable and runnable as a CLI, you refactor it into a dual-mode module with an explicit run() function and an argparse-based CLI interface. This allows the same module to be executed directly or imported by other projects.

What is the best way to refactor Python scripts for stable data processing pipelines?

Refactoring Python scripts for data processing pipelines involves removing hard-coded paths and exposing parameterized inputs. By enforcing an explicit run() function and a structured, testable module architecture, scripts become stable and maintainable for job schedulers.

How do I convert a long-running ETL script into a reusable module?

Converting an ETL script into a reusable module requires wrapping its logic in a dual-mode structure. This exposes a parameterized run() function so the code can be safely imported as a library and integrated into external job schedulers without hard-coded dependencies.

Can I use argparse to build a CLI interface for an importable Python module?

Yes, you can use argparse to build a CLI for an importable Python module. A dual-mode architecture uses argparse to handle command-line execution while keeping the underlying run() function fully overridable for safe library imports and testing.

Does converting a Python script to dual-mode require any external dependencies?

Converting a Python script to dual-mode requires no external dependencies. The refactoring process relies on standard Python features like argparse to generate a self-contained, importable module that functions as both a CLI tool and a library.

Why should I avoid hard-coded paths in data processing scripts?

You should avoid hard-coded paths in data processing scripts to ensure safe, parameterized operations. Replacing them with configurable arguments allows the dual-mode module to run reliably across different environments and be imported without side effects.