{"id":5196,"library":"dlinfo","title":"dlinfo","description":"dlinfo is a Python wrapper for libc's dlinfo (on Linux) and dyld_find (on macOS), providing a way to inspect dynamically loaded shared objects. The current version is 2.0.0. The project maintains an active development status with regular updates for Python compatibility and bug fixes, typically with releases tied to significant changes or Python version support.","status":"active","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/fphammerle/python-dlinfo","tags":["system-info","low-level","ffi","shared-libraries","ctypes","linux","macos"],"install":[{"cmd":"pip install dlinfo","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Requires Python 3.9 or higher for compatibility, as older versions (3.5-3.8) are no longer supported.","package":"python","optional":false}],"imports":[{"symbol":"DLInfo","correct":"from dlinfo import DLInfo"}],"quickstart":{"code":"import ctypes\nimport ctypes.util\nfrom dlinfo import DLInfo\n\n# Load the C standard library\n# This will typically find 'libc.so.6' on Linux or 'libc.dylib' on macOS\nlib_path = ctypes.util.find_library('c')\nif lib_path is None:\n    print(\"Could not find the C standard library. This example may not run on your system.\")\n    # Exit gracefully or raise an error depending on desired behavior\nelse:\n    lib = ctypes.cdll.LoadLibrary(lib_path)\n\n    # Create a DLInfo instance\n    dlinfo_instance = DLInfo(lib)\n\n    # Get the path of the loaded library\n    library_path = dlinfo_instance.path\n    print(f\"Path of 'c' library: {library_path}\")\n\n    # Example of getting SONAME (if available and applicable)\n    # On some systems, DLInfo.soname might return None if not explicitly set by the library\n    soname = dlinfo_instance.soname\n    if soname:\n        print(f\"SONAME of 'c' library: {soname}\")\n    else:\n        print(\"SONAME not explicitly available or not set for 'c' library.\")\n","lang":"python","description":"This quickstart demonstrates how to load the C standard library using `ctypes`, create a `DLInfo` object, and retrieve the library's absolute file path and SONAME (if available). This is the primary usage pattern for `dlinfo`."},"warnings":[{"fix":"Upgrade Python to version 3.9 or later, or pin `dlinfo` to `<2.0.0`.","message":"Version 2.0.0 removed compatibility with Python versions 3.5, 3.6, 3.7, and 3.8. Users on these older Python interpreters must remain on `dlinfo<2.0.0` or upgrade their Python environment to 3.9 or newer.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Change `except Exception:` to `except RuntimeError:` (or a more specific exception if applicable) for error handling related to `dlinfo` function failures.","message":"As of v2.0.0, the exception raised when the underlying `libc's dlinfo` function fails has changed from a generic `Exception` to a more specific `RuntimeError`. Update `except` blocks in your code accordingly.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your deployment environment is Linux or macOS. Be aware of potential platform-specific differences in behavior and available information.","message":"The library's core functionality relies on system-level C libraries (`libc's dlinfo` on Linux and `dyld_find` on macOS). This means its behavior is inherently platform-dependent and may not work on other operating systems like Windows without a POSIX compatibility layer, or might yield different results.","severity":"gotcha","affected_versions":"<all>"},{"fix":"Validate library paths and ensure the target shared library is accessible and correctly named for `ctypes.util.find_library()`. Add robust error handling around `ctypes` calls.","message":"The usage pattern involves direct interaction with Python's `ctypes` module to load shared libraries. Incorrect paths, non-existent libraries, or issues with `ctypes.util.find_library()` can lead to `OSError` or `AttributeError` when attempting to create `DLInfo` instances or access its properties.","severity":"gotcha","affected_versions":"<all>"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}