PEP 8 (legacy package)

1.7.1 · maintenance · verified Sat Apr 11

The `pep8` package, version 1.7.1, is a Python style guide checker that verifies code against some of the conventions in PEP 8. This package has been renamed to `pycodestyle` to reduce confusion between the tool and the actual PEP 8 style guide document. While still installable, users are strongly encouraged to use `pycodestyle` instead. The package is in maintenance mode under its old name, with active development continuing as `pycodestyle`.

Warnings

Install

Imports

Quickstart

The `pep8` package is primarily used via its command-line interface. For programmatic checks, you can import `Checker` and instantiate it with a file path. The `check_all()` method runs checks and prints errors directly to stdout, returning the total count of errors found. For modern usage, consider the `pycodestyle` package.

import os

# Create a dummy Python file to check
with open('example.py', 'w') as f:
    f.write('def my_function(a,b):\n    return a+ b\n')

# Command-line usage (typical)
# import subprocess
# subprocess.run(['pep8', 'example.py'])

# Programmatic usage of the legacy pep8 package
from pep8 import Checker

# You can pass a filename or a file-like object
checker = Checker('example.py')
errors = checker.check_all()

print(f"Found {errors} style errors.")
if errors > 0:
    print("Note: The pep8 package prints errors directly to stdout during check_all().")

# Cleanup (optional)
os.remove('example.py')

view raw JSON →