{"id":923,"library":"pkgutil-resolve-name","title":"pkgutil-resolve-name","description":"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.","status":"active","version":"1.3.10","language":"python","source_language":"en","source_url":"https://github.com/graingert/pkgutil-resolve-name","tags":["pkgutil","import","dynamic-import","backport","reflection"],"install":[{"cmd":"pip install pkgutil-resolve-name","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required runtime environment","package":"python","optional":false}],"imports":[{"symbol":"resolve_name","correct":"from pkgutil_resolve_name import resolve_name"}],"quickstart":{"code":"from pkgutil_resolve_name import resolve_name\n\n# Resolve a class from a standard library module\nPath = resolve_name('pathlib:Path')\nprint(f\"Resolved object: {Path}\")\nprint(f\"Is it the pathlib.Path class? {Path.__name__ == 'Path' and Path.__module__ == 'pathlib'}\")\n\n# Resolve a function\nsys_exit = resolve_name('sys:exit')\nprint(f\"Resolved object: {sys_exit}\")\nprint(f\"Is it the sys.exit function? {sys_exit.__name__ == 'exit' and sys_exit.__module__ == 'sys'}\")\n\n# Resolve a module directly\ncollections_module = resolve_name('collections')\nprint(f\"Resolved object: {collections_module}\")\nprint(f\"Is it the collections module? {collections_module.__name__ == 'collections'}\")","lang":"python","description":"Demonstrates resolving a class, a function, and a module by their string names using `resolve_name`."},"warnings":[{"fix":"For Python 3.9+, use `from pkgutil import resolve_name` directly. For older Python versions, continue using this backport.","message":"This 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.","severity":"gotcha","affected_versions":"< 3.9"},{"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.","message":"The `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.","severity":"breaking","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T21:19:58.414Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"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')`.","cause":"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'.","error":"ValueError: invalid format: 'module-with-dash.ClassName'"},{"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.","cause":"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.","error":"AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?"},{"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.","cause":"`pkgutil.resolve_name` successfully imported the specified module, but could not find the named object (e.g., class, function, or variable) within that module.","error":"AttributeError: module 'my_module' has no attribute 'NonExistentClass'"},{"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`.","cause":"`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.","error":"ModuleNotFoundError: No module named 'non_existent_module'"}],"ecosystem":"pypi","meta_description":null,"install_score":80,"install_tag":"verified","quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.3.10","cli_name":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"17.8M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"17.8M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0,"mem_mb":0.1,"disk_size":"18M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"19.6M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"19.6M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0,"mem_mb":0.1,"disk_size":"20M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"11.5M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"11.5M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.4,"import_time_s":0,"mem_mb":0.1,"disk_size":"12M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"11.2M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"11.1M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.4,"import_time_s":0,"mem_mb":0,"disk_size":"12M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"17.3M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"17.3M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.7,"import_time_s":0,"mem_mb":0.1,"disk_size":"18M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0.1,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":null,"tag_description":null,"results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}