modwrap is a pure Python 3 utility (no external dependencies) that lets you dynamically load and execute functions from any Python module. 🐍
📦 Installation
Install directly from PyPI:
pip install modwrap
Could be add to your project using poetry:
poetry add modwrap
🔧 Programmatic Usage
Use modwrap in your Python code to load modules, introspect callable signatures, and execute functions dynamically:
Basic Usage
from modwrap import ModuleWrapper
wrapper = ModuleWrapper("./examples/shell.py")
# Load and call a function
func = wrapper.get_callable("execute")
result = func(command="whoami")
print(result)
# Access the raw module object
mod = wrapper.module
print(mod.execute("whoami"))
Signature Validation
Validate function signatures with type checking:
# Validate with type hints
wrapper.validate_signature("execute", {"command": str, "timeout": float})
# Or use the non-raising version
if wrapper.has_signature("execute", {"command": str}):
func = wrapper.get_callable("execute")
result = func(command="ls")
Validate only argument names (no type checking):
# Validate argument names only
wrapper.validate_args("execute", ["command", "timeout"])
# Or use the non-raising version
if wrapper.has_args("execute", ["command", "timeout"]):
func = wrapper.get_callable("execute")
result = func(command="ls", timeout=30)
Dependency Analysis
Check what packages need to be installed:
deps = wrapper.get_dependencies()
print("Standard library:", deps['stdlib'])
print("Third-party packages:", deps['third_party'])
print("Local imports:", deps['local'])
# Check for missing dependencies
if deps['missing']:
print(f"Install missing packages: pip install {' '.join(deps['missing'])}")
Introspection
# Get function signature details
sig = wrapper.get_signature("execute")
print(sig) # {'command': {'type': 'str', 'default': None}, ...}
# Get docstrings
doc = wrapper.get_doc("execute") # Full docstring
summary = wrapper.get_doc_summary("execute") # First line only
# Check if callable exists
if wrapper.has_callable("execute"):
print("Function exists!")
# Get classes from module
cls = wrapper.get_class("MyClass") # Get specific class
cls = wrapper.get_class(must_inherit=BaseClass) # Get class by inheritance
Working with Classes
# Load and call class methods
wrapper.get_callable("MyClass.method_name")
# Get a class and instantiate it
MyClass = wrapper.get_class("MyClass")
instance = MyClass()
Utility Functions
Discover all modules in a directory:
from modwrap import list_modules, iter_modules
# Get all modules as a list
modules = list_modules("./my_modules")
for wrapper in modules:
print(wrapper.name)
# Or iterate lazily (memory efficient)
for wrapper in iter_modules("./my_modules"):
if wrapper.has_callable("main"):
wrapper.get_callable("main")()
Metadata
Release files for modwrap 1.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| modwrap-1.1.7.tar.gz | 5.8 kB | Without provenance | Details for modwrap-1.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| modwrap-1.1.7-py3-none-any.whl | Python 3 | none | any | Details for modwrap-1.1.7-py3-none-any.whl |
Total release size: 12.7 kB
Release files / modwrap-1.1.7.tar.gz
| Download URL | modwrap-1.1.7.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd020e5a0d3fa7f9101740793929b6ec8d86cf0987fb10e1b70772599d273812
|
|
BLAKE2b-256 checksum How to use checksums |
05adb0a4eeca2c0eedd57861928e43a18f459b987f4d92445038aa531e42f487
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.9 Linux/6.16.8+kali-amd64
|
Release files / modwrap-1.1.7-py3-none-any.whl
| Download URL | modwrap-1.1.7-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f32bb074607c322c0f2514a0b51843788b9cd6617cfcf8ddfa5ac4c48407ca7
|
|
BLAKE2b-256 checksum How to use checksums |
963adb4553e74aa05967822cb8e0c917f28ececbdcfb95d8a1a3d5769a745a67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.9 Linux/6.16.8+kali-amd64
|
Security for modwrap 1.1.7
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.