{"id":24241,"library":"pkginfo2","title":"pkginfo2","description":"Query metadata from sdists, bdists, and installed packages. A safer fork of pkginfo that avoids arbitrary imports and eval. Current version 30.1.0, released 2025-04. Maintained by AboutCode.org.","status":"active","version":"30.1.0","language":"python","source_language":"en","source_url":"https://github.com/aboutcode-org/pkginfo2","tags":["metadata","packaging","sdist","bdist","wheel","installed-packages"],"install":[{"cmd":"pip install pkginfo2","lang":"bash","label":"Latest from PyPI"}],"dependencies":[],"imports":[{"note":"Old library is pkginfo, not pkginfo2","wrong":"from pkginfo import get_metadata","symbol":"get_metadata","correct":"from pkginfo2 import get_metadata"},{"note":"No common wrong import known","symbol":"UnpackedSDist","correct":"from pkginfo2 import UnpackedSDist"}],"quickstart":{"code":"from pkginfo2 import get_metadata\n\n# Get metadata from a source distribution\nmetadata = get_metadata('pkginfo2-30.1.0.tar.gz')\nprint(metadata.name, metadata.version)\n\n# Get metadata from an installed package\nfrom pkginfo2.installed import Installed\ninst = Installed('pkginfo2')\nprint(inst.name, inst.version)\n\n# Use environment variable for a file path\nimport os\npath = os.environ.get('PKGINFO2_FILE', 'pkginfo2-30.1.0.tar.gz')\nmetadata = get_metadata(path)\nprint(metadata.name, metadata.version)","lang":"python","description":"Demonstrates reading metadata from a file and installed package."},"warnings":[{"fix":"Replace 'from pkginfo import ...' with 'from pkginfo2 import ...'","message":"pkginfo2 is a separate fork; do not mix imports with the original pkginfo. The API is similar but not identical.","severity":"breaking","affected_versions":"all"},{"fix":"Check for None before accessing attributes:\nmetadata = get_metadata('pkg.whl')\nif metadata is None:\n    raise ValueError('Could not read metadata')","message":"get_metadata() with a .whl file may return None if the wheel is not a valid zip or lacks METADATA file.","severity":"gotcha","affected_versions":">=30.0.0"},{"fix":"Upgrade to Python 3.10 or later.","message":"Python 3.10+ only. Older Python versions are not supported.","severity":"breaking","affected_versions":"30.0.0+"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install pkginfo2: pip install pkginfo2","cause":"Attempting to use old pkginfo package under the name pkginfo2.","error":"ModuleNotFoundError: No module named 'pkginfo'"},{"fix":"Check return value: metadata = get_metadata('file.whl'); if metadata is None: handle error","cause":"get_metadata() returned None for a .whl file without METADATA.","error":"AttributeError: 'NoneType' object has no attribute 'name'"},{"fix":"Upgrade to latest: pip install --upgrade pkginfo2","cause":"Old version of pkginfo2 (<30.0.0) may not include get_metadata.","error":"ImportError: cannot import name 'get_metadata' from 'pkginfo2'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}