Software & Apps

How to View the Dependency Graph of your Python Project – Gauge

Understanding your project’s dependency graph is important for several reasons:

  • Education ->Visualization helps new developers quickly understand how things can be structured and where new equipment goes.
  • Refactoring → Understanding how a module is used and what its dependencies are creates a clear path to modifying or removing it.
  • Code Quality → It is easy to identify circular module-level dependencies, bad design decisions, and weak points, such as tightly coupled modules.

With Tachyou can easily imagine the set of dependencies that exist within your Python project. Here’s how:

1. Install Tach

> pip install tach

The first step is straightforward – installation Tach and make sure you are on the latest version.

2. Define module boundaries

> tach mod

Next, we need to define the modules within your project that we want to see dependencies between. the tach mod The command opens an editor where you can mark modules and your Python source. Here are the commands you need:

  • up/down/left/right arrow: navigate
  • enter: mark the directory or file as a module
  • Ctrl + a: Mark all files or directories in the current level as modules
  • s: mark directory as Python source
  • Ctrl + s: save

We will use the FastAPI repo as an example. Here’s how it looks for FastAPI before saving:

3. Sync your dependencies with Tach

To properly visualize your existing dependencies, Tach will crawling the Python AST to know which modules import from each other. This is achieved by running:

> tach sync

Here’s a snippet of what Tach found for the above configuration:

4. View your dependencies using Tach

The last step is the simplest. Just run tach show --weband click the generated URL to see your dependency graph! You can also view a localized version of the graph through GraphViz using the base command tach show .

.

Here is the link for FastAPI!

You can also click/drag modules and edges to better understand the relationships in your codebase:

By following the steps above, you can easily visualize your project’s set of Python dependencies, and inform future architectural decisions.

Tach lets you too enforcement of boundaries between modules, as well as defining rigid interfaces for a given module. If there’s a feature you’d like to see on Tach, don’t hesitate drop an issue or join the discussion on Discord!

.

2025-01-21 19:49:00

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button