Registry / serialization / pkgutil-resolve-name

pkgutil-resolve-name

JSON →
library1.3.10pypypi✓ verified 24d ago

pkgutil-resolve-name is a Python library that provides a backport of the `pkgutil.resolve_name` function, originally introduced in Python 3.9. It allows resolving a string-based name (e.g., 'module.submodule:ClassName' or 'module.function_name') to its corresponding Python object. The current version is 1.3.10, with an infrequent release cadence as it primarily backports a standard library feature.

pip install pkgutil-resolve-name
INSTALL
IMPORT
SIG · PKGUTIL-RESOLVE-NA
P
pkgutil-resolve-name
serializationpythonv1.3.10
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.10 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

resolve_name
from pkgutil_resolve_name import resolve_name

Demonstrates resolving a class, a function, and a module by their string names using `resolve_name`.

from pkgutil_resolve_name import resolve_name # Resolve a class from a standard library module Path = resolve_name('pathlib:Path') print(f"Resolved object: {Path}") print(f"Is it the pathlib.Path class? {Path.__name__ == 'Path' and Path.__module__ == 'pathlib'}") # Resolve a function sys_exit = resolve_name('sys:exit') print(f"Resolved object: {sys_exit}") print(f"Is it the sys.exit function? {sys_exit.__name__ == 'exit' and sys_exit.__module__ == 'sys'}") # Resolve a module directly collections_module = resolve_name('collections') print(f"Resolved object: {collections_module}") print(f"Is it the collections module? {collections_module.__name__ == 'collections'}")
Debug
Known issues
gotchaThis library is a backport of `pkgutil.resolve_name` from Python 3.9. If your project targets Python 3.9 or newer, you can directly use `pkgutil.resolve_name` from the standard library without needing this external package.
fix
For Python 3.9+, use `from pkgutil import resolve_name` directly. For older Python versions, continue using this backport.
affects: < 3.9
breakingThe `resolve_name` function (both this backport and the standard library version) allows resolving arbitrary Python objects by string. This can be a security footgun, especially in contexts involving untrusted input or deserialization (e.g., `pickle`). An attacker could potentially use this to load and execute dangerous functions or modules, bypassing blocklists.
fix
Avoid using `resolve_name` with untrusted input strings. Implement robust validation or an allow-list for acceptable object paths if dynamic resolution is absolutely necessary in security-sensitive applications. Consider alternative approaches that do not rely on dynamic string-to-object resolution for critical operations.
affects: All versions
Errors
Common errors & fixes
ValueError: invalid format: 'module-with-dash.ClassName'
The string passed to `pkgutil.resolve_name` contains characters (like a hyphen '-') that are not valid in Python identifiers, violating the expected format of 'module.submodule:ClassName' or 'module.function_name'.
fix
Ensure the module and object names adhere to valid Python identifier naming conventions, using underscores instead of hyphens where appropriate. For example, `pkgutil.resolve_name('module_with_underscore.ClassName')`.
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
This error typically occurs in Python 3.12 and later when older versions of tools like `pip` or `setuptools` (or packages that rely on them) attempt to use the `pkgutil.ImpImporter` class, which was removed from the standard library in Python 3.12.
fix
Upgrade `pip` and `setuptools` to their latest versions within your environment (e.g., `python -m pip install --upgrade pip setuptools`). If the issue persists, ensure all other dependencies are updated, or consider using a Python version older than 3.12 if a specific legacy package cannot be updated.
AttributeError: module 'my_module' has no attribute 'NonExistentClass'
`pkgutil.resolve_name` successfully imported the specified module, but could not find the named object (e.g., class, function, or variable) within that module.
fix
Verify that the object path provided to `pkgutil.resolve_name` exactly matches an existing object within the specified module. Double-check for typos or incorrect casing.
ModuleNotFoundError: No module named 'non_existent_module'
`pkgutil.resolve_name` was unable to locate or import the module specified in the input string, meaning the module does not exist or is not in the Python path.
fix
Ensure the module name is spelled correctly and that the module is installed and accessible within the current Python environment (e.g., listed in `sys.path`). If it's a third-party package, install it using `pip install non_existent_module`.
Upgrade
Version history
1.3.10latest on PyPI · released Jul 21, 2021
Audit
Dependencies
pythonrequiredRequired runtime environment
Agent activity
5 hits · last 30 days
node
4
Resources
pkgutil-resolve-name — pip install pkgutil-resolve-name · libregistry