== Creating Command Line Tools With Python == === Standard library support for parsing command lines === * [[https://docs.python.org/library/optparse.html|optparse]] and [[https://docs.python.org/library/argparse.html|argparse]] (optparse is marked as deprecated since the introduction of argparse with Python 2.7 and Python 3.2, use argparse unless you have to support older Python versions) * [[https://docs.python.org/2/library/getopt.html|getopt]] C-style command line parser The [[https://docs.python.org/howto/argparse.html|Argparse Tutorial]] is an excellent read for getting you started with creating command line tools. See also OptionParsing. ---- === Other articles on Python command line tools === '''For sysadmins familiar with Bash scripting''': Beginner Level, circa 02/2008 * [[http://magazine.redhat.com/2008/02/07/python-for-bash-scripters-a-well-kept-secret/ | Python for Bash scripters: A well-kept secret ]] '''Using Python To Create Unix Commandline Tools:''' Beginning/Intermediate Level * Summary: An introductory article on how to create command line tools with Python. A beginner should learn how to create command line tool after finishing. * [[http://www.ibm.com/developerworks/aix/library/au-pythocli/?ca=dgr-lnxw82pythonunixtool&S_TACT=105AGX59&S_CMP=GR|Introduction To Creating CLI Tools with Python]] '''Command line tool with optparse, subprocess, and logging''': Beginning/Intermediate level * Summary: This script provides shortcuts for using a Git repository but the script could be used as a template for other shell tools. * [[http://www.jperla.com/blog/2008/11/17/a-clean-python-shell-script/ | A Clean Python Shell Script ]]. '''PyCon2008 Presentation on Command Line Tools:''' Intermediate Level * Summary: Presentation goes into detail on using threads, subprocess, optparse, configparser, and ORM's to create sophisticated tools. * [[http://code.noahgift.com/pycon2008/pycon2008_cli_noahgift.pdf|Slides: Creating Command Line Tools with Python]] * [[http://code.noahgift.com/pycon2008/pycon2008_cli_noahgift.zip|Source: Code]]