Pylama

8.4.1 · active · verified Thu Apr 16

Pylama is a comprehensive code audit tool for Python. It acts as a wrapper, integrating various popular linters and checkers such as pycodestyle, pydocstyle, PyFlakes, Mccabe, Pylint, Radon, Mypy, and Vulture, to provide a unified interface for checking code quality. The current version is 8.4.1, and it receives updates periodically to support newer Python versions and linter functionalities.

Common errors

Warnings

Install

Imports

Quickstart

The primary way to use Pylama is via the command line, running `pylama` in your project's root or specifying files/directories. For programmatic use, you can import `check_path` and `parse_options` from `pylama.main` to analyze files and retrieve issues directly within Python code. This example demonstrates creating a temporary file with known issues, running `pylama` on it, and printing the reported errors.

import os
import textwrap
from pylama.main import check_path, parse_options

# Create a dummy Python file to check
file_content = textwrap.dedent('''
    import os, sys

    def my_function():
        x=10 # E225 missing whitespace around operator
        if x > 5:
            print("Hello")
        return "world"

    my_function() # W0612 unused variable 'x'
''')

file_path = "./temp_pylama_test.py"
with open(file_path, "w") as f:
    f.write(file_content)

# Run pylama programmatically
# Options can be passed as a dictionary
options_dict = {
    'linters': ['pycodestyle', 'pyflakes'], # Specify linters to use
    'ignore': ['W0611'], # Ignore specific warnings, e.g., unused imports
    'select': []
}

# parse_options processes paths and dictionary options into an options object
options = parse_options([file_path], **options_dict)
errors = check_path(options)

if errors:
    print(f"Found {len(errors)} issues in {file_path}:")
    for error in errors:
        print(f"  {error.filename}:{error.lnum}:{error.col} [{error.type}] {error.text} [{error.linter}]")
else:
    print(f"No issues found in {file_path}.")

# Clean up the dummy file
os.remove(file_path)

view raw JSON →