Format Python code using the yapf formatter in Emacs
Emacs Lisp
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information. Add README. May 6, 2015
python-yapf.el Add package's prefix to some functions May 28, 2017


Format Python code according to the pep8 or google style using the yapf formatter in Emacs.


First, install Python yapf package with pip:

pip install -U yapf

Then, copy python-yapf.el to your load-path and add to your ~/.emacs:

(require 'python-yapf)


Three commands are supplied to format python code:

  • python-yapf-region: Format the code of the region or the buffer if no region selected.
  • python-yapf-file: Format a file(by default the one opened in current buffer).
  • python-yapf-directory: Search and format .py files in a directory.

Run them interactively:

M-x python-yapf-* RET

Or set any key bindings you like.


Currently, YAPF is in alpha stage(buggy) and may change often in the released version, many features are required to enhance the code formatting. When you format code files, please remember to make backups.


Bugfix or suggestions/improvements welcome!