Pexpect might be useful for you: http://sourceforge.net/projects/pexpect/

Description from the webpage: "Pexpect is a Python module for spawning child applications; controlling them; and responding to expected patterns in their output. Pexpect can be used for automating interactive applications such as ssh, ftp, passwd, telnet, etc. Pexpect is pure Python."

Answer from Filip Korling on Stack Overflow
🌐
Medium
medium.com › @shamir.stav_83310 › lets-create-a-cli-with-python-part-1-ae4fe9e0258b
Let’s Create A CLI With Python — Part 1 | by Stav Shamir | Medium
April 11, 2019 - Let’s summarize what we’ve done: 1. Examined the API’s endpoints and decide which ones to support 2. Mapped the endpoints the click commands 3. Decided which parameters to support for each command 4. Add the parameters with click.option decorators and command function arguments · Next time we will create a wrapper for the API and have our CLI actually do something!
🌐
PyPI
pypi.org › project › cli-wrapper
cli-wrapper · PyPI
Requires python 3.10 or later. pip install cli-wrapper # for just the wrapper pip install ruamel.yaml # for yaml support pip install dotted_dict # for dotted_dict support shown above
      » pip install cli-wrapper
    
Published: May 08, 2025
Version: 0.1.0
Discussions

Good example of CLI wrapper?
Can you give an example of what you'd like to do with it? More on reddit.com
🌐 r/learnpython
8
7
September 12, 2014
select - How to wrap a CLI program in Python (keeping the interactivity)? - Stack Overflow
I'd like to write a wrapper for an interactive CLI Program (the Asterisk CLI). Basically, I need to keep the interaction with the CLI (including tab-completion) but I want to filter the output of More on stackoverflow.com
🌐 stackoverflow.com
subprocess - Help with wrapping a command line tool in Python - Stack Overflow
I'm really stuck with a problem I'm hoping someone can help me with. I'm trying to create a wrapper in Python3.1 for a command line program called spooky. I can successfully run this program on the More on stackoverflow.com
🌐 stackoverflow.com
Using Python, what's an effective way to wrap a command line utility? - Software Engineering Stack Exchange
I want to write a Python application that "wraps" a command line utility, passing through all parameters intact, except for the parameters that I choose to modify. I imagine there's an easy way to... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
🌐
GitHub
github.com › danbradham › scrim
GitHub - danbradham/scrim: Opaque Python CLI Wrapper · GitHub
Then the Scrim Script invokes the actual Python CLI passing all arguments from the User. The Python CLI can now use the scrim api to append commands to a list. When the python program exits, the list of commands is written to a temporary script file. The Scrim Script now continues and executes the temporary script file if it exists.
Author: danbradham
🌐
Reddit
reddit.com › r/learnpython › good example of cli wrapper?
r/learnpython on Reddit: Good example of CLI wrapper?
September 12, 2014 -

I'd like to write a python app that wraps an existing command line interface.

Does anyone know of good example apps to look at?

The CLI is fairly minimal but I am not quite sure how to approach this as I've mainly used Python for data analysis.

Thanks.

Edit (full example, from comment below):

Yes, so the CLI is for interacting with specific database/files. Basically I just use it to grab data, then I use/edit/analyze the data, and sometimes want to write back to the DB.

Examples:

mycli pull mydatabase (grab the database as csv for local use)
mycli import new_data.csv (import new csv data into DB)

Right now I just do this with call commands in my Python scripts:

subprocess.call(['mycli', 'pull', 'mydatabase'])

I'd like to just make a simple Python Module w/ an API to do this instead.

from mycli import DbManager
db = DbManager()
db.pull('mydatabase')

I can write this code now in a not DRY way. Basically just making a function for each thing the CLI can do.

I'd like to see an example of a larger application, so I can just understand how to best organize something like this in case it gets larger.

🌐
Medium
medium.com › @shamir.stav_83310 › lets-create-a-cli-with-python-part-2-750f21f36b4a
Let’s Create A CLI With Python — Part 2 | by Stav Shamir | Medium
April 11, 2019 - Let’s Create A CLI With Python — Part 2 This part is mostly about how to use the requests library to wrap an API with python functions. In the last part we’ve created a skeleton for a CLI …
Find elsewhere
🌐
PyPI
pypi.org › project › pycliwrapper
pycliwrapper · PyPI
May 26, 2023 - Wrap any CLI tool to Python like syntax. from pycliwrapper import CliWrapper apt_cache = CliWrapper("apt-cache", parser=lambda stdout: stdout.splitlines()) # Equivalent to run: "apt-cache search bash" and parsing # the output as a list res = ...
      » pip install pycliwrapper
    
Published: May 26, 2023
Version: 1.1
🌐
Readthedocs
nipype.readthedocs.io › en › 0.11.0 › devel › cmd_interface_devel.html
How to wrap a command line tool — nipy pipeline and interfaces package
As with all interfaces command line wrappers need to have inputs defined. Command line input spec has to inherit from CommandLineInputSpec which adds two extra inputs: environ (a dictionary of environmental variables), and args (a string defining extra flags).
🌐
Python
svn.python.org › projects › sandbox › branches › setuptools-0.6 › setuptools › tests › win_script_wrapper.txt
Python Script Wrapper for Windows =================================
Note that the script starts with a Unix-style '#!' line saying which Python executable to run. The wrapper will use this to find the correct Python executable. We'll also copy cli.exe to the sample-directory with the name foo.exe:
🌐
PyPI
pypi.org › project › exec-wrappers
exec-wrappers · PyPI
This will create in /tmp/conda_wrappers a wrapper for each executable found in ~/miniconda/envs/test/bin. So if you run the python wrapper:
🌐
The Hitchhiker's Guide to Python
docs.python-guide.org › scenarios › cli
Command-line Applications — The Hitchhiker's Guide to Python
Plac is a simple wrapper over the Python standard library argparse, which hides most of its complexity by using a declarative interface: the argument parser is inferred rather than written down imperatively.
🌐
PyPI
pypi.org › project › commandwrapper
commandwrapper · PyPI
Command Wrapper (make subprocess.Popen() easy) pip install commandwrapper Copy PIP instructions · Author : Yves-Gwenael Bourhis ================================================== Wrap a shell comand into a python threaded object.
🌐
DEV Community
dev.to › vast-cow › make-a-cli-command-from-your-python-package-quick-guide-21o5
Make a CLI command from your Python package - DEV Community
January 21, 2026 - #beginners #cli #python #tutorial · In short: declare a console_scripts entry point in your package metadata, activate the target virtual environment, then run pip install (during development use pip install -e .). That will place an executable ...
🌐
Real Python
realpython.com › python-click
Click and Python: Build Extensible and Composable CLI Apps – Real Python
March 18, 2026 - In this tutorial, you'll learn how to use the Click library to build robust, extensible, and user-friendly command-line interfaces (CLI) for your Python automation and tooling scripts.
🌐
Simon Willison
simonwillison.net › 2023 › Sep › 30 › cli-tools-python
Things I’ve learned about building CLI tools in Python
September 30, 2023 - Here are some notes on what I’ve learned about designing and implementing CLI tools in Python so far. I build enough CLI apps that I developed my own Cookiecutter template for starting new ones. That template is simonw/click-app. You can create a new application from that template directly on GitHub, too—I wrote more about that in Dynamic content for GitHub repository templates using cookiecutter and GitHub Actions. Almost all of my tools are built using the Click Python library.
🌐
Python Packaging
packaging.python.org › en › latest › guides › creating-command-line-tools
Creating and packaging command-line tools - Python Packaging User Guide
Alternatively, docopt makes it possible to create CLI interfaces based solely on docstrings; advanced users are encouraged to make use of click (on which typer is based).