Welcome to PySachi’s documentation!

Introduction

PySachi is a Python static code analysis tool to check your code against the Entropy coding standard, measuring entropy and displaying warnings.

Installation

You can install, upgrade, uninstall pysachi with these commands:

$ pip install pysachi
$ pip install --upgrade pysachi
$ pip uninstall pysachi

PySachi API

pysachi Module

pysachi.run(source, *, checkers=None, renderer=None)[source]

Run static code analysis on a source code.

This is a shortcut for:

report = pysachi.analyze(source)
result = pysachi.render(report)
Parameters:
  • source (str) – Source code to analyze.
  • checkers (Optional[List[Any]]) – List of checkers to run on source code.
  • renderer (Optional[str]) – Name of renderer to use.
Return type:

str

Returns:

Rendered report.

pysachi.analyze(source, *, checkers=None)[source]

Run static code analysis on a source code.

Example for a file:

with open("/some/path/file.py", "r") as f:
    report = pysachi.analyze(f.read())

Example for a module:

import inspect

report = pysachi.analyze(inspect.getsource(target))
Parameters:
  • source (str) – Source code to analyze.
  • checkers (Optional[List[Any]]) – List of checks to run on source code.
Return type:

ASTReport

Returns:

Analysis report.

pysachi.render(report, *, renderer=None)[source]

Render an report.ASTReport to str.

To use the default renderer raw:

result = pysachi.render(report)

To use a specific renderer:

result = pysachi.render(report, renderer="html")

Specified renderer will be loaded using pkg_resources and must have been registered as a pysachi.renderers entry point via setuptools for it to work. Fallback to raw renderer if the specified renderer can’t be found.

Parameters:
  • report (ASTReport) – Analysis report.
  • renderer (Optional[str]) – Name of renderer registered as entry point for pysachi.renderers.
Return type:

str

Returns:

Rendered analysis report.

pysachi.walk(tree, *, checkers=None)[source]

Run static code analysis over an ast.AST node.

Walking the tree is done by analyzer.DefaultAnalyzer which run checkers on important nodes.

Parameters:
  • tree (AST) – The root node to analyze.
  • checkers (Optional[List[Any]]) – List of checks to run on nodes.
Return type:

ASTReport

Returns:

A complete report of analysis.

Indices and tables