Skip to main content
Build status

pyformat formats Python code to follow a consistent style.

Features

  • Formats code to follow the PEP 8 style guide (using autopep8).

  • Removes unused imports (using autoflake).

  • Formats docstrings to follow PEP 257 (using docformatter).

  • Makes strings all use the same type of quote where possible (using unify).

Installation

From pip:

$ pip install --upgrade pyformat

Example

After running:

$ pyformat --in-place example.py

This code:

def launch_rocket   ():



    """Launch
the
rocket. Go colonize space."""

def factorial(x):
    '''

    Return x factorial.

    This uses math.factorial.

    '''
    import math
    import re
    import os
    return math.factorial( x );
def print_factorial(x):
    """Print x factorial"""
    print( factorial(x)  )
def main():
    """Main
    function"""
    print_factorial(5)
    if factorial(10):
      launch_rocket()

Gets formatted into this:

def launch_rocket():
    """Launch the rocket.

    Go colonize space.

    """


def factorial(x):
    """Return x factorial.

    This uses math.factorial.

    """
    import math
    return math.factorial(x)


def print_factorial(x):
    """Print x factorial."""
    print(factorial(x))


def main():
    """Main function."""
    print_factorial(5)
    if factorial(10):
        launch_rocket()

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyformat-1.0.tar.gz (7.4 kB view details)

Uploaded Source

File details

Details for the file pyformat-1.0.tar.gz.

File metadata

  • Download URL: pyformat-1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.9

File hashes

Hashes for pyformat-1.0.tar.gz
Algorithm Hash digest
SHA256 16376cbc7afb19d9cc3be024e2f3543dcec4d569716e8350c271dd04a1bbe393
MD5 865809fb1bd1d670934e75fb0e417944
BLAKE2b-256 f18ce2e9b9f316839db401fd4efdd6199b98ba652636da6d982f9c0fb3dc1e9e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0 This release

1 file

0.7

1 file

0.6

1 file

0.5.7

1 file

0.5.6

1 file

0.5.5

1 file

0.5.4

1 file

0.5.3

1 file

0.5.2

1 file

0.5.1

1 file

0.5

1 file

0.4

1 file

0.3.4

1 file

0.3.3

1 file

0.3.2

1 file

0.3.1

1 file

0.3

1 file

0.2.4

1 file

0.2.3

1 file

0.2.2

1 file

0.2.1

1 file

0.2

1 file

0.1.1

1 file

0.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page