You can use the setuptools library to help package your application into a wheel (installable module, like from PyPi), then add the scripts argument to specify how you want to run it from the command line:

setup(
    ...
    scripts=['bin/funniest-joke'],
    ...
)

When we install the package, setuptools will copy the script to our PATH and make it available for general use

You can find more information here about how to incorporate this functionality.

Answer from Xiddoc on Stack Overflow
🌐
Python Packaging
packaging.python.org › en › latest › guides › creating-command-line-tools
Creating and packaging command-line tools - Python Packaging User Guide
The pyproject metadata keys and the [build-system] table may be filled in as described in Writing your pyproject.toml, adding a dependency on typer (this tutorial uses version 0.12.3). For the project to be recognised as a command-line tool, additionally a console_scripts entry point (see Creating executable scripts) needs to be added as a subkey:
🌐
The Hitchhiker's Guide to Python
docs.python-guide.org › scenarios › cli
Command-line Applications — The Hitchhiker's Guide to Python
Cliff is a framework for building command-line programs. It uses setuptools entry points to provide subcommands, output formatters, and other extensions. The framework is meant to be used to create multi-level commands such as svn and git, where the main program handles some basic argument parsing and then invokes a sub-command to do the work. Cement is an advanced CLI Application Framework.
Discussions

How to build and run a Python command line application? - Stack Overflow
I'm trying to build a simple command line application using Python. At the moment, I call my application in Windows PowerShell, for instance, as: python myprog.py --input_file "test_file.json&... More on stackoverflow.com
🌐 stackoverflow.com
How to create a Windows command line application and its installer from wheels - Packaging - Discussions on Python.org
Let’s say that we have Windows wheels for a CLI. To take a simple but realistic example, one can consider the CLI black (a Python console-script entry point) and the wheels that are installed with black[jupyter]. My real motivation would be creation of apps and installers for Mercurial (a ... More on discuss.python.org
🌐 discuss.python.org
2
January 4, 2025
command line interface - How can I setup a python CLI application so that I can use it without directly referring to the interpreter? - Stack Overflow
I want a self contained application I can install using pip and then launch directly without any reference to the python interpreter. ... It is an important requirement to me that the package can be installed using pip and the command line interface is immediately available. Shebangs/fiddling manually with the path/creating ... More on stackoverflow.com
🌐 stackoverflow.com
making my program a command line application?

hey, i want to make my program i made a few weeks back into a command line application

Just to be sure, what kind of application do you think it is right now?

More on reddit.com
🌐 r/learnpython
2
1
January 10, 2024
🌐
KDnuggets
kdnuggets.com › build-a-command-line-app-with-python-in-7-easy-steps
Build a Command-Line App with Python in 7 Easy Steps - KDnuggets
This tutorial uses Python 3.11. In the todo.py file, start by importing the required modules. For our simple to-do list app, we'll need the following: ... Recall that we’ll use command-line flags to add, list, and remove tasks. We can use both short and long options for each argument. For our app, let’s use the following: ... Here’s where we’ll use the argparse module to parse the arguments provided at the command line. We define the create_parser() function that does the following:
🌐
Honeybadger
honeybadger.io › blog › building-command-line-applications-in-python-a-comprehensive-guide
Building command-line applications in Python - Honeybadger Developer Blog
March 19, 2024 - To add different functionalities to the Python command-line application, we will use the argparse module. You can install this module using PIP by executing the following statement in the bash terminal. ... After installing, we can use the argparse module in a Python program to create and parse command-line arguments for adding different functionalities.
🌐
Real Python
realpython.com › python-typer-cli
Build a Command-Line To-Do App With Python and Typer – Real Python
July 3, 2026 - Then you need to give the project a coherent Python application layout. That’s what you’ll do in the following subsections. To download all the files and the project structure you’ll be creating in this section, click the link below and go to the source_code_step_1/ directory: Get Source Code: Click here to get the source code you’ll use to build a to-do app for your command line using Python and Typer.
🌐
Thomas Stringer
trstringer.com › easy-and-nice-python-cli
The easy (and nice) way to do CLI apps in Python | Thomas Stringer
October 20, 2016 - The best way to install (and uninstall) your Python CLI app is to use pip (pip3 for Python 3). In the root directory of the CLI source code, running pip3 install . will install this app using setup.py as “instructions”. Likewise, running pip3 uninstall pycli will remove the app.
Find elsewhere
🌐
Opensource.com
opensource.com › article › 22 › 7 › bootstrap-python-command-line-application
Turn your Python script into a command-line application | Opensource.com
It would also be nice to have an entry point into this script that users can call from the command line. Right now, you can only run it by finding the .py file and executing it manually. Fortunately, Python's packaging infrastructure has a nice "canned" way to make this an easy configuration change. Add the following to the options.entry_points section of your setup.cfg: console_scripts = roto = rotoscope.rotoscope:rotoscope · This change creates a shell command called roto, which you can use to call the rotoscope script.
🌐
Python.org
discuss.python.org › packaging
How to create a Windows command line application and its installer from wheels - Packaging - Discussions on Python.org
January 4, 2025 - Let’s say that we have Windows wheels for a CLI. To take a simple but realistic example, one can consider the CLI black (a Python console-script entry point) and the wheels that are installed with black[jupyter]. My real motivation would be creation of apps and installers for Mercurial (a ...
🌐
DEV Community
dev.to › wangonya › building-command-line-applications-with-python-5l4
Building Command-Line Applications with Python - DEV Community
August 16, 2019 - Since I learn best by doing, I went ahead to create norris-cli among other apps, and discovered the possibilities were endless 😄. Building these kinds of projects is a great way to learn, and it's super fun. To improve my skills and help others learn, I'll be doing a whole series on "Building CLI Apps with Python". I'll start with the basics and go step by step. In the end, we'll put what we've learned into practice by creating a practice project*. Of course, what we'll make won't be very useful, but we'll learn enough in the process to go ahead and make something truly useful.
🌐
GitHub
github.com › pypa › packaging.python.org › blob › main › source › guides › creating-command-line-tools.rst
packaging.python.org/source/guides/creating-command-line-tools.rst at main · pypa/packaging.python.org
The file :file:`__main__.py` marks the main entry point for the application when running it via :mod:`runpy` (i.e. python -m greetings, which works immediately with flat layout, but requires installation of the package with src layout), so initialize the command-line interface here:
Author: pypa
🌐
Medium
medium.com › @noransaber685 › simple-guide-to-creating-a-command-line-interface-cli-in-python-c2de7b8f5e05
Simple Guide to Creating a Command-Line Interface (CLI) in Python | by Noran Saber Abdelfattah | Medium
February 3, 2024 - To start your CLI, create an instance of your class and call cmdloop(): ... Now, when you run your Python script, your CLI will greet you with the introductory message and the prompt.
🌐
Medium
trujillo9616.medium.com › making-a-cli-application-in-python-a9c7978db54e
Making a CLI Application in Python | by Adrian Trujillo Duron | Medium
December 14, 2021 - Argparse — The argparse module makes it easy to write user-friendly command-line interfaces. The program defines what arguments it requires, and argparse will figure out how to parse those out of sys.argv. The argparse module also automatically generates help and usage messages and issues errors when users give the program invalid arguments. Click — Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary.
🌐
Medium
medium.com › @nabulovivian2014 › how-i-created-a-command-line-application-with-python-edf332b8d414
How I created a command line application with python | by nabulo vivian | Medium
September 20, 2018 - Since am using pyinquirer, Install it in the virtual environment, venv using pip install pyinquirer from the scripts folder of the virtual environment. ... create a python file ‘cli_newsapi.py’ from where you are going to implement your command line application.
🌐
DEV Community
dev.to › kanakos01 › create-a-cli-application-with-python-1j37
Create a CLI application with Python - DEV Community
February 9, 2025 - from setuptools import setup setup( name="calcli", version="6.9", packages=["calcli"], entry_points={ "console_scripts": ["calcli = calcli.__main__:main"], }, description="A CLI calculator using argparse", author="Your Name", url="Project URL", python_requires=">=3.6", ) ... entry_points - stores the commands that will be accessible through the CLI. here when we type calcli the calcli.__main__:main script will be executed · After you create a setup.py you are ready to build the package. Now, there are 2 options - pip install .
🌐
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.
🌐
Medium
medium.com › @zahedialfurquan20 › building-a-command-line-application-using-python-fbcf7a60863a
Building a command line application using python, typer and poetry | by Alfurquan Zahedi | Medium
March 24, 2024 - To start coding the application, we need to set up a working Python environment with all the tools, libraries, and dependencies we will use in the process. Then we need to give the project a coherent Python application layout.
🌐
Medium
medium.com › h7w › creating-command-line-applications-in-python-from-basics-to-real-world-applications-f0bb62a5142b
Creating Command-Line Applications in Python: From Basics to Real-World Applications | by Vijay | T3CH | Medium
November 7, 2024 - A command-line application (or CLI) is simply a program you can run in your terminal or command prompt. There’s no fancy user interface — it’s all about typing commands to get your work done. Imagine apps like Git, the text-based task manager todo.txt, or even Python’s own package…
🌐
Klein Embedded
kleinembedded.com › home › creating a python command line tool
Creating a Python command line tool - Klein Embedded
November 29, 2022 - The command prompt does not have shebang-support, but you can associate .py files with a specific program (the Python interpreter by default). If you do not want to type in the .py extension when calling the script, you can add the extension to the PATHEXT environment variable, which contains a list of file extensions for executable files. Of course, you still have to add the script folder to the Path. We will start by creating a folder for our command line tools (e.g.