Skip to main content

Another Uncompromising Code Formatter for Python.

Project description

StraitJacket: Another Uncompromising Code Formatter for Python

StraitJacket is a wrapper around black which implements post processing to perform automatic code alignment.


MIT License Supported Python Versions PyCalVer v201904.0010-beta PyPI Version PyPI Downloads

Code Quality/CI:

Build Status Type Checked with mypy Code Coverage Code Style: sjfmt

Name role since until
Manuel Barkhau ( author/maintainer 2018-10 -


Example of automatic alignment.

class TokenType(enum.Enum):           # class TokenType(enum.Enum):

    INDENT    = 0                     #     INDENT = 0
    SEPARATOR = 1                     #     SEPARATOR = 1
    CODE      = 2                     #     CODE = 2

Indent      = str                     # Indent = str
RowIndex    = int                     # RowIndex = int
ColIndex    = int                     # ColIndex = int
OffsetWidth = int                     # OffsetWidth = int
TokenTable  = typ.List[TokenRow]      # TokenTable = typ.List[TokenRow]


Usage is exactly the same as for black, except that the command is named sjfmt.

$ pip install straitjacket
$ sjfmt --help
Usage: sjfmt [OPTIONS] [SRC]...

  Another uncompromising code formatter.

  -l, --line-length INTEGER       How many characters per line to allow.
                                  [default: 88]
  --py36                          Allow using Python 3.6-only syntax on all

Editor/Tooling Integration

Plugins for your editor usually support setting a custom path to black. You can simply point to sjfmt instead.


$ which sjfmt
$ which sjfmtd


C:\Users\Username>where sjfmt


PS C:\Users\Username> (gcm sjfmt).Path



    "black_command": "C:/Python37/Scripts/sjfmt.exe",
    "black_line_length": 100,
    // ...

Document formatting can be triggered with Ctrl+Alt+F.

vscode python extension

    "python.formatting.provider": "black",
    "python.formatting.blackPath": "C:\\Python37\\Scripts\\sjfmt.exe",
    "python.formatting.blackArgs": [
        "--line-length", "100",

Document formatting can be triggered with Shift+Alt+F.


Install the plugin black-pycharm, which can be found in Settings > Plugins > Brows Repositories. You may have to restart PyCharm for the plugin to load.

To configure the path, go to Settings > Tools > BlackPycharm Configuration and set Path to Black executable to the location of the sjfmt binary.

You can reformat your code using Ctrl + Shift + A to access the Find Action panel. The name of the action to format your code is Reformat code (BLACK). You may want to rebind this action, at least in my setup the default binding didn't seem to work.


By the nature of this plugin, certain flake8 codes will be violated. This is an excerpt from what you might put in your setup.cfg to ignore these:

ignore =
    # No whitespace after paren open "("
    # No whitespace before paren ")"
    # Whitespace before ":"
    # Multiple spaces before operator
    # Multiple spaces after operand
    # Multiple spaces before keyword

Changelog for straitjacket


  • Update for release of black==19.3b0


TLDR: more bugfixes and updated documentation


TLDR: no major changes, just bug fixes.

  • Fixed #1: Disable right alignment of numbers when not preceded by a number.
  • Fixed #3: Disable alignment when preceded by a multiline string.
  • Fixed #4: Excessive whitespace in non aligned context.
  • Fixed #8: Double and single quotes around strings not consistent


  • Initial release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for straitjacket, version 201904.10b0
Filename, size File type Python version Upload date Hashes
Filename, size straitjacket-201904.10b0-py36.py37-none-any.whl (12.5 kB) File type Wheel Python version py36.py37 Upload date Hashes View
Filename, size straitjacket-201904.10b0.tar.gz (17.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page