Skip to main content

Dependency call extraction tool for Python modules

What does this package do?

This package can use to extract functions, import statements (TODO: class) in a module file, and their call dependencies in a source repository.

Example:

Consider a simple repository structure

simple_repo
  |
  |_ file1.py
  |_ folder1.py
        |_ file2.py     

The content in each file is

# file1.py
def print_function(str):
  print(str)

# folder1/file2.py
from file1 import print_function

def start_print():
  print_function("Author: Nam Le Hai")

def print_hello():
  print_function("hello")

The tool can use to find the dependency of print_hello() function in file2.py which is the print_function() function imported from file1.py.

Quickstart Guide

Currently, our package only supports extracting dependency for functions and import statements in a module files.

Requirement

Python >= 3.10

Install pydepcall

Using Anaconda (feel free to use other env)

conda create -n YOUR_ENV_NAME python=3.10
conda activate YOUR_ENV_NAME
pip install pydepcall

Usage:

from pydepcall import Extractor

If you want to extract all module files in the repository

reposrc = YOUR_LOCAL_PATH_OF_REPO
extractor = Extractor(reposrc)
output = extractor.extract()

If you want to extract a specific module file in the repository

reposrc = YOUR_LOCAL_PATH_OF_REPO
module_file = YOUR_LOCAL_PATH_OF_FILE_IN_REPO
extractor = Extractor(reposrc, module_file)
output = extractor.extract()

Example

>>> from pydepcall import Extractor
>>> reposrc = "simple_repo"
>>> extractor = Extractor(reposrc)
>>> output = extractor.extract()
>>> output
{'simple_repo/file1.py': <pydepcall.Node.ModuleNode object at 0x7faeb6d84580>, 'simple_repo/folder1/file2.py': <pydepcall.Node.ModuleNode object at 0x7faeb7822050>}

>>> output["simple_repo/folder1/file2.py"].function_list
[<pydepcall.Node.FunctionNode object at 0x7faeb6bc2740>, <pydepcall.Node.FunctionNode object at 0x7faeb6bc2530>]

>>> output["simple_repo/folder1/file2.py"].function_list[0].children
[<pydepcall.Node.ImportNode object at 0x7fc5fade6320>]

>>> output["simple_repo/folder1/file2.py"].function_list[0].children[0].children
[<pydepcall.Node.FunctionNode object at 0x7faeb6bc22c0>]

>>> output["simple_repo/folder1/file2.py"].function_list[0].children[0].children[0].content
'def print_function(str):\n  print(str)'

Output format

For extracting a specific module, the output will be a ModuleNode of the input file.

For extracting the whole repository, the output will be the dictionary of ModuleNode with the keys are all module files in the repository.

Node objects

The package has 5 main nodes:

  • ModuleNode: contains all FunctionNode and ImportNode in a module file
  • ImportNode: a node represents an import statement
  • FunctionNode: a node represents a python function
  • ClassNode: a node represents a class
  • BlockNode: a node represents a codeblock in the module file

Every node except ModuleNode has the following attributes:

  • path: the module file's local path contain that node
  • content: the text content of the node (function, import, class or codeblock)
  • position_in_file: the position of the node in the module file

For FunctionNode and ImportNode, we can acquire their dependencies through their children (node.children) attribute.

Please see Node.py for more details.

Metadata

Release files for pydepcall 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydepcall 0.0.2
File Size Uploaded Provenance Actions
pydepcall-0.0.2.tar.gz 13.6 kB Without provenance Details for pydepcall-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydepcall 0.0.2
File Interpreter ABI Platform Actions
pydepcall-0.0.2-py3-none-any.whl Python 3 none any Details for pydepcall-0.0.2-py3-none-any.whl

Total release size: 27.1 kB

Release files / pydepcall-0.0.2.tar.gz

Download URL pydepcall-0.0.2.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bf15db559c385d9d38925b9c343a4a5b58bf191b690735348d226c61fbab3e4a
BLAKE2b-256 checksum
How to use checksums
7e55bda8520df5d3b907c92817fd8d4f93ce4c3e2b75a6055b40e41c9fadb6ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.14

Release files / pydepcall-0.0.2-py3-none-any.whl

Download URL pydepcall-0.0.2-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d406c89912c381b5743eff968738f0db2135551b7c736edc251599d1a5ccc28e
BLAKE2b-256 checksum
How to use checksums
4b41addb3f28132da07144a32161f567839d8a6dabf5a2914a3da4c5efa7451e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.14

Security for pydepcall 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page