snakefood: Python Dependency Graphs



Generate dependency graphs from Python code. This dependency tracker package has a few distinguishing characteristics:

A problem with dependency trackers that run code is that they are unreliable, due to the dynamic nature of Python (the presence of imports within function calls and __import__ hooks makes it almost impossible to always do the right thing). This script aims at being right 99% of the time, and we think that given the trade-offs, 99% is good enough for 99% of the uses.

I fully intend that this program work on all codebases. It has been tested on a number of popular open source codes (see the test directory).

Tools Included

  1. sfood:

    Given a set of input files or root directories, generate a list of dependencies between the files;

  2. sfood-graph:

    Read a list of dependencies and produce a Graphviz dot file. (This file can be run through the Graphviz dot tool to produce a viewable/printable PDF file);

  3. sfood-cluster:

    Read a list of dependencies, a list of file clusters, and output a list of simplified (clustered) dependencies.

  4. sfood-checker:

    Analyze the source code with the AST and list unused or redundant imports.

  5. sfood-imports:

    Find and list import statements in Python files, regardless of whether they can be imported or not.

See full documentation for more details.




A Mercurial repository can be found at:


Martin Blais <>