Discovering Click511 words. Time to Read: About 5 minutes.
I’m going to have two posts here in quick succession, because I learned a bunch of things in the last couple weeks all in a row that are really cool. The first one I want to talk about is Click, which is a Python framework for quickly making command-line interface (CLI) programs. I have been using it recently to make a tool that automates a few of the more repetetive tasks at work. The basics are really simple!
And that’s it! You can run it like so:
And it checks inputs to ensure the right number, count, and even type if you specify it. If the user puts the wrong thing in or is unsure how to use it, they can simply:
And there are a whole bunch of other great things about it. There is built in support for testing to aid with TDD and writing tests in general. With my PQ-CLI, my goal was to do the project like a real big kid, with license, readme, git repo, writing tests first, etc. I think I did ok with that, and I’m still going. There is support for grouping and nexting and piping commands. And the documentation is really helpful (examples first, API and documentation later). I wasn’t suprised when I looked up at the url for Click and realized it was part of the Pocoo family (the guy who made Flask, among a bunch of other useful projects). Anyways, check out my project for more examples and take a stop by the main Click project page for even more guidance.Author: Ryan Palo | Tags: python tools | Buy me a coffee