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()

Metadata

Release files for pyformat 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyformat 1.0
File Size Uploaded Provenance
pyformat-1.0.tar.gz 7.4 kB Without provenance Details

Release files / pyformat-1.0.tar.gz

Download URL pyformat-1.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
16376cbc7afb19d9cc3be024e2f3543dcec4d569716e8350c271dd04a1bbe393
BLAKE2b-256 checksum
How to use checksums
f18ce2e9b9f316839db401fd4efdd6199b98ba652636da6d982f9c0fb3dc1e9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.9

Security for pyformat 1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page