PyCharm 2020.2 Help

Format files from the command line

Apply code style formatting to specified files from the command line. To be able to format files, install and enable plugins with support for the corresponding file types in PyCharm (for example, the Shell Script plugin to format shell script files).

You can find the script for running PyCharm in the installation directory under bin. To use this script as the command-line launcher, add it to your system PATH as described in Command-line interface.

Syntax
pycharm.bat format [<options>] <path ...>
Examples

Format two specific files from the C:\Data\src directory using the default code style settings:

pycharm.bat format C:\Data\src\hello.html C:\Data\src\world.html

Recursively format all files in the C:\Data\src directory including all subdirectories using the default code style settings:

pycharm.bat format -r C:\Data\src

Non-recursively format all the .xml and .html files in the C:\Data\src directory using code style settings from C:\Data\settings.xml:

pycharm.bat format -s C:\Data\settings.xml -m *.xml,*.html C:\Data\src

By default, PyCharm does not provide a command-line launcher. For information about creating a launcher script for PyCharm, see Command-line interface.

Syntax
pycharm format [<options>] <path ...>
Examples

Format two specific files from the ~/Data/src directory using the default code style settings:

pycharm format ~/Data/src/hello.html ~/Data/src/world.html

Recursively format all files in the ~/Data/src directory including all subdirectories using the default code style settings:

pycharm format -r ~/Data/src

Non-recursively format all the .xml and .html files in the ~/Data/src directory using code style settings from ~/Data/settings.xml:

pycharm format -s ~/Data/settings.xml -m *.xml,*.html ~/Data/src

You can find the script for running PyCharm in the installation directory under bin. To use this script as the command-line launcher, add it to your system PATH as described in Command-line interface.

Syntax
pycharm.sh format [<options>] <path ...>
Examples

Format two specific files from the ~/Data/src directory using the default code style settings:

pycharm.sh format ~/Data/src/hello.html ~/Data/src/world.html

Recursively format all files in the ~/Data/src directory including all subdirectories using the default code style settings:

pycharm.sh format -r ~/Data/src

Non-recursively format all the .xml and .html files in the ~/Data/src directory using code style settings from ~/Data/settings.xml:

pycharm.sh format -s ~/Data/settings.xml -m *.xml,*.html ~/Data/src

Options

OptionDescription
-hShow the help message and quit.
-m|-mask Specify a comma-separated list of file masks that define the files to be processed. You can use the * (any string) and ? (any single character) wildcards.
-r|-R Process specified directories recursively.
-s|-settings

Specify the code style settings file to use for formatting. This can be one of the following:

  • A file with the exported code style settings: in the Settings/Preferences dialog Ctrl+Alt+S , open the Editor | Code Style page, click The Show Scheme Actions button, and select Export.

  • The .idea/codeStyleSettings.xml file stored in your project directory (for PyCharm version 2017.2 and earlier).

  • The .idea/codeStyles/Project.xml file stored in your project directory (for PyCharm version 2017.3 and later).

If this option is not specified, the default code style settings will be used.

Last modified: 08 May 2020