Registry / testing / ufmt
library2.9.1pypypi✓ verified 24d ago

ufmt (pronounced "micro-fmt") is a safe, atomic code formatter for Python, built on top of the popular `black` formatter and `µsort` import sorter. It combines their functionality into a single, atomic step, ensuring consistent code style and import order without intermediate conflicts. Currently at version 2.9.1, it requires Python 3.10 or newer and maintains an active release cadence.

pip install ufmt
INSTALL
IMPORT
SIG · UFMT
U
ufmt
testingpythonv2.9.1
Install
3.7s avg
Import
1305ms
Disk
42MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.9.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.428s · 40.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.7s · import 1.182s · 46MB
42MB installed
● package 42MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ufmt_paths
from ufmt import ufmt_paths
High-level API for formatting multiple files or directories recursively.
ufmt_file
from ufmt import ufmt_file
High-level API for formatting a single file.

This quickstart demonstrates how to use the `ufmt_file` API to programmatically format a Python file. It creates a temporary file, formats it with `ufmt`, prints the original and formatted content, and then cleans up the temporary file. For simple command-line usage, run `ufmt format <path>` in your terminal.

import os from pathlib import Path from ufmt import ufmt_file from black import Mode, TargetVersion from usort import Config def main(): # Create a dummy Python file dummy_content = ( "import os, sys\n\ndef my_func ( param1, param2 ) :\n \"\"\"A docstring.\"\"\"\n return param1 + param2\n" ) dummy_file = Path("temp_module.py") dummy_file.write_text(dummy_content) print(f"Original content of {dummy_file.name}:\n---\n{dummy_content.strip()}\n---") # Define black and usort configs (optional, ufmt can detect from pyproject.toml) # For this example, we provide minimal configs black_config = Mode(target_versions={TargetVersion.PY310}) usort_config = Config() # Format the file using the ufmt API result = ufmt_file( path=dummy_file, black_config=black_config, usort_config=usort_config, return_content=True ) if result.error: print(f"Error formatting {dummy_file.name}: {result.error}") elif result.changed: print(f"Formatted content of {dummy_file.name}:\n---\n{result.after.decode().strip()}\n---") else: print(f"{dummy_file.name} was already formatted correctly.\n---\n{result.after.decode().strip()}\n---") # Clean up the dummy file dummy_file.unlink() if __name__ == "__main__": main()
ufmt --version
Debug
Known issues
breakingufmt v2.0.0 dropped support for Python 3.6. v2.2.0 further dropped support for Python 3.7. Users must be on Python 3.10 or newer (as of 2.9.1).
fix
Upgrade your Python environment to 3.10 or newer.
affects: >=2.0.0
breakingThe `ufmt_file` and `ufmt_paths` API functions now require keyword arguments for all parameters.
fix
Update calls to `ufmt_file()` and `ufmt_paths()` to use keyword arguments (e.g., `ufmt_file(path=my_path)`).
affects: >=2.0.0
deprecatedThe `ufmt_string` function was deprecated in v2.0.0 and will be removed in v3.0. Use `ufmt_bytes` instead for formatting raw byte content.
fix
Migrate from `ufmt_string` to `ufmt_bytes` for programmatic formatting of string-like content.
affects: >=2.0.0
gotchaFor stable and reproducible CI workflows, always pin the versions of `ufmt`, `black`, and `usort` in your `requirements.txt` or `pyproject.toml` to prevent unexpected formatting changes introduced by newer versions of these transitive dependencies.
fix
Pin `black==X.Y.Z`, `usort==A.B.C`, and `ufmt==P.Q.R` in your dependency declarations.
affects: all
gotchaPrior to v2.1.0, `ufmt` could fail to format Python 3.10+ `match case` statements due to `µsort`'s reliance on `LibCST`. This was fixed by enabling `LibCST`'s native parser by default. If using older `ufmt` versions, an `LIBCST_PARSER_TYPE=native` environment variable was required.
fix
Upgrade to `ufmt` version 2.1.0 or newer, or set the environment variable `LIBCST_PARSER_TYPE=native` before running `ufmt`.
affects: <2.1.0
Errors
Common errors & fixes
ufmt: command not found
The `ufmt` command-line tool is not found in your system's PATH, likely because it was not installed or the Python environment where it was installed is not active.
fix
Install `ufmt` using `pip install ufmt` or activate the virtual environment where it's already installed.
ERROR: ufmt requires Python >=3.10, but you are using Python 3.9.x
You are attempting to install or run `ufmt` with a Python version older than 3.10, which is its minimum requirement.
fix
Upgrade your Python version to 3.10 or newer, or switch to a Python environment that meets the version requirement.
ModuleNotFoundError: No module named 'ufmt'
The `ufmt` library is not installed in the Python environment where the script is being executed, or the environment is not correctly activated.
fix
Install the library using `pip install ufmt` in the active Python environment.
Error: No such option: --some-black-option
You are attempting to use a command-line option that is not directly supported by `ufmt`, even if it's a valid option for `black` or `µsort`. `ufmt` handles configuration for these tools via `pyproject.toml`.
fix
Remove the unsupported CLI option and instead configure `black` or `µsort` specific settings in your `pyproject.toml` file, which `ufmt` will automatically detect.
Upgrade
Version history
2.9.1latest on PyPI · released Feb 8, 2026
Audit
Dependencies
blackrequiredCore dependency for code formatting. It is highly recommended to pin its version for consistent CI results.
usortrequiredCore dependency for import sorting. It is highly recommended to pin its version for consistent CI results.
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources