Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

pytree

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pytree

Print python project tree structure with classes and methods

latest
Source
npmnpm
Version
1.3.0
Version published
Maintainers
1
Created
Source

pytree

NPM version npm-typescript License

About

Pytree is a Node.js package that prints a tree of a Python project's directory structure with classes and methods. It provides an API that allows you to extract the classes and methods from your Python files, and then prints or saves a tree structure of your project's directory with those extracted classes and methods.

Example

import { runParse } from 'pytree';

// Print the tree structure of the current directory
const structure = runParse();

console.log(structure)
// [{ level: 0, type: 'file', name: 'file1.py' },
// { level: 1, type: 'class', name: 'MyClass' },
// { level: 2, type: 'method', name: 'my_method' },
// { level: 2, type: 'method', name: 'method_and_child' }]

// Print the tree structure of the directory 'src'
runParse(['src']);

// Print the tree structure of the directories 'src' and 'tests',
// excluding any files or directories that match the regular expression /__pycache__/
runParse(['src', 'tests'], null, [/__pycache__/]);

└─> file1.py
  └─> MyClass
    └─> my_method
  └─> MyOtherClass
    └─> my_other_method

Installation

npm install pytree

or

yarn add pytree

Usage

The runParse() function is the main entry point for the package. It takes the following arguments:

  • dirs (optional, default=['.']): an array of directories/files to search for Python files.
  • outputFile (optional): a file path to save the output to. If this argument is not provided, the output is printed to the console.
  • except (optional, default=[]): an array of regular expressions to exclude files or directories.

Usage (global module)

npx pytree

npx pytree --dir /path/to/directory1 /path/to/file /path/to/directory2

npx pytree --except "__init__.py" "test_*"

npx pytree --dest /path/to/output.txt

API

  • getClassAndMethodIndices(file: string) => { classes: ClassInfo[]; methods: MethodInfo[]; content: string}
  • walkTree(currentPath: string, level: number, output: OutputEntry[], except: RegExpExecArray[]) => void
  • printOutput(output: OutputEntry[]) => void
  • saveOutput(output: OutputEntry[], filePath: string) => void
  • isPythonFile(filename: string) => boolean
  • runParse(dirs = [], except = []) => output: OutputEntry[]
  • run(dirs = [], outputFile = null, except = []) - used for CLI command, prints result

Keywords

pytree

FAQs

Package last updated on 28 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts