Skip to main content

Formats Python code to follow a consistent style.

Project description

Build status Test coverage 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()

Project details


Download files

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

Source Distribution

pyformat-0.5.4.tar.gz (6.3 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: pyformat-0.5.4.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyformat-0.5.4.tar.gz
Algorithm Hash digest
SHA256 90f49322f144953d1ee7454b8c3cd2421cb823b46ac5c6858b06351a2c5f9162
MD5 da219b026550eacc6f4ee42d54bb7c71
BLAKE2b-256 36eea29d45115a61c07564b800085f5566d5fa3f2f634ea200a4c30477942e46

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page