Pyrfecter logo Pyrfecter

Lint, format, and modernize your Python code to make it positively perfect.

Input
Output

Linting & Analysis

Pyrfecter: the secure online Python formatter

What is code formatting?

Code formatting is the practice of automatically updating the appearance of your code without changing what it does. In other words, it changes code syntax but not semantics.

Code formatters provide consistent code output given inputs of different styles, for example rewriting single quotes (') as double quotes (").

As a quick example, here's some unformatted Python code:

x = {  'a':37,'b':42,

'c':927}

And the same Python code formatted formatted with Black:

x = {"a": 37, "b": 42, "c": 927}

Spacing, newlines, and quotes were all updated with consistent rules:

Why format with Pyrfecter?

Why not! It's free, easy, and secure because your code never leaves your browser.

Pyrfecter uses Black to format your Python code. Black is maintained by the Python Software Foundation, so you can be sure that Python code formatted with Pyrfecter is going to match Python best practices.

But that's not all: Pyrfecter also sorts and formats Python imports with isort. Check out the Sort imports example for more information.

What benefits does code formatting offer?

Consistency

When a project has code formatting, all code will look the same regardless of who wrote it.

Faster code reviews

Code that is difficult to read can be difficult to understand, making it harder for reviewers to engage with your code.

Plus, with nicely formtted code, reviewers won't have to comment on formatting-related changes, which leaves more time to reivew the code's function rather than its form.

Other Python formatters

Ruff

Ruff is an increasingly popular linter and formatter for Python. It's written in Rust and optimized to be very fast.

If you have a very large code base or if your formatting needs to be lightning-fast, give Ruff a try:

https://docs.astral.sh/ruff/formatter/

autopep8

autopep8 formats Python code according to PEP 8 - Style Guide for Python Code. It builds on top of pycodestyle (formerly known as "pep8") by automatically fixing issues that pycodestyle finds.

See https://github.com/hhatto/autopep8 for more information.

YAPF

YAPF, or "Yet Another Python Formatter", is owned by Google and maintained by open-source contributors. Check it out at https://github.com/google/yapf.