#2 BRIEF: CLI, Python
Exploring new and popular open source CLI tools and Python packages, including fd, dive, ruff and more
Welcome to Behind the Mutex! Our weekly newsletter summarizes new notable activity in open-source, suggest pro-tips and highlights interesting tweets.
In Case You Missed It
This section covers Behind the Mutex posts of the past week.
Open Source Landscape
Behind the Mutex picks a few categories and explores new and popular projects and features there.
CLI
CLI remains a key user interface with all sorts of new tools and applications being regularly added or improved. It is definitely worth keeping an eye on this area as sometimes a new tool can give you an instant performance boost.
fd: https://github.com/sharkdp/fd
fd
is a user-friendly alternative to the well-known and respected find
command. Part of the friendliness comes from that fact that it is up to an order of magnitude faster than find
, thanks to the regex
and ignore
Rust crates which also power ripgrep. Some of its notable features:
Reasonable defaults, including various ignore rules
Uses colors to highlight different file types
Supports parallel and batch command execution via -x and -X correspondingly
zx: https://github.com/google/zx
If you find writing complex shell scripts challenging due to various reasons (one of them might be that you don’t like Bash), and ever wondered if, say, JavaScript might be a better choice, you should definitely check zx
. It is a Node.JS package that provides a number of goodies for your shell scripts:
Asynchronous process spawning:
$()
returns aProcessPromise<ProcessOutput>
and it is up to you toawait
until it terminates or process its standard streams in real timeAutomatic escaping and quotes: no need to worry about the correct way to pass arguments to your commands as even
Arrays
are property handledImperative-style error handling:
try-catch
non-zero exited processesBuilt-in functions, such as
cd
,fetch
,retry
and more
If you also need to run some commands remotely, you can look at webpod which offers ssh()
that is a factory that creates a function bound to the specified SSH config:
Dive: https://github.com/wagoodman/dive
Dive is an interactive CLI tool for inspecting your Docker/OCI container images. It is a great time saver when it comes to understanding the FS changes each layer brings. Its most distinctive capabilities are:
Inspecting FS changes layer-by-layer: you chose the layer on the upper left pane and see the combined FS changes on the right pane, with the highlighted difference the selected layer contributes
Estimate the efficiency score and potential wasted space of every layer
Quickly iterate on build-inspect cycles by using the build shortcut:
dive build -t tag .
Python Ecosystem
Having surpassed all other languages for last two years in the TIOBE index, Python is getting more and more popular, thanks to its multi-purpose capabilities, vast collection of high-quality packages and its great community. Thus, Behind the Mutex is set to be covering the Python ecosystem on a regular basis.
Ruff: https://github.com/charliermarsh/ruff
Running static code analysis is important. Both locally and as part of a CI pipeline. Not only such tools guide you, highlight potential issues and even try to fix them, but they also significantly streamline collaboration. A typical Python project may be instrumented with a number of various linters, some of which perform better than others. In a relatively big codebase these tools can be a toll in terms of time it takes for all of them to run against all the modules.
Many have used the well-known and loved tools like Flake8 and isort for years and without a doubt appreciated their usefulness. Ruff brings the same functionality, but it does it one, two and sometimes even three order of magnitude faster thanks to Rust.
One more interesting peculiarity is that the package has no dependencies. This makes its installation ridiculously fast too.
Integrations with pre-commit, Github Actions and VS Code are available.
The —-fix
option also comes handy to resolve some straight-forward linting issues.
Many popular projects already use Ruff. Don’t miss out and try it yourself.
HTTPX: https://github.com/encode/httpx
When it comes to performing HTTP requests in asynchronous code, aiohttp pops in many minds right away. No wonder, as the package has been around for a relatively long time and is definitely battle-proven. Though if you want to see a more frequent cadence of patch and minor releases of your HTTP client, HTTPX might be worth looking at.
Some of HTTPX’s differentiating features and capabilities include:
Support of both sync and async APIs partially compatible with requests
HTTP/2 for those rare cases when you really need it
A built-in CLI:
httpx
Rich: https://github.com/Textualize/rich
Building user interfaces is hard, but building them for terminals is even harder. Rich offers rich text and beautiful formatting while hiding the underlying complexity of rendering in various terminal applications. The set of built-in features is impressive. You can output colored and styled text, render tables, code with syntax highlighting, Markdown, progress bars and much more.
If you need to build a CLI tool and want to add elements of interactivity to it, Rich is definitely the way to go.
But if you need something more…
Textual: https://github.com/Textualize/textual
Built on top of Rich, Textual brings user interfaces in terminals to the whole new level. The package is a framework for rapid development of terminal-based applications, inspired by Web. Textual provides a way to build terminal apps pretty much similar to how Web apps are built. DOM, Widgets, CSS, Events, reactivity and much more, available for your next CLI app.
If you have any feedback or would like to see certain open-sources projects highlighted in our upcoming summaries and reviews, please feel free to comment, send an email or DM the author on Twitter @dalazx.
Until next Tuesday,
Behind the Mutex.