Package: ls-imports
Installation & Usage$pipinstallls-imports
$python-mls_imports...Or use the CLI throughpipx:$ pipx run ls-imports --help
Usage: ls-imports [OPTIONS] [PATHS]...

  Search Python source file(s) in PATHS for imported modules.

  Directories specified by PATHS are searched recursively for *.py files.

Options:
  -i, --ignore MODULE             Ignore a module and all its submodules. This
                                  option may be given multiple times.
  -R, --ignore-relative / --no-ignore-relative
                                  Ignore relative imports.
  -S, --ignore-stdlib / --no-ignore-stdlib
                                  Ignore standard library modules.
  -f, --show-files / --no-show-files
                                  For each import, list the files that import
                                  it.
  --version                       Show the version and exit.
  --help                          Show this message and exit.ExamplesLibrarySetup:>>>source="""...import ast...import click...from .base import pkgfunc......def lazy_import():...import math...return math.sin(20.0)...""">>>withopen('file.py','w')asf:...f.write(source)Parse imports from a file:>>>importls_imports>>>ls_imports.parse_file('file.py')['math', 'ast', 'click', '.base']Parse imports from a string:>>>ls_imports.parse_source(source)['math', 'ast', 'click', '.base']Command-line interfaceExclude standard library modules:$python-mls_imports--ignore-stdlibfile.py
clickExclude relative imports:$python-mls_imports--ignore-relativefile.py
ast
click
mathSearch a directory recursively:$python-mls_importsdir/Search a large package for all third-party imports, and show which files
import them:$gitclonehttps://github.com/denavit/libdenavit-py
$python-mls_imports-RSf--ignorelibdenavitlibdenavit-py/src
matplotlib.pyplotlibdenavit-py/src/libdenavit/OpenSees/get_fiber_data.pylibdenavit-py/src/libdenavit/OpenSees/plotting.pylibdenavit-py/src/libdenavit/OpenSees/uniaxial_material_analysis.pylibdenavit-py/src/libdenavit/camber.pylibdenavit-py/src/libdenavit/interaction_diagram_2d.pylibdenavit-py/src/libdenavit/non_sway_column_2d.pylibdenavit-py/src/libdenavit/section/RC.pylibdenavit-py/src/libdenavit/section/circle_shape.pylibdenavit-py/src/libdenavit/section/encased_composite.pylibdenavit-py/src/libdenavit/section/fiber_section.pylibdenavit-py/src/libdenavit/section/obround_shape.pylibdenavit-py/src/libdenavit/section/rectangle_shape.pylibdenavit-py/src/libdenavit/section/reinf.pylibdenavit-py/src/libdenavit/sway_column_2d.py
numpylibdenavit-py/src/libdenavit/OpenSees/fiber_section.pylibdenavit-py/src/libdenavit/camber.pylibdenavit-py/src/libdenavit/cross_section_2d.pylibdenavit-py/src/libdenavit/interaction_diagram_2d.pylibdenavit-py/src/libdenavit/joist.pylibdenavit-py/src/libdenavit/non_sway_column_2d.pylibdenavit-py/src/libdenavit/section/ACI_phi.pylibdenavit-py/src/libdenavit/section/ACI_strain_compatibility.pylibdenavit-py/src/libdenavit/section/RC.pylibdenavit-py/src/libdenavit/section/ccft.pylibdenavit-py/src/libdenavit/section/circle_shape.pylibdenavit-py/src/libdenavit/section/database/to_numpy.pylibdenavit-py/src/libdenavit/section/encased_composite.pylibdenavit-py/src/libdenavit/section/fiber_patches.pylibdenavit-py/src/libdenavit/section/fiber_section.pylibdenavit-py/src/libdenavit/section/obround_shape.pylibdenavit-py/src/libdenavit/section/rectangle_shape.pylibdenavit-py/src/libdenavit/section/reinf.pylibdenavit-py/src/libdenavit/sway_column_2d.py
openseespy.openseeslibdenavit-py/src/libdenavit/OpenSees/fiber_section.pylibdenavit-py/src/libdenavit/OpenSees/get_fiber_data.pylibdenavit-py/src/libdenavit/OpenSees/plotting.pylibdenavit-py/src/libdenavit/OpenSees/uniaxial_material_analysis.pylibdenavit-py/src/libdenavit/cross_section_2d.pylibdenavit-py/src/libdenavit/non_sway_column_2d.pylibdenavit-py/src/libdenavit/section/RC.pylibdenavit-py/src/libdenavit/section/encased_composite.pylibdenavit-py/src/libdenavit/sway_column_2d.py
pandaslibdenavit-py/src/libdenavit/section/database/to_numpy.pylibdenavit-py/src/libdenavit/section/fiber_section.py
pintlibdenavit-py/src/libdenavit/unit_convert.py
scipy.optimizelibdenavit-py/src/libdenavit/effective_length_factor.pylibdenavit-py/src/libdenavit/non_sway_column_2d.pylibdenavit-py/src/libdenavit/sway_column_2d.py
shapely.geometrylibdenavit-py/src/libdenavit/interaction_diagram_2d.pyPrior workBased onlist-imports.findimportsis similar, but shows
the reverse relation (for each file, shows the modules/names it imports).