Pyrfecter logo Pyrfecter

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

Input
Output

Linting & Analysis

What is Pyrfecter?

Pyrfecter is a Python code linter, formatter, and improver that runs entirely in your browser. It uses Pyodide under the hood, along with a number of excellent Python code quality tools (listed below).

What can I expect?

Cleaner Python code! Pyrfecter aims to be maximally helpful and minimally disruptive by performing a number of improvements to your Python code without changing how it works. (That's the goal, anyway. If your code was changed in a breaking way, please get in touch.)

Code is formatted to Black's default of 88 characters. This might be configurable in the future, but for now if you want to reformat your code with a different line length, you can do that in the Black playground:

  1. Visit the Black playground at https://black.vercel.app
  2. Click the settings gear (⚙️) in the bottom left
  3. Specify your new line length in the "Line Length" input
  4. Wait for your code to be reformatted automatically

Why should I use Pyrfecter?

That's a good question. Pyrfecter was designed to be used to tidy up Python on-the-fly. Maybe you're just learning and you want to give your code some polish without installing and configuring all the tools Pyrfecter uses. Maybe you have a Python code snippet you want to include in documentation for a project that isn't a Python project, like API documentatino showing how to make a request with Python.

But whatever your reasons, if you're looking for cleaner Python code, Pyrfecter can help.

Are there other tools that do similar things?

Certainly! Some of the tools Pyrfecter uses have online playgrounds where you can see how the tool will affect your code in isolation.

If you're looking only to format your code with Black, you can use Black's playground: https://black.vercel.app/

Screenshot of Black's playground
Screenshot of Black's playground

If you just want to sort your imports, you can use isort's live editor at https://pycqa.github.io/isort/docs/quick_start/0.-try.html.

Screenshot of isort's playground
Screenshot of isort's playground

For regular Python development, it's a good practice to configure your code editor to lint your code as you type for format/fix your code when you commit it (or even when you save it). pre-commit is an excellent tool to run Python formatters, linters, and fixers right after you do a git commit but before you write your commit message. pre-commit hooks are available for a number of the code quality tools Pyrfecter uses (listed below).

Code quality tools

Here's a list of code quality tools used by Pyrfecter, along with a link to their homepage and, if they have one, an example of how to use their tool as a pre-commit hook.

ToolLinks
Black
"The uncompromising Python code formatter"
Docs

pre-commit
Pyflakes
"A simple program which checks Python source files for errors"
GitHub
isort
"[A] Python utility / library to sort imports alphabetically, [...] separated into sections and by type"
Docs

pre-commit
pybetter
A "[t]ool for fixing trivial problems with your code."
GitHub

pre-commit
auto-walrus
"A tool and pre-commit hook to automatically apply the awesome walrus operator."
GitHub

pre-commit
flynt
"A tool to automatically convert old string literal formatting to f-strings"
GitHub

pre-commit
McCabe
A "McCabe complexity checker for Python"
GitHub
ssort
"The python source code sorter."
GitHub

pre-commit