b2KIT

Python Formatter (Black / autopep8)

Format Python code using Black or autopep8 style rules with configurable line length and options.

Tested tool guide Tested browser tools Checked August 16, 2026

What Python Formatter (Black / autopep8) does, with a checked example

This tool reformats pasted Python code to a consistent style. Pick an engine: Black, which rewrites the whole file to its opinionated canonical form, or autopep8, which surgically fixes individual PEP 8 violations and leaves everything else alone. A line-length setting controls where long lines wrap, at 88 characters for Black's default and 79 for PEP 8. Everything runs in the browser, so your code is never uploaded. The surprise most users hit: Black does not just re-indent. It rewrites quotes, explodes long signatures onto one parameter per line, and removes redundant parentheses and backslashes, so the output can look structurally different from the input.

Worked example

A concrete input and expected output from the current implementation.

Input

def very_important_function(template: str, *variables, file: os.PathLike, engine: str, header: bool = True, debug: bool = False):
    """Applies `variables` to the `template` and writes to `file`."""
    with open(file, 'w') as f:
        f.write(template.format(*variables))

Expected output

def very_important_function(
    template: str,
    *variables,
    file: os.PathLike,
    engine: str,
    header: bool = True,
    debug: bool = False,
):
    """Applies `variables` to the `template` and writes to `file`."""
    with open(file, "w") as f:
        f.write(template.format(*variables))

In Black mode with the default 88-character limit, the 129-character signature line cannot fit on one line, so Black explodes it: one parameter per line, a trailing comma after the last parameter, and the closing parenthesis moved to its own line. The single-quoted 'w' is also normalized to double quotes, Black's default quote style. The docstring and the two body lines already fit, so they pass through unchanged. autopep8 mode would not change the quotes and would rewrite far less.

How the result is produced

1

Black rewrites, autopep8 repairs

Black is opinionated and deterministic: the same input always produces the same output, and it re-forms whole constructs, not just indentation, including string quoting, parentheses, blank lines, and trailing commas. autopep8 works the other way: it runs pycodestyle checks and fixes only the violations those checks report, so code that already passes PEP 8 returns nearly unchanged.

2

Line length and options

The line-length setting is the wrap point for long lines, with different defaults per engine: 88 characters for Black, 79 for PEP 8 and autopep8. Options typically control Black's string-quote normalization and its magic-trailing-comma behavior, or autopep8's aggressive multi-pass fixing. In either mode the engine parses the code before formatting, so syntactically invalid input returns an error rather than partially formatted output.

Good uses

  • Standardizing a file with mixed hand-formatted styles before committing it, without installing Black or autopep8 locally.
  • Previewing what Black would do to existing code before adopting it project-wide, so the eventual reformatting commit contains no surprises.
  • Cleaning up a snippet before pasting it into documentation, a chat, or a code review comment.

Limits and checks

  • A syntax error means no output: both engines parse the code first, so a missing parenthesis, quote, or colon returns an error rather than formatted code. Nothing in your paste is partially formatted or silently dropped.
  • The line length you set is a target, not a guarantee: Black does not split long string literals and does not rewrap the text inside comments, so lines containing those can still exceed the limit and pass through untouched.
  • The engines disagree by design. autopep8 will not change quotes, trailing commas, or wrapping that PEP 8 merely tolerates, so autopep8 output and Black output for the same input are different results. And in Black mode, a trailing comma left in a call forces every argument onto its own line, the documented magic trailing comma.

Common questions

Will it change my single quotes to double quotes?

In Black mode, yes: ordinary single-quoted strings are rewritten to double quotes (Black switches to single quotes only when the string itself contains double quotes), and this can be disabled with the string-normalization option. The text inside docstrings is not reformatted. autopep8 mode never touches quotes. If quote style matters to you, this is the biggest behavioral difference between the two engines.

Is my code uploaded anywhere?

No. Formatting runs entirely in your browser and nothing is sent to a server, so pasted code, including proprietary source, stays on your machine; there is no upload step or server-side history. The trade-off is that the page ships a fixed engine version, so Python syntax newer than that version may be rejected until the page updates.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools