Skip to main content

A tool for exploring complex inheritance patters in python code

Project description Testing Status Documentation Status Current Coverage

The inheritance_explorer is an open source python package for inspecting other packages. In particular, it focuses on class inheritance structures, allowing you to produce graphs that recursively map out child classes from a given starting class. There are a number of useful applications: from learning structures of unfamiliar code bases to identifying duplicate code.

Useful links: github repository, full documentation


To install the latest release into your current active environment:

$ pip install inheritance_explorer

If you want to produce static images of any graphs, you’ll also need to install graphviz following the instructions at graphviz is not needed for the interactive plotting and similarity calculations (see Quick Start below).

Quick Start

Basic class mapping

The primary function of the inheritance_explorer is to trace out the class inheritance starting from a single parent class and recursively traversing all child classes. To get started, initialize a ClassGraphTree with the starting class:

from matplotlib.axes import Axes
from inheritance_explorer import ClassGraphTree

base_class = Axes # the starting class to map from
cgt = ClassGraphTree(base_class) # traces an inheritance tree

From here, there are a number of ways to visualize the inheritance graph.

From a jupyter notebook, you can construct a pyvis interactive network graph


graph = cgt.build_interactive_graph(width="1200px",
                                    font_color='white')'_tmp.html') # render the pyvis interactive graph
If you have graphviz installed, you can also render a static graph either to

display in a jupyter notebook or save to file. To display in a notebook:


To save a file, you can access the underlying graph object directly:


Function tracking

The ClassGraphTree can also track a selected function of a class during traversal. When a child class overrides the function, the source code is stored. To use this functionality, use the funcname keyword argument to provide the function name as a string:

from matplotlib.axes import Axes
from inheritance_explorer import ClassGraphTree

base_class = Axes # the starting class to map from
cgt = ClassGraphTree(base_class, funcname='clear')

By default, after the traversal completes, the different versions of the function that is tracked will be run through a code-similarity calculation. Cases where the similarity fraction is above a cutoff value (default of .75), the two nodes will be connected on the resulting graph:

Additionally, you can inspect the source code itself for any of the classes that define it using cgt.get_source_code(class_name). If in a jupyter notebook, you can view it with syntax highlighting with

from IPython.display import Code
Code(cgt.get_source_code('PolarAxes'), language="python")

For a complete description of the code similarity calculation and how to modify it, check out the full documentation.

Command line usage

inheritance_explorer provides some command line functionality, check the full documentation for details.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inheritance_explorer-0.1.3.tar.gz (13.2 MB view hashes)

Uploaded Source

Built Distribution

inheritance_explorer-0.1.3-py3-none-any.whl (18.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page