René's URL Explorer Experiment


Title: Build Command-Line Interfaces With Python's argparse – Real Python

Open Graph Title: Build Command-Line Interfaces With Python's argparse – Real Python

Description: In this step-by-step Python tutorial, you'll learn how to take your command-line Python scripts to the next level by adding a convenient command-line interface (CLI) that you can write with the argparse module from the standard library.

Open Graph Description: In this step-by-step Python tutorial, you'll learn how to take your command-line Python scripts to the next level by adding a convenient command-line interface (CLI) that you can write with the argparse module from the standard library.

Mail addresses
?subject=Python article for you&body=Build Command-Line Interfaces With Python's argparse on Real Python https://realpython.com/command-line-interfaces-python-argparse/

Opengraph URL: https://realpython.com/command-line-interfaces-python-argparse/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "Build Command-Line Interfaces With Python's argparse",
  "image": {
    "@type": "ImageObject",
    "url": "https://files.realpython.com/media/Python-argparse-Guide_Watermarked.a7affa701ed5.jpg",
    "width": 1920,
    "height": 1080
  },
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://realpython.com/command-line-interfaces-python-argparse/",
    "lastReviewed": "2024-12-14",
    "author": {
      "@type": "Person",
      "name": "Leodanis Pozo Ramos",
      "image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
      "url": "https://realpython.com/team/lpozoramos/",
      "affiliation": {
        "@type": "Organization",
        "@id": "https://realpython.com/#organization",
        "name": "Real Python",
        "url": "https://realpython.com",
        "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
      }
    },
    "reviewedBy": [
      {
        "@type": "Person",
        "name": "Alex Ronquillo",
        "image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/IMG_0116.f88cbfca15da.jpg",
        "url": "https://realpython.com/team/aronquillo/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Aldren Santos",
        "image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Aldren_Santos_Real_Python.6b0861d8b841.png",
        "url": "https://realpython.com/team/asantos/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Brenda Weleschuk",
        "image": "https://realpython.com/cdn-cgi/image/width=320,height=320,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/IMG_3324_1.50b309355fc1.jpg",
        "url": "https://realpython.com/team/bweleschuk/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Bartosz Zaczy\u0144ski",
        "image": "https://realpython.com/cdn-cgi/image/width=1694,height=1694,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/coders_lab_2109368.259b1599fbee.jpg",
        "url": "https://realpython.com/team/bzaczynski/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Davide Mastromatteo",
        "image": "https://realpython.com/cdn-cgi/image/width=700,height=700,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/mastro.f2fa63891e00.jpg",
        "url": "https://realpython.com/team/dmastromatteo/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Geir Arne Hjelle",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/gahjelle.470149ee709e.jpg",
        "url": "https://realpython.com/team/gahjelle/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Ian Currie",
        "image": "https://realpython.com/cdn-cgi/image/width=480,height=480,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/5sK42VEQ_-_Copy_-_Copy.b8a1a4a9ca1f.jpeg",
        "url": "https://realpython.com/team/icurrie/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Joanna Jablonski",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/jjablonksi-avatar.e37c4f83308e.jpg",
        "url": "https://realpython.com/team/jjablonski/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Kate Finegan",
        "image": "https://realpython.com/cdn-cgi/image/width=400,height=400,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/VZxEtUor_400x400.7169c68e3950.jpg",
        "url": "https://realpython.com/team/kfinegan/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      }
    ]
  },
  "datePublished": "2024-12-14T14:00:00+00:00",
  "dateModified": "2024-12-14T14:09:25.393381+00:00",
  "publisher": {
    "@type": "Organization",
    "@id": "https://realpython.com/#organization",
    "name": "Real Python",
    "url": "https://realpython.com",
    "logo": {
      "@type": "ImageObject",
      "url": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png",
      "width": 512,
      "height": 512
    },
    "description": "Real Python is a leading provider of online Python education and one of the largest language-specific online communities for software developers. It publishes high-quality learning resources, such as tutorials, books, and courses to an audience of millions of developers, data scientists, and machine learning engineers each month.",
    "slogan": "Become a Python Expert",
    "email": "info@realpython.com",
    "sameAs": [
      "https://github.com/realpython",
      "https://www.youtube.com/realpython",
      "https://twitter.com/realpython",
      "https://x.com/realpython",
      "https://www.linkedin.com/company/realpython-com/",
      "https://www.facebook.com/learnrealpython",
      "https://www.instagram.com/realpython",
      "https://www.tiktok.com/@realpython.com"
    ]
  },
  "author": {
    "@type": "Person",
    "name": "Leodanis Pozo Ramos",
    "image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
    "url": "https://realpython.com/team/lpozoramos/",
    "affiliation": {
      "@type": "Organization",
      "@id": "https://realpython.com/#organization",
      "name": "Real Python",
      "url": "https://realpython.com",
      "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
    }
  },
  "description": "In this step-by-step Python tutorial, you'll learn how to take your command-line Python scripts to the next level by adding a convenient command-line interface (CLI) that you can write with the argparse module from the standard library.",
  "hasPart": {
    "@type": "FAQPage",
    "mainEntity": [
      {
        "@type": "Question",
        "name": "What is the purpose of using the argparse module in Python?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "

You use the argparse module to create user-friendly command-line interfaces, allowing you to define the arguments your app requires and automatically generate help and usage messages.

" } }, { "@type": "Question", "name": "How do you add arguments in argparse?", "acceptedAnswer": { "@type": "Answer", "text": "

You add arguments in argparse by calling the .add_argument() method on an ArgumentParser instance, specifying the argument name and any options or flags it should have.

" } }, { "@type": "Question", "name": "How do you handle optional arguments in argparse?", "acceptedAnswer": { "@type": "Answer", "text": "

You handle optional arguments in argparse by using flags or switches that start with a dash (-) or double dash (--). You can specify their behavior using the action parameter in .add_argument().

" } }, { "@type": "Question", "name": "How can you provide a default value for an argument in argparse?", "acceptedAnswer": { "@type": "Answer", "text": "

You can set a default value for an argument in argparse by using the default parameter in the .add_argument() method, specifying the value the argument should take if the user doesn’t provide it.

" } }, { "@type": "Question", "name": "What is the difference between sys.argv and argparse?", "acceptedAnswer": { "@type": "Answer", "text": "

sys.argv provides a simple way to access command-line arguments as a list of strings, while argparse offers a more powerful and flexible approach for parsing, validating, and handling command-line arguments.

" } } ] } }

authorReal Python
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/Python-argparse-Guide_Watermarked.a7affa701ed5.jpg
og:imagehttps://files.realpython.com/media/Python-argparse-Guide_Watermarked.a7affa701ed5.jpg
twitter:creator@realpython
og:typearticle

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/command-line-interfaces-python-argparse
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/quizzes/
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Code Mentor →BetaPersonalized code assistance & learning toolshttps://realpython.com/mentor/
Unlock All Content →https://realpython.com/account/join/
More https://realpython.com/command-line-interfaces-python-argparse
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Contributorhttps://realpython.com/jobs/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?next=%2Fcommand-line-interfaces-python-argparse%2F
Browse Topicshttps://realpython.com/tutorials/all/
Guided Learning Pathshttps://realpython.com/learning-paths/
Basicshttps://realpython.com/search?level=basics
Intermediatehttps://realpython.com/search?level=intermediate
Advancedhttps://realpython.com/search?level=advanced
aihttps://realpython.com/tutorials/ai/
algorithmshttps://realpython.com/tutorials/algorithms/
apihttps://realpython.com/tutorials/api/
best-practiceshttps://realpython.com/tutorials/best-practices/
careerhttps://realpython.com/tutorials/career/
communityhttps://realpython.com/tutorials/community/
databaseshttps://realpython.com/tutorials/databases/
data-sciencehttps://realpython.com/tutorials/data-science/
data-structureshttps://realpython.com/tutorials/data-structures/
data-vizhttps://realpython.com/tutorials/data-viz/
devopshttps://realpython.com/tutorials/devops/
djangohttps://realpython.com/tutorials/django/
dockerhttps://realpython.com/tutorials/docker/
editorshttps://realpython.com/tutorials/editors/
flaskhttps://realpython.com/tutorials/flask/
front-endhttps://realpython.com/tutorials/front-end/
gamedevhttps://realpython.com/tutorials/gamedev/
guihttps://realpython.com/tutorials/gui/
machine-learninghttps://realpython.com/tutorials/machine-learning/
newshttps://realpython.com/tutorials/news/
numpyhttps://realpython.com/tutorials/numpy/
projectshttps://realpython.com/tutorials/projects/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
testinghttps://realpython.com/tutorials/testing/
toolshttps://realpython.com/tutorials/tools/
web-devhttps://realpython.com/tutorials/web-dev/
web-scrapinghttps://realpython.com/tutorials/web-scraping/
Table of Contentshttps://realpython.com/command-line-interfaces-python-argparse#toc
Getting to Know Command-Line Interfaceshttps://realpython.com/command-line-interfaces-python-argparse#getting-to-know-command-line-interfaces
Command-Line Interfaces (CLIs)https://realpython.com/command-line-interfaces-python-argparse#command-line-interfaces-clis
Commands, Arguments, Options, Parameters, and Subcommandshttps://realpython.com/command-line-interfaces-python-argparse#commands-arguments-options-parameters-and-subcommands
Getting Started With CLIs in Python: sys.argv vs argparsehttps://realpython.com/command-line-interfaces-python-argparse#getting-started-with-clis-in-python-sysargv-vs-argparse
Using sys.argv to Build a Minimal CLIhttps://realpython.com/command-line-interfaces-python-argparse#using-sysargv-to-build-a-minimal-cli
Creating a CLI With argparsehttps://realpython.com/command-line-interfaces-python-argparse#creating-a-cli-with-argparse
Creating Command-Line Interfaces With Python’s argparsehttps://realpython.com/command-line-interfaces-python-argparse#creating-command-line-interfaces-with-pythons-argparse
Creating a Command-Line Argument Parserhttps://realpython.com/command-line-interfaces-python-argparse#creating-a-command-line-argument-parser
Adding Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#adding-arguments-and-options
Parsing Command-Line Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#parsing-command-line-arguments-and-options
Setting Up Your CLI App’s Layout and Build Systemhttps://realpython.com/command-line-interfaces-python-argparse#setting-up-your-cli-apps-layout-and-build-system
Customizing Your Command-Line Argument Parserhttps://realpython.com/command-line-interfaces-python-argparse#customizing-your-command-line-argument-parser
Tweaking the Program’s Help and Usage Contenthttps://realpython.com/command-line-interfaces-python-argparse#tweaking-the-programs-help-and-usage-content
Providing Global Settings for Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#providing-global-settings-for-arguments-and-options
Fine-Tuning Your Command-Line Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#fine-tuning-your-command-line-arguments-and-options
Setting the Action Behind an Optionhttps://realpython.com/command-line-interfaces-python-argparse#setting-the-action-behind-an-option
Customizing Input Values in Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#customizing-input-values-in-arguments-and-options
Providing and Customizing Help Messages in Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#providing-and-customizing-help-messages-in-arguments-and-options
Defining Mutually Exclusive Argument and Option Groupshttps://realpython.com/command-line-interfaces-python-argparse#defining-mutually-exclusive-argument-and-option-groups
Adding Subcommands to Your CLIshttps://realpython.com/command-line-interfaces-python-argparse#adding-subcommands-to-your-clis
Handling How Your CLI App’s Execution Terminateshttps://realpython.com/command-line-interfaces-python-argparse#handling-how-your-cli-apps-execution-terminates
Conclusionhttps://realpython.com/command-line-interfaces-python-argparse#conclusion
Frequently Asked Questionshttps://realpython.com/command-line-interfaces-python-argparse#frequently-asked-questions
https://realpython.com/feedback/survey/article/command-line-interfaces-python-argparse/liked/?from=article-sidebar
https://realpython.com/feedback/survey/article/command-line-interfaces-python-argparse/disliked/?from=article-sidebar
Building Command Line Interfaces With argparse 1h 3m · 10 lessons https://realpython.com/courses/python-argparse-command-line-interfaces/
Leodanis Pozo Ramoshttps://realpython.com/command-line-interfaces-python-argparse#author
https://realpython.com/command-line-interfaces-python-argparse#reader-comments
intermediatehttps://realpython.com/tutorials/intermediate/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
Getting to Know Command-Line Interfaceshttps://realpython.com/command-line-interfaces-python-argparse#getting-to-know-command-line-interfaces
Command-Line Interfaces (CLIs)https://realpython.com/command-line-interfaces-python-argparse#command-line-interfaces-clis
Commands, Arguments, Options, Parameters, and Subcommandshttps://realpython.com/command-line-interfaces-python-argparse#commands-arguments-options-parameters-and-subcommands
Getting Started With CLIs in Python: sys.argv vs argparsehttps://realpython.com/command-line-interfaces-python-argparse#getting-started-with-clis-in-python-sysargv-vs-argparse
Using sys.argv to Build a Minimal CLIhttps://realpython.com/command-line-interfaces-python-argparse#using-sysargv-to-build-a-minimal-cli
Creating a CLI With argparsehttps://realpython.com/command-line-interfaces-python-argparse#creating-a-cli-with-argparse
Creating Command-Line Interfaces With Python’s argparsehttps://realpython.com/command-line-interfaces-python-argparse#creating-command-line-interfaces-with-pythons-argparse
Creating a Command-Line Argument Parserhttps://realpython.com/command-line-interfaces-python-argparse#creating-a-command-line-argument-parser
Adding Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#adding-arguments-and-options
Parsing Command-Line Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#parsing-command-line-arguments-and-options
Setting Up Your CLI App’s Layout and Build Systemhttps://realpython.com/command-line-interfaces-python-argparse#setting-up-your-cli-apps-layout-and-build-system
Customizing Your Command-Line Argument Parserhttps://realpython.com/command-line-interfaces-python-argparse#customizing-your-command-line-argument-parser
Tweaking the Program’s Help and Usage Contenthttps://realpython.com/command-line-interfaces-python-argparse#tweaking-the-programs-help-and-usage-content
Providing Global Settings for Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#providing-global-settings-for-arguments-and-options
Fine-Tuning Your Command-Line Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#fine-tuning-your-command-line-arguments-and-options
Setting the Action Behind an Optionhttps://realpython.com/command-line-interfaces-python-argparse#setting-the-action-behind-an-option
Customizing Input Values in Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#customizing-input-values-in-arguments-and-options
Providing and Customizing Help Messages in Arguments and Optionshttps://realpython.com/command-line-interfaces-python-argparse#providing-and-customizing-help-messages-in-arguments-and-options
Defining Mutually Exclusive Argument and Option Groupshttps://realpython.com/command-line-interfaces-python-argparse#defining-mutually-exclusive-argument-and-option-groups
Adding Subcommands to Your CLIshttps://realpython.com/command-line-interfaces-python-argparse#adding-subcommands-to-your-clis
Handling How Your CLI App’s Execution Terminateshttps://realpython.com/command-line-interfaces-python-argparse#handling-how-your-cli-apps-execution-terminates
Conclusionhttps://realpython.com/command-line-interfaces-python-argparse#conclusion
Frequently Asked Questionshttps://realpython.com/command-line-interfaces-python-argparse#frequently-asked-questions
Remove adshttps://realpython.com/account/join/
Building Command Line Interfaces With argparsehttps://realpython.com/courses/python-argparse-command-line-interfaces/
object-oriented programminghttps://realpython.com/python3-object-oriented-programming/
script development and executionhttps://realpython.com/run-python-scripts/
packages and moduleshttps://realpython.com/python-modules-packages/
Click here to download the free sample codehttps://realpython.com/bonus/command-line-interfaces-python-argparse-code/
https://realpython.com/quizzes/command-line-interfaces-python-argparse/
Build Command-Line Interfaces With Python's argparsehttps://realpython.com/quizzes/command-line-interfaces-python-argparse/
https://realpython.com/command-line-interfaces-python-argparse#getting-to-know-command-line-interfaces
computer softwarehttps://en.wikipedia.org/wiki/Software
hardware componentshttps://en.wikipedia.org/wiki/Computer_hardware
interfacehttps://en.wikipedia.org/wiki/Interface_(computing)
user interfacehttps://en.wikipedia.org/wiki/User_interface
graphical user interfaces (GUIs)https://realpython.com/python-gui-tkinter/
command-line interfaces (CLIs)https://en.wikipedia.org/wiki/Command-line_interface
Remove adshttps://realpython.com/account/join/
https://realpython.com/command-line-interfaces-python-argparse#command-line-interfaces-clis
terminalhttps://realpython.com/terminal-commands/
Unix-likehttps://en.wikipedia.org/wiki/Unix-like
ls Unix commandhttps://en.wikipedia.org/wiki/Ls
https://realpython.com/command-line-interfaces-python-argparse#commands-arguments-options-parameters-and-subcommands
piphttps://realpython.com/what-is-pip/
Remove adshttps://realpython.com/account/join/
https://realpython.com/command-line-interfaces-python-argparse#getting-started-with-clis-in-python-sysargv-vs-argparse
argvhttps://docs.python.org/3/library/sys.html#sys.argv
syshttps://docs.python.org/3/library/sys.html#module-sys
https://realpython.com/command-line-interfaces-python-argparse#using-sysargv-to-build-a-minimal-cli
pathlib.Pathhttps://realpython.com/python-pathlib/
for loophttps://realpython.com/python-for-loop/
run the scripthttps://realpython.com/run-python-scripts/
https://realpython.com/command-line-interfaces-python-argparse#creating-a-cli-with-argparse
argparsehttps://docs.python.org/3/library/argparse.html?highlight=argparse#module-argparse
standard libraryhttps://docs.python.org/3/library/index.html
Python 3.2https://docs.python.org/3/whatsnew/3.2.html#pep-389-argparse-command-line-parsing-module
389https://www.python.org/dev/peps/pep-0389/
Typerhttps://realpython.com/python-typer-cli/
Clickhttps://realpython.com/python-click/
getopthttps://docs.python.org/3/library/getopt.html
optparsehttps://docs.python.org/3/library/optparse.html
ArgumentParserhttps://docs.python.org/3/library/argparse.html#argparse.ArgumentParser
.add_argument()https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument
.parse_args()https://docs.python.org/3/library/argparse.html?highlight=argparse#argparse.ArgumentParser.parse_args
Namespacehttps://docs.python.org/3/library/argparse.html#namespace
conditional statementshttps://realpython.com/python-conditional-statements/
variablehttps://realpython.com/python-variables/
printshttps://realpython.com/python-print/
Remove adshttps://realpython.com/account/join/
https://realpython.com/command-line-interfaces-python-argparse#creating-command-line-interfaces-with-pythons-argparse
documentationhttps://docs.python.org/3/library/argparse.html#module-argparse
https://realpython.com/command-line-interfaces-python-argparse#creating-a-command-line-argument-parser
ArgumentParserhttps://docs.python.org/3/library/argparse.html#argumentparser-objects
constructorhttps://realpython.com/python-class-constructor/
customizing your argument parserhttps://realpython.com/command-line-interfaces-python-argparse#customizing-your-command-line-argument-parser
https://realpython.com/command-line-interfaces-python-argparse#adding-arguments-and-options
.add_argument()https://docs.python.org/3/library/argparse.html#the-add-argument-method
name or flaghttps://docs.python.org/3/library/argparse.html?highlight=argparse#name-or-flags
Booleanhttps://realpython.com/python-boolean/
Setting the Action Behind an Optionhttps://realpython.com/command-line-interfaces-python-argparse#setting-the-action-behind-an-option
returnshttps://realpython.com/python-return-statement/
Path.stat()https://docs.python.org/3/library/pathlib.html#pathlib.Path.stat
datetime.datetimehttps://realpython.com/python-datetime/
stringhttps://realpython.com/python-strings/
Remove adshttps://realpython.com/account/join/
https://realpython.com/command-line-interfaces-python-argparse#parsing-command-line-arguments-and-options
.parse_args()https://docs.python.org/3/library/argparse.html#the-parse-args-method
Namespacehttps://docs.python.org/3/library/argparse.html#the-namespace-object
https://realpython.com/command-line-interfaces-python-argparse#setting-up-your-cli-apps-layout-and-build-system
lay outhttps://realpython.com/python-application-layouts/
modules and packageshttps://realpython.com/python-modules-packages/
model-view-controller (MVC)https://realpython.com/the-model-view-controller-mvc-paradigm-summarized-with-legos/
pyproject.tomlhttps://realpython.com/python-pyproject-toml/
TOMLhttps://realpython.com/python-toml/
README.mdhttps://dbader.org/blog/write-a-great-readme-for-your-github-project
requirements.txthttps://realpython.com/what-is-pip/#using-requirements-files
unit testshttps://realpython.com/python-testing/
table headerhttps://realpython.com/python-toml/#tables
build systemhttps://realpython.com/pypi-publish-python-package/#build-your-package
publish your apphttps://realpython.com/pypi-publish-python-package/
PyPIhttps://pypi.org/
Remove adshttps://realpython.com/account/join/
https://realpython.com/command-line-interfaces-python-argparse#customizing-your-command-line-argument-parser
https://realpython.com/command-line-interfaces-python-argparse#tweaking-the-programs-help-and-usage-content
user experience (UX)https://en.wikipedia.org/wiki/User_experience
https://realpython.com/command-line-interfaces-python-argparse#setting-the-programs-name
https://realpython.com/command-line-interfaces-python-argparse#define-the-programs-description-and-epilog-message
old-style string-formatting operator (%)https://realpython.com/python-string-formatting/#1-old-style-string-formatting-operator
f-stringshttps://realpython.com/python-f-strings/
NameErrorhttps://realpython.com/python-traceback/#nameerror
https://realpython.com/command-line-interfaces-python-argparse#display-grouped-help-for-arguments-and-options
.add_argument_group()https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument_group
Remove adshttps://realpython.com/account/join/
https://realpython.com/command-line-interfaces-python-argparse#providing-global-settings-for-arguments-and-options
argument_defaulthttps://docs.python.org/3/library/argparse.html#argument-default
constanthttps://realpython.com/python-constants/
fromfile_prefix_charshttps://docs.python.org/3/library/argparse.html#fromfile-prefix-chars
allow_abbrevhttps://docs.python.org/3/library/argparse.html#allow-abbrev
Remove adshttps://realpython.com/account/join/
https://realpython.com/command-line-interfaces-python-argparse#fine-tuning-your-command-line-arguments-and-options
actionhttps://docs.python.org/3/library/argparse.html#action
typehttps://docs.python.org/3/library/argparse.html?highlight=argparse#type
nargshttps://docs.python.org/3/library/argparse.html?highlight=argparse#nargs
defaulthttps://docs.python.org/3/library/argparse.html?highlight=argparse#default
helphttps://docs.python.org/3/library/argparse.html?highlight=argparse#help
https://realpython.com/command-line-interfaces-python-argparse#setting-the-action-behind-an-option
Boolean valuehttps://realpython.com/python-boolean/
Appendshttps://realpython.com/python-append/
listhttps://realpython.com/python-lists-tuples/
consthttps://docs.python.org/3/library/argparse.html#const
Windowshttps://realpython.com/command-line-interfaces-python-argparse#windows-1
Linux + macOShttps://realpython.com/command-line-interfaces-python-argparse#linux-macos-1
argparse.Actionhttps://docs.python.org/3/library/argparse.html#argparse.Action
.__call__()https://docs.python.org/3/reference/datamodel.html#object.__call__
instances into callable objectshttps://realpython.com/python-callable-instances/
.__init__()https://realpython.com/python-class-constructor/#object-initialization-with-__init__
Remove adshttps://realpython.com/account/join/
https://realpython.com/command-line-interfaces-python-argparse#customizing-input-values-in-arguments-and-options
https://realpython.com/command-line-interfaces-python-argparse#setting-the-type-of-input-values
objecthttps://realpython.com/learning-paths/object-oriented-programming-oop-python/
numbershttps://realpython.com/python-numbers/
inthttps://realpython.com/python-numbers/#integers
https://realpython.com/command-line-interfaces-python-argparse#taking-multiple-input-values
nargshttps://docs.python.org/3/library/argparse.html#nargs
Cartesianhttps://en.wikipedia.org/wiki/Cartesian_coordinate_system
https://realpython.com/command-line-interfaces-python-argparse#providing-default-values
defaulthttps://docs.python.org/3/library/argparse.html#default
https://realpython.com/command-line-interfaces-python-argparse#specifying-a-list-of-allowed-input-values
choiceshttps://docs.python.org/3/library/argparse.html#choices
range()https://realpython.com/python-range/
Remove adshttps://realpython.com/account/join/
https://realpython.com/command-line-interfaces-python-argparse#providing-and-customizing-help-messages-in-arguments-and-options
helphttps://docs.python.org/3/library/argparse.html#help
metavarhttps://docs.python.org/3/library/argparse.html#metavar
Remove adshttps://realpython.com/account/join/
https://realpython.com/command-line-interfaces-python-argparse#defining-mutually-exclusive-argument-and-option-groups
https://realpython.com/command-line-interfaces-python-argparse#adding-subcommands-to-your-clis
piphttps://realpython.com/what-is-pip/
pyenvhttps://realpython.com/intro-to-pyenv/
Poetryhttps://realpython.com/dependency-management-python-poetry/
githttps://realpython.com/python-git-github-intro/
.add_subparsers()https://docs.python.org/3/library/argparse.html#sub-commands
dictionary unpacking operator (**)https://realpython.com/iterate-through-dictionary-python/#using-the-dictionary-unpacking-operator
.set_defaults()https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.set_defaults
https://realpython.com/command-line-interfaces-python-argparse#handling-how-your-cli-apps-execution-terminates
error codehttps://en.wikipedia.org/wiki/Error_code
exit statushttps://en.wikipedia.org/wiki/Exit_status
hexadecimalhttps://en.wikipedia.org/wiki/Hexadecimal
.exit(status=0, message=None)https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.exit
.error(message)https://docs.python.org/3/library/argparse.html?highlight=argparse#argparse.ArgumentParser.error
standard error streamhttps://realpython.com/python-subprocess/#the-standard-io-streams
Windowshttps://realpython.com/command-line-interfaces-python-argparse#windows-2
Linux + macOShttps://realpython.com/command-line-interfaces-python-argparse#linux-macos-2
https://realpython.com/command-line-interfaces-python-argparse#conclusion
Click here to download the free sample codehttps://realpython.com/bonus/command-line-interfaces-python-argparse-code/
https://realpython.com/command-line-interfaces-python-argparse#frequently-asked-questions
https://realpython.com/quizzes/command-line-interfaces-python-argparse/
Build Command-Line Interfaces With Python's argparsehttps://realpython.com/quizzes/command-line-interfaces-python-argparse/
https://realpython.com/feedback/survey/article/command-line-interfaces-python-argparse/liked/?from=article-footer
https://realpython.com/feedback/survey/article/command-line-interfaces-python-argparse/disliked/?from=article-footer
Building Command Line Interfaces With argparsehttps://realpython.com/courses/python-argparse-command-line-interfaces/
https://realpython.com/team/lpozoramos/
» More about Leodanishttps://realpython.com/team/lpozoramos/
https://realpython.com/team/aronquillo/
Alexhttps://realpython.com/team/aronquillo/
https://realpython.com/team/asantos/
Aldrenhttps://realpython.com/team/asantos/
https://realpython.com/team/bweleschuk/
Brendahttps://realpython.com/team/bweleschuk/
https://realpython.com/team/bzaczynski/
Bartoszhttps://realpython.com/team/bzaczynski/
https://realpython.com/team/dmastromatteo/
Davidehttps://realpython.com/team/dmastromatteo/
https://realpython.com/team/gahjelle/
Geir Arnehttps://realpython.com/team/gahjelle/
https://realpython.com/team/icurrie/
Ianhttps://realpython.com/team/icurrie/
https://realpython.com/team/jjablonski/
Joannahttps://realpython.com/team/jjablonski/
https://realpython.com/team/kfinegan/
Katehttps://realpython.com/team/kfinegan/
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=command-line-interfaces-python-argparse
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=command-line-interfaces-python-argparse
https://realpython.com/feedback/survey/article/command-line-interfaces-python-argparse/liked/?from=article-comments
https://realpython.com/feedback/survey/article/command-line-interfaces-python-argparse/disliked/?from=article-comments
LinkedInhttps://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Frealpython.com%2Fcommand-line-interfaces-python-argparse%2F
Twitterhttps://twitter.com/intent/tweet/?text=Interesting%20Python%20article%20on%20%40realpython%3A%20Build%20Command-Line%20Interfaces%20With%20Python%27s%20argparse&url=https%3A%2F%2Frealpython.com%2Fcommand-line-interfaces-python-argparse%2F
Blueskyhttps://bsky.app/intent/compose?text=Interesting%20Python%20article%20on%20%40realpython.com%3A%20Build%20Command-Line%20Interfaces%20With%20Python%27s%20argparse%20https%3A%2F%2Frealpython.com%2Fcommand-line-interfaces-python-argparse%2F
Facebookhttps://facebook.com/sharer/sharer.php?u=https%3A%2F%2Frealpython.com%2Fcommand-line-interfaces-python-argparse%2F
Get tips for asking good questionshttps://realpython.com/python-beginner-tips/#tip-9-ask-good-questions
get answers to common questions in our support portalhttps://support.realpython.com
Real Python Community Chathttps://realpython.com/community/
“Office Hours” Live Q&A Sessionhttps://realpython.com/office-hours/
intermediatehttps://realpython.com/tutorials/intermediate/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
Important Standard Library Moduleshttps://realpython.com/learning-paths/standard-library-modules-you-should-know/?utm_source=realpython&utm_medium=web&utm_campaign=related-learning-path&utm_content=command-line-interfaces-python-argparse
Building Command Line Interfaces With argparsehttps://realpython.com/courses/python-argparse-command-line-interfaces/?utm_source=realpython&utm_medium=web&utm_campaign=related-course&utm_content=command-line-interfaces-python-argparse
Python's pathlib Module: Taming the File Systemhttps://realpython.com/python-pathlib/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=command-line-interfaces-python-argparse
Build a Command-Line To-Do App With Python and Typerhttps://realpython.com/python-typer-cli/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=command-line-interfaces-python-argparse
Python's Requests Library (Guide)https://realpython.com/python-requests/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=command-line-interfaces-python-argparse
Build a Python MCP Client to Test Servers From Your Terminalhttps://realpython.com/python-mcp-client/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=command-line-interfaces-python-argparse
The subprocess Module: Wrapping Programs With Pythonhttps://realpython.com/python-subprocess/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=command-line-interfaces-python-argparse
https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fcommand-line-interfaces-python-argparse%2F
Continue »https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fcommand-line-interfaces-python-argparse%2F
Sign-Inhttps://realpython.com/account/login/?next=/command-line-interfaces-python-argparse/
Start Herehttps://realpython.com/start-here/
Learning Resourceshttps://realpython.com/search
Code Mentorhttps://realpython.com/mentor/
Python Referencehttps://realpython.com/ref/
Python Cheat Sheethttps://realpython.com/cheatsheets/python/
Support Centerhttps://support.realpython.com/
Learning Pathshttps://realpython.com/learning-paths/
Quizzes & Exerciseshttps://realpython.com/quizzes/
Browse Topicshttps://realpython.com/tutorials/all/
Live Courseshttps://realpython.com/live/
Bookshttps://realpython.com/books/
Podcasthttps://realpython.com/podcasts/rpp/
Newsletterhttps://realpython.com/newsletter/
Community Chathttps://realpython.com/community/
Office Hourshttps://realpython.com/office-hours/
Learner Storieshttps://realpython.com/learner-stories/
Plans & Pricinghttps://realpython.com/account/join/
Team Planshttps://realpython.com/account/join-team/
For Businesshttps://realpython.com/account/join-team/inquiry/
For Schoolshttps://realpython.com/account/join-team/education-inquiry/
Reviewshttps://realpython.com/learner-stories/
About Ushttps://realpython.com/about/
Teamhttps://realpython.com/team/
Mission & Valueshttps://realpython.com/mission/
Editorial Guidelineshttps://realpython.com/editorial-guidelines/
Sponsorshipshttps://realpython.com/sponsorships/
Careershttps://realpython.workable.com
Press Kithttps://realpython.com/media-kit/
Merchhttps://realpython.com/merch
https://www.youtube.com/realpython
https://x.com/realpython
https://www.linkedin.com/company/realpython-com
https://www.facebook.com/LearnRealPython
https://github.com/realpython/
Privacy Policyhttps://realpython.com/privacy-policy/
Terms of Usehttps://realpython.com/terms/
Securityhttps://realpython.com/security/
Contacthttps://realpython.com/contact/
https://realpython.com/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.