Skip to main content

Py Module Info

Testing Upload Python Package

Get extra info about a python module, like imports, functions called inside other funcs etc.


Installation

pip install py-module-info

Why use this?

Well Idk, the inspect module in python requires you to import the module. This package does not require you to import, but rather just looks at the python file like a normal text file and parses it. The problem with importing is that it may execute code that can harm your PC. So maybe ?

What does it do?

Get info about the imports used

# test.py

import json
import pprint as p
from typing import List as l
from json import load, dump as d
from py_module_info.main import ModuleInfo

To get the imported names use

from py_module_info import ModuleInfo
m = ModuleInfo("test.py")
imports = m.get_imports()
print(imports.get_imported_names())

# output
['json', 'pprint', 'List', 'load', 'dump', 'ModuleInfo']

# in order to get the alias names used
print(imports.get_imported_names(use_alias=True))
# output
['json', 'p', 'l', 'load', 'd', 'ModuleInfo']

To get the literal import string in the module use

from py_module_info import ModuleInfo
m = ModuleInfo("test.py")
imports = m.get_imports()
print(imports.get_import_strings())

# output
['import json', 'import pprint', 'from typing import List',
'from json import load', 'from json import dump', 'from py_module_info.main import ModuleInfo']

# use alias names insted
print(imports.get_import_strings(use_alias=True))

# output
['import json', 'import pprint as p', 'from typing import List as l',
'from json import load', 'from json import dump as d', 'from py_module_info.main import ModuleInfo']

Note

  • The imports will be split into individual imports:
 import test, json
  • will become
import test
import json

Get info about the function in the module.

# test.py

import json
from pprint import pprint

def foo():
    pprint({"Hello": "World"})


    with open("test.json") as f:
        print(json.load(f))

To get info about the functions use

from py_module_info import ModuleInfo

m = ModuleInfo("test.py")
print(m.get_funcs_info())

# output
{'foo': {'args': [], 'defaults': [], 'arg_count': 0, 'calls': ['json.load(f)', 'open("test.json")', 'pprint({"Hello": "World"})', 'print(json.load(f))']}}

The output includes the args passed in function, the defaults value for the the arguments, the argument count, and all the function calls that happened inside the function.

The function calls are all expanded and includes the entire call string.

In order to get just the function calls use

from py_module_info import ModuleInfo

m = ModuleInfo("test.py")
print(m.get_funcs_info(only_func_name=True))

# output
{'foo': {'args': [], 'defaults': [], 'arg_count': 0, 'calls': ['load', 'open', 'pprint', 'print']}}

Get info about the classes in a module

# test.py
class Foo(A.Test):

    def __init__(self, name):
        self.name = name

    def n():
        pass


class Bar():

    def a():
        print('Hello')

To get meta info about the classes in the module use

from py_module_info import ModuleInfo

m = ModuleInfo("test.py")
print(m.get_classes_info())

# output
{'Foo': {'bases': ['A.Test'], 'methods': {'__init__': {'args': ['self', 'name'], 'defaults': [], 'arg_count': 2, 'calls': []}, 'n': {'args': [], 'defaults': [], 'arg_count': 0, 
'calls': []}}}, 'Bar': {'bases': [], 'methods': {'a': {'args': [], 'defaults': [], 'arg_count': 0, 'calls': ["print('Hello')"]}}}}

Currently the output includes the information about the base classes and the info about different methods in the class.

Metadata

Release files for py-module-info 0.1.0

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

Source distribution (sdist)

Source distribution for py-module-info 0.1.0
File Size Uploaded Provenance
py-module-info-0.1.0.tar.gz 6.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for py-module-info 0.1.0
File Interpreter ABI Platform
py_module_info-0.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 14.4 kB

Release files / py-module-info-0.1.0.tar.gz

Download URL py-module-info-0.1.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
177f57fbafad8201fba29aab722811421fd919ed19d862238df09d507fa1d27b
BLAKE2b-256 checksum
How to use checksums
eae29b126e61a4aba8da8ffedb886f189788984dac58502f70bbb22b0402be2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

Release files / py_module_info-0.1.0-py2.py3-none-any.whl

Download URL py_module_info-0.1.0-py2.py3-none-any.whl
Size 8.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4ab9dc9fa49e46c99a1d7c306347cd49fa9502d3ed83efbf67cc691c4a50b19d
BLAKE2b-256 checksum
How to use checksums
606538ee4aede64db28ee243641b136ee4b4baa276aae2fa3b5ac046da509d2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

Security for py-module-info 0.1.0

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.

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