µfmt: safe, atomic formatting and import sorting
µfmt is a code formatter and import sorter for Python and Visual Studio Code,
built on top of black and µsort:
Black makes code review faster by producing the smallest diffs possible.
Blackened code looks the same regardless of the project you’re reading.
μsort is a safe, minimal import sorter. Its primary goal is to make no “dangerous”
changes to code, and to make no changes on code style.
µfmt formats files in-memory, first with µsort and then with black, before
writing any changes back to disk. This enables a combined, atomic formatting steps in
VS Code, without any chance of conflict or intermediate changes between the import
sorter and the code formatter.
- This extension requires Python version 3.7 or newer.
- The extension comes bundled with µfmt
Older versions of µfmt may work, but are not supported.
Once installed, "µfmt" will be available as a formatter for Python files
µfmt can be set as the default formatter by adding the following to your settings:
or through the command pallete option "Format Document With...":
Be sure to disable the legacy Python formatter, if enabled:
Format on Save
VS Code can automatically format your Python files when saving by adding the following
to your settings: