You should add main.py to your PATH. What happens when you are running flask run is that your teminal looks up the command flask in PATH and runs the program that it is pointing to. You could see it as a kind of shortcut to the program Flask.

By adding your program to your PATH, you can tell the computer that if you type helloworld in your terminal, the terminal should run /my/path/to/helloworld.py.

I don't know what OS you are on, so here are links for most common OS on how to add a PATH variable.

Windows

Linux

Mac OSX

Edit: After you gave more explanation, setuptools is what you are looking for. Please look at this reference to see how to use it.

Answer from Damiaan on Stack Overflow
๐ŸŒ
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.
๐ŸŒ
Real Python
realpython.com โ€บ python-typer-cli
Build a Command-Line To-Do App With Python and Typer โ€“ Real Python
July 3, 2026 - In this step-by-step project, you'll create a to-do application for your command line using Python and Typer. While you build this app, you'll learn the basics of Typer, a modern and versatile library for building command-line interfaces (CLI).
๐ŸŒ
Python Packaging
packaging.python.org โ€บ en โ€บ latest โ€บ guides โ€บ creating-command-line-tools
Creating and packaging command-line tools - Python Packaging User Guide
This guide will walk you through creating and packaging a standalone command-line application that can be installed with pipx, a tool for creating and managing Python Virtual Environments and exposing the executable scripts of packages (and available manual pages) for use on the command-line.
๐ŸŒ
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.
๐ŸŒ
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 - Hence, flags are used in a command line application to turn specific features on or off. Usually, we execute a Python program from the command-line terminal using the syntax python filename.py or python3 filename.py.
๐ŸŒ
Readthedocs
python-guide.readthedocs.io โ€บ en โ€บ latest โ€บ 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.
๐ŸŒ
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
So only make sure youโ€™re using a recent version of Python. 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.
Find elsewhere
๐ŸŒ
pytz
pythonhosted.org โ€บ pyCLI
cli โ€” command line tools โ€” pyCLI devel documentation
The cli package is a framework for making simple, correct command line applications in Python. With cli, you can quickly add standard command line parsing; logging; unit and functional testing; and profiling to your CLI apps.
๐ŸŒ
Better Programming
betterprogramming.pub โ€บ designing-beautiful-command-line-applications-with-python-72bd2f972ea
Designing Beautiful Command-Line Applications With Python | by Martin Thoma | Better Programming
February 9, 2022 - Designing Beautiful Command-Line Applications With Python Five libraries that make your console beautiful A lot of people still write their command-line applications with Argparse or even Optparse โ€ฆ
๐ŸŒ
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 - Itโ€™s the โ€œCommand Line Interface Creation Kitโ€. Itโ€™s highly configurable but comes with sensible defaults out of the box. Docopt โ€” A lightweight python package for creating command line interface easily by parsing POSIC-style or Markdown usage instructions.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ command-line-interface-programming-python
Command Line Interface Programming in Python - GeeksforGeeks
How do we execute any script in Python? $ python do_something.py $ python do_something_with_args.py gfg vibhu Probably that's how you do it. If your answer was that you just click a button on your IDE to execute your Python code, just assume you were asked specifically how you do it on command line.
Published: March 7, 2022
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ using โ€บ cmdline.html
1. Command line and environment โ€” Python 3.15.0 documentation
If this option is given, the first element of sys.argv will be the script name as given on the command line.
๐ŸŒ
Opensource.com
opensource.com โ€บ article โ€บ 18 โ€บ 5 โ€บ 3-python-command-line-tools
3 Python command-line tools | Opensource.com
May 30, 2018 - In this month's Python column, ... a command-line application. A command-line application is a program that you interact with and run from something like your shell ......
๐ŸŒ
DEV Community
dev.to โ€บ wangonya โ€บ building-command-line-applications-with-python-5l4
Building Command-Line Applications with Python - DEV Community
August 16, 2019 - You can do a lot of amazing things with Python. When I started teaching myself Python last year, one of the most interesting things I discovered was how relatively easy it was to create CLI apps.
๐ŸŒ
Qodo
qodo.ai โ€บ blog โ€บ technology โ€บ creating powerful command-line tools in python: a practical guide
Creating Powerful Command-Line Tools in Python: A Practical Guide
July 11, 2025 - Command-line tools, often referred to as command-line interfaces (CLIs), are text-based interfaces that allow users to interact with software and perform tasks by entering commands and arguments into a terminal or console.
๐ŸŒ
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 - An editor that you will use to write the command line application. For my case, I used VScode. A programming language, python. I chose python because of its flexibility and works well with existing programs.
๐ŸŒ
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 CLI) and potentially also TortoiseHg (a GUI), but this would be more complicated so letโ€™s first consider the simpler case of Black.