<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-write-a-great-command-line-application---dan-craig-vuuwvuutf" -->

---
title: How to Write a Great Command Line Application - Dan Craig
description: A conference talk walks through building maintainable, testable Python command line applications using argparse, covering argv/exit codes fundamentals, type...
canonical: https://daily.dev/posts/how-to-write-a-great-command-line-application---dan-craig-vuuwvuutf
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Write a Great Command Line Application - Dan Craig | daily.dev
og:description: A conference talk walks through building maintainable, testable Python command line applications using argparse, covering argv/exit codes fundamentals, type...
og:url: https://daily.dev/posts/how-to-write-a-great-command-line-application---dan-craig-vuuwvuutf
og:image: https://api.daily.dev/og/posts/VuuwVUUtf.png
og:image:alt: How to Write a Great Command Line Application - Dan Craig
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Write a Great Command Line Application - Dan Craig

**[PyCon US](https://daily.dev/sources/pyconus)** · 27 min read · 0 upvotes · 0 comments

## Summary

A conference talk walks through building maintainable, testable Python command line applications using argparse, covering argv/exit codes fundamentals, type coercion, file handling with FileType, refactoring into a testable main(argv) pattern with a do() function using kwargs expansion, handling KeyboardInterrupt and broken pipe errors gracefully, using logging with -v verbosity counts, and closes with a survey of third-party CLI libraries (click, typer, Tyro) plus a UV shebang tip using PEP 723 inline dependencies. It also flags that argparse's FileType helper was recently deprecated as of Python 3.14 because it leaves open file handles unmanaged, and sketches a replacement pattern using context managers.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=sflWQAxZV0U>

## Questions this post answers

### Is argparse's FileType being deprecated in Python 3.14?

Yes, argparse.FileType has been deprecated as of Python 3.14. The Python core developers decided its downsides outweigh its benefits, mainly because it returns an open file handle with no mechanism for closing it afterward. There is no deprecation warning yet and no timeline for full removal, and the official documentation has not yet suggested a replacement pattern.

_Track how Python's FileType deprecation affects your CLI scripts and pick a replacement pattern on daily.dev._

### How do I stop a broken pipe error from showing a stack trace when piping Python output to head?

Suppress the BrokenPipeError by catching it around your program's exit logic and redirecting standard output to devnull before closing, following the workaround documented in the Python signal module docs. The error happens because head closes the pipe after reading enough lines, and Python's final flush to standard out then fails since the file handle is already closed.

_Developers piping long-running Python CLI output into Unix tools can compare fixes like this on daily.dev._

### How do I make a Python script executable without needing a virtual environment set up first?

Use the shebang line '#!/usr/bin/env -S uv run' along with PEP 723 inline dependency metadata in the script. This lets uv read the declared dependencies and Python version directly from the script and create a cached ephemeral virtual environment automatically, so no manual virtual environment setup is required to run the script.

_Anyone standardizing self-contained Python scripts can follow uv-based shebang patterns discussed on daily.dev._

## Similar posts on daily.dev

- [Python Command Line Arguments: sys.argv, argparse, getopt](https://daily.dev/posts/python-command-line-arguments-sys-argv-argparse-getopt-ookr1pixv) · DigitalOcean Community · 2 upvotes · 0 comments
- [Scripting good practices in Python](https://daily.dev/posts/scripting-good-practices-in-python-gdk4udvhp) · Bite Code · 26 upvotes · 1 comments
- [Structuring Your Python Script – Real Python](https://daily.dev/posts/structuring-your-python-script-real-python-qj5o3ub1o) · Real Python · 0 upvotes · 0 comments
- [Learn Command Line Interface \(CLI\) Development with Dart: From Zero to a Fully Published Developer Tool](https://daily.dev/posts/learn-command-line-interface-cli-development-with-dart-from-zero-to-a-fully-published-developer-t-yihtfpndi) · freeCodeCamp · 4 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#testing](https://daily.dev/tags/testing), [#cli](https://daily.dev/tags/cli), [#unix](https://daily.dev/tags/unix)

[View this post on daily.dev](https://daily.dev/posts/how-to-write-a-great-command-line-application---dan-craig-vuuwvuutf)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Write a Great Command Line Application - Dan Craig","url":"https://daily.dev/posts/how-to-write-a-great-command-line-application---dan-craig-vuuwvuutf","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-write-a-great-command-line-application---dan-craig-vuuwvuutf"},"datePublished":"2026-08-25T18:58:23.724Z","dateModified":"2026-09-14T09:22:06.677Z","description":"A conference talk walks through building maintainable, testable Python command line applications using argparse, covering argv/exit codes fundamentals, type...","image":"https://i.ytimg.com/vi/sflWQAxZV0U/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/sflWQAxZV0U/sddefault.jpg","isAccessibleForFree":true,"articleSection":"PyCon US","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"PyCon US","logo":"https://media.daily.dev/image/upload/s--DLedNxG1--/f_auto,q_auto/v1777800767/logos/pyconus?_a=BAMAMiWQ0","url":"https://daily.dev/sources/pyconus"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-write-a-great-command-line-application---dan-craig-vuuwvuutf","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,testing,cli,unix","timeRequired":"PT27M","video":{"@type":"VideoObject","name":"How to Write a Great Command Line Application - Dan Craig","description":"A conference talk walks through building maintainable, testable Python command line applications using argparse, covering argv/exit codes fundamentals, type...","thumbnailUrl":"https://i.ytimg.com/vi/sflWQAxZV0U/sddefault.jpg","uploadDate":"2026-08-25T18:58:23.724Z","duration":"PT27M","url":"https://api.daily.dev/r/VuuwVUUtf","embedUrl":"https://www.youtube.com/embed/sflWQAxZV0U"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"PyCon US","item":"https://daily.dev/sources/pyconus"},{"@type":"ListItem","position":3,"name":"How to Write a Great Command Line Application - Dan Craig"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-write-a-great-command-line-application---dan-craig-vuuwvuutf#faq","mainEntity":[{"@type":"Question","name":"Is argparse's FileType being deprecated in Python 3.14?","acceptedAnswer":{"@type":"Answer","text":"Yes, argparse.FileType has been deprecated as of Python 3.14. The Python core developers decided its downsides outweigh its benefits, mainly because it returns an open file handle with no mechanism for closing it afterward. There is no deprecation warning yet and no timeline for full removal, and the official documentation has not yet suggested a replacement pattern. Track how Python's FileType deprecation affects your CLI scripts and pick a replacement pattern on daily.dev."}},{"@type":"Question","name":"How do I stop a broken pipe error from showing a stack trace when piping Python output to head?","acceptedAnswer":{"@type":"Answer","text":"Suppress the BrokenPipeError by catching it around your program's exit logic and redirecting standard output to devnull before closing, following the workaround documented in the Python signal module docs. The error happens because head closes the pipe after reading enough lines, and Python's final flush to standard out then fails since the file handle is already closed. Developers piping long-running Python CLI output into Unix tools can compare fixes like this on daily.dev."}},{"@type":"Question","name":"How do I make a Python script executable without needing a virtual environment set up first?","acceptedAnswer":{"@type":"Answer","text":"Use the shebang line '#!/usr/bin/env -S uv run' along with PEP 723 inline dependency metadata in the script. This lets uv read the declared dependencies and Python version directly from the script and create a cached ephemeral virtual environment automatically, so no manual virtual environment setup is required to run the script. Anyone standardizing self-contained Python scripts can follow uv-based shebang patterns discussed on daily.dev."}}]}
```

