argparse-ps1
Generate PowerShell wrapper scripts from Python argparse parsers
argparse-ps1 automatically generates PowerShell (.ps1) wrapper scripts for Python scripts that use argparse. This provides native PowerShell tab completion and parameter binding for your Python scripts.
Features
- 🚀 Automatic Generation: Creates PowerShell wrappers from
ArgumentParserobjects - 🎯 Type Mapping: Maps Python types to PowerShell parameter types
- 📝 Native Interface: Provides PowerShell-style parameter names and help
- ⚙️ Multiple Runners: Supports
uv,python, or custom runners - 🔧 Zero Dependencies: Uses only Python standard library
Installation
pip install argparse-ps1
Quick Start
Add wrapper generation to your Python script:
from argparse_ps1 import generate_ps1_wrapper
# Your existing argparse code
parser = argparse.ArgumentParser(description="My script")
parser.add_argument("--hello", action="store_true", help="Say hello")
parser.add_argument("--option", type=str, help="String option")
# Generate PowerShell wrapper
if "--make-ps1" in sys.argv:
output = generate_ps1_wrapper(parser, script_path=Path(__file__))
print(f"Generated: {output}")
sys.exit(0)
Generate the wrapper:
python my_script.py --make-ps1
# Creates My-Script.ps1
Use the PowerShell wrapper:
.\My-Script.ps1 -Hello -Option "test"
Examples
See the examples/ directory for complete working examples:
- basic_example.py: Simple boolean flags
- example.py: String options with
uv run - example_uv_project.py: Using
uv run --project - example_python.py: Using
pythonrunner instead ofuv
Project Mode Requirements
For project mode examples (example_uv_project.py), you need:
- Proper pyproject.toml structure with
[project.scripts]entry - Package structure with
__init__.pyfiles - Correct execution method: Use
uv run python example_uv_project.pyinstead of script entries
Usage Modes
Default: uv run (Direct Script)
generate_ps1_wrapper(parser, script_path=Path(__file__))
# Creates: & uv run script.py @args
Project Mode: uv run --project
generate_ps1_wrapper(
parser,
script_path=Path(__file__),
project_root=Path(".."),
command_name="my-command" # Must exist in [project.scripts]
)
# Creates: & uv run --project .. my-command @args
Custom Runner
Use alternative Python executables instead of uv:
# System Python
generate_ps1_wrapper(
parser,
script_path=Path(__file__),
runner="python"
)
# Creates: & python script.py @args
# Virtual environment Python (relative path)
generate_ps1_wrapper(
parser,
script_path=Path(__file__),
runner=".venv/Scripts/python.exe" # Windows
# runner=".venv/bin/python" # Unix/macOS
)
# Creates: & .venv\Scripts\python.exe script.py @args
# Custom Python installation (absolute path)
generate_ps1_wrapper(
parser,
script_path=Path(__file__),
runner="C:/Python312/python.exe"
)
# Creates: & "C:/Python312/python.exe" script.py @args
Note: See example_python.py for a complete working example.
API Reference
def generate_ps1_wrapper(
parser: argparse.ArgumentParser,
*,
script_path: Path,
output_path: Path | None = None,
output_dir: Path | None = None,
skip_dests: Iterable[str] | None = None,
runner: str = "uv",
command_name: str | None = None,
) -> Path
Parameters:
parser: YourArgumentParserinstancescript_path: Path to your Python script (absolute path required)output_path: Specific output file path (optional, overrides output_dir)output_dir: Output directory (default: current working directory)skip_dests: Argument destinations to exclude from wrapperrunner: Command to run Python scripts (default: "uv", can be "python")command_name: Command name in[project.scripts](enables project mode for uv)
Type Mapping
| Python Type | PowerShell Type | Example |
|---|---|---|
str |
[string] |
-Name "value" |
int |
[int] |
-Count 42 |
float |
[double] |
-Rate 3.14 |
Path |
[string] |
-File "path/to/file" |
store_true |
[switch] |
-Verbose |
Requirements
- Python 3.11+
- Windows PowerShell or PowerShell Core
License
MIT License - see LICENSE file for details.
Contributing
Contributions welcome! Please see DEVELOPMENT.md for setup instructions.
Metadata
Release files for argparse-ps1 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| argparse_ps1-0.1.6.tar.gz | 12.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| argparse_ps1-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.1 kB
Release files / argparse_ps1-0.1.6.tar.gz
| Download URL | argparse_ps1-0.1.6.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f7d8766593c69109ec6076e917f8779b0f5a76a8d651230cd5c1b417296a9a6
|
|
BLAKE2b-256 checksum How to use checksums |
8a32f938e2948b1bd4c89619b789cbf84ac8108238f508b3ae781283cebe30cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / argparse_ps1-0.1.6-py3-none-any.whl
| Download URL | argparse_ps1-0.1.6-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f04da96d04bf446239c9d63c85bf49712119d846cb6c1a12f09a4d611e0a8335
|
|
BLAKE2b-256 checksum How to use checksums |
65757975ac8fb4628c270d1480c71e469c41556c3c5fdc56f141a09ef4ee6c1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for argparse-ps1 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.