Registry / devops / shfmt-py

shfmt-py

JSON →
library4.0.0pypypiunverified

A Python wrapper around shfmt, the shell script formatter. Downloads and manages the shfmt binary automatically. Current version 3.12.0.2, wraps mvdan/sh v3.12.0. Supports Python >=3.9. Releases follow upstream shfmt versions with a patch suffix.

pip install shfmt-py
INSTALL
IMPORT
SIG · SHFMT-PY
S
shfmt-py
devopspythonv4.0.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.0.0 · 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 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

shfmt
import shfmt_py
from shfmt_py import shfmt

Basic usage: call shfmt() with code string and optional arguments. Use write=True to overwrite file. Use filename= to pass filename for error detection context.

from shfmt_py import shfmt # Format a string code = 'if [ $foo = bar ]; then echo hello ; fi' formatted = shfmt(code, lang='bash', space_redirects=True) print(formatted) # Format a file shfmt(code, write=True, filename='script.sh') # Check for formatting differences (intended for CI) import sys from shfmt_py import ShfmtError try: shfmt(code, filename='script.sh') # raises ShfmtError if not formatted except ShfmtError as e: print(e.diff()) sys.exit(1)
shfmt --version
Debug
Known issues
gotchaThe shfmt binary is downloaded automatically on first use, which may fail in air-gapped environments. Cache the binary manually.
fix
Set environment variable SHPATH to a pre-downloaded binary path, or use the binary caching mechanism (see docs).
affects: all
deprecatedPassing a string to the 'lang' parameter without specifying 'filename' may produce incorrect formatting. In future versions, 'filename' will be required for proper language detection.
fix
Always provide a filename (e.g., 'script.sh') when calling shfmt() to ensure correct language detection.
affects: <4.0.0
gotchaThe package version includes the upstream shfmt version plus a patch number (e.g., 3.12.0.2). This can cause confusion when comparing versions. Breaking changes in shfmt reflect in the first three numbers.
fix
Check upstream shfmt release notes for breaking changes. The fourth number is the wrapper patch.
affects: all
Upgrade
Version history
4.0.0latest on PyPI · released May 13, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
20
Resources
shfmt-py — pip install shfmt-py · libregistry