Build AWESOME CLIs With Click in Python

preview_player
Показать описание

In this video, I'll guide you through creating a Command Line Interface (CLI) tool in Python using the Click package. We'll build a simple note-taking tool that can write, read, update, and delete notes. Stick around until the end to discover some hidden features Click offers right out of the box that many people don't know about.

🔖 Chapters:
0:00 Intro
0:31 Story time
2:45 Creating the project
4:00 Create the CLI
4:54 Commands
6:33 Arguments vs Options
7:58 Creating the command
10:40 Connecting to the Entry point
12:16 The design of click
14:19 Continuing the connection
16:46 Using click context
18:25 Adding config to our tool
20:26 Giving the option to create the config
22:59 Things you get for free with Click
24:12 Final Thoughts
24:52 Outro

#arjancodes #softwaredesign #python
Рекомендации по теме
Комментарии
Автор

Hi Arjan. Thanks for yet another super clear and instructive video. And, ... at the right time as I am creating a CLI for various related functionalities already written in Python. So, again thanks!

Un your video I saw you were using poetry. As this was not the main focus of this video you simply executed poetry commands. I looked back in your video history and saw that in 2023 you posted a video titled "How to Build a Complete Python Package Step-by-Step". There you used setuptools for packaging, and not (yet) poetry.

Even after many years of Python programming I find packaging a complex topic. For my work I would very much like to use poetry for packaging and distribution.
I would really love to see you (and your team) create an in-depth video about poetry, covering topics like a build frontend and backend.

jurgenrusch
Автор

I don't really see a point in using Click directly anymore. Typer does the same thing but better, using type hints to set up everything. It's also based on Click, so if you need something that Typer doesn't offer natively, you can use Click through Typer to do what you want. IMO, Click by itself doesn't offer enough to warrant adding a dependency, as stdlib's argparse is quite powerful and easy to use.

maleldil
Автор

Nice video!!
I would love to see a video on most commonly used libraries for creating cli programs in python in the industry with their pros and cons

Aceptron
Автор

Click is a great library. A couple of features I used were Multi Command Chaining and Multi Command Pipelines. May I suggest a video with some advanced features of Click. It would be awesome. Great video Arjan and thanks for sharing.

EusebioResende
Автор

> Also sometimes called a flag
Correct me if I'm wrong, but my understanding is that flags are boolean values (they're either present or they aren't) and don't require any additional information, whereas options are necessarily followed by a value.
Sometimes they can go either way, depending on context. For example, "--help" might be a flag if used by itself, or it can be an option if used like "--help <topic>".

DJStompZone
Автор

This is absolutely fascinating! IAbout nine years back, had used click to create a command line tool which took a file list of tsv and output a combined xls file with the original tsv files as sheets 😀. This has been a nice refresher.

ladycoder
Автор

Yes to pytest. As I was watching I was thinking this video would be even better if it use TDD right from the beginning where pytest and coverage was used. Create the empty functions, write the test of expected behaviour, complete the functions, write next set of functionality, rinse and repeat. Would demonstrate a great way to "approach" development that would help a lot of people see some good technique and practices.

iamrodos
Автор

How to test CLI would undoubtedly be a great addition to a possible continuation of this topic.

Deiha-zd
Автор

Great video. I tend to use classic argparse at my workplace but I’ll give click a try for future projects 👍

bryangarcia
Автор

I liked your introduction story. It instantely got me hooked

patrickkurmann
Автор

Great video Arjan :) Good job. We use click in our company everywhere. It's really nice package.

riki
Автор

Great job!
Please prepare more extended example with pytest, pydantic
It's a pleasure to learn programming with you!

Greetings!

Geo-Artist
Автор

I would love to see an additional video covering some more advanced usage like adding a logger for scripts or conditional parameters (like if one option/arg is supplied make another not required)

snakehunt
Автор

Thanks for sharing this. I've been using docopt for a long time and while I like it is can be very finicky to use. Click looks a lot more deterministic without all the hassle of using argparse directly. Will definitely try it with my next project.

realpdm
Автор

Thanks for interesting and detailed explanation!

iaroslavdavydiak
Автор

Yes would love to see how to add pydantic to add validation to configuration values and with a logger and pytest!

johnsontea
Автор

I am a DevOps Engineer. Any time I need a CLI tool to help with some task or another, I write it in Python. That is because I have yet to find anything I needed to do on my Linux servers, for which a package did not already exist. For almost all of them I use Click and Rich and when I don't, it is because I need a very quick solution without dependencies outside of the standard library.

jg
Автор

Thank you for the professional content you produce. I learned a lot from you. ❤
Please do more rust

MohsenPadidar
Автор

Looks cool! I usually write my more complex CLI tools in Go with Cobra which has a great interface. This looks kind of similar but for Python instead!

phortheman
Автор

21:40 Perhaps the 'platformdirs' library is a good option for determining the location of configuration files.

Deiha-zd