You can use list directly in parse_args()
args = parser.parse_args(["arg1", "arg2", "arg3"])
or you can use your line
command = "arg1 arg2 arg3"
args = parser.parse_args(command.split(" "))
You can always put it in sys.argv and parser should use it
import sys
sys.argv = ["script", "arg1", "arg2", "arg3"]
it can be useful if you want to append() some option to values which you get from command line
sys.argv.append("--debug")
If you have more complex command with quoted strings like
'arg1 "Hello World" arg3'
then you can use standard module shlex to split it correctly into three arguments
import shlex
shlex.split('arg1 "Hello world" arg3')
['arg1', 'Hello World', 'arg3'].
Normal command.split(" ") would incorrectly give four arguments
['arg1', '"Hello', 'World"', 'arg3']
parser.parse_args( ["script", "arg1", "arg2", "arg3"] )did exactly what I wanted. it was mantioned here all along docs.python.org/3.8/library/…