{"library":"shfmt-py","title":"shfmt-py","description":"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.","language":"python","status":"active","last_verified":"Fri May 01","install":{"commands":["pip install shfmt-py"],"cli":{"name":"shfmt","version":"v3.13.1"}},"imports":["from shfmt_py import shfmt","from shfmt_py import ShfmtError"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from shfmt_py import shfmt\n\n# Format a string\ncode = 'if [ $foo = bar ]; then echo hello ; fi'\nformatted = shfmt(code, lang='bash', space_redirects=True)\nprint(formatted)\n\n# Format a file\nshfmt(code, write=True, filename='script.sh')\n\n# Check for formatting differences (intended for CI)\nimport sys\nfrom shfmt_py import ShfmtError\ntry:\n    shfmt(code, filename='script.sh')  # raises ShfmtError if not formatted\nexcept ShfmtError as e:\n    print(e.diff())\n    sys.exit(1)","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}