Text of docs.python.org › es › 3 › library › importlib.metadata.html as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

importlib.metadata – Acceso a los metadatos de los paquetes — documentación de Python - 3.15.2

Navegación índice módulos | siguiente | anterior | Python » 3.15.2 documentation » The Python standard library » Importando módulos » importlib.metadata – Acceso a los metadatos de los paquetes | Tema | importlib.metadata – Acceso a los metadatos de los paquetes ¶ Added in version 3.8. Distinto en la versión 3.10: importlib.metadata ya no es provisional. Source code: Lib/importlib/metadata/__init__.py importlib.metadata is a library that provides access to the metadata of an installed Distribution Package , such as its entry points or its top-level names ( Import Package s, modules, if any).

Built in part on Python’s import system, this library provides the entry point and metadata APIs that were previously exposed by the now-removed pkg_resources package. Along with importlib.resources , it supersedes pkg_resources . importlib.metadata operates on third-party distribution packages installed into Python’s site-packages directory via tools such as pip . Specifically, it works with distributions with discoverable dist-info or egg-info directories, and metadata defined by the Core metadata specifications .

Importante These are not necessarily equivalent to or correspond 1:1 with the top-level import package names that can be imported inside Python code. One distribution package can contain multiple import packages (and single modules), and one top-level import package may map to multiple distribution packages if it is a namespace package. You can use packages_distributions() to get a mapping between them. By default, distribution metadata can live on the file system or in zip archives on sys.path .

Through an extension mechanism, the metadata can live almost anywhere. Ver también https://importlib-metadata.readthedocs.io/ La documentación de importlib_metadata , que proporciona un backport de importlib.metadata . Esto incluye una Referencia API para las clases y funciones de este módulo, así como una Guía de migración para los usuarios existentes de pkg_resources . Descripción general ¶ Let’s say you wanted to get the version string for a Distribution Package you’ve installed using pip .

We start by creating a virtual environment and installing something into it: $ python -m venv example $ source example/bin/activate (example) $ python -m pip install wheel Se puede obtener la cadena de versión para wheel ejecutando lo siguiente: (example) $ python >>> from importlib.metadata import version >>> version ( 'wheel' ) '0.32.3' You can also get a collection of entry points selectable by properties of the EntryPoint (typically “group” or “name”), such as console_scripts , distutils.commands and others.

Each group contains a collection of EntryPoint objects. Se pueden obtener los metadatos para una distribución : >>> from importlib.metadata import metadata >>> list ( metadata ( 'wheel' )) ['Metadata-Version', 'Name', 'Version', 'Summary', 'Home-page', 'Author', 'Author-email', 'Maintainer', 'Maintainer-email', 'License', 'Project-URL', 'Project-URL', 'Project-URL', 'Keywords', 'Platform', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Requires-Python', 'Provides-Extra', 'Requires-Dist', 'Requires-Dist'] También se puede obtener el número de versión de una distribución , enumerar sus archivos constituyentes y obtener una lista de los Requerimientos de la distribución de la distribución. exception importlib.metadata.

PackageNotFoundError ¶ Subclass of ModuleNotFoundError raised by several functions in this module when queried for a distribution package which is not installed in the current Python environment. exception importlib.metadata. MetadataNotFound ¶ Subclass of FileNotFoundError raised when attempting to load metadata from a distribution folder that is empty or otherwise does not contain a metadata file. API funcional ¶ Este paquete provee la siguiente funcionalidad a través de su API pública.

Puntos de entrada ¶ importlib.metadata. entry_points ( ** select_params ) ¶ Returns a EntryPoints instance describing entry points for the current environment. Any given keyword parameters are passed to the select() method for comparison to the attributes of the individual entry point definitions. Note: to query for entry points based on EntryPoint.dist attribute, use Distribution.entry_points() instead (as different Distribution instances do not currently compare equal, even if they have the same attributes) class importlib.metadata.

EntryPoints ¶ Details of a collection of installed entry points. Also provides a .groups attribute that reports all identified entry point groups, and a .names attribute that reports all identified entry point names. class importlib.metadata. EntryPoint ¶ Details of an installed entry point. Each EntryPoint instance has .name , .group , and .value attributes and a .load() method to resolve the value. There are also .module , .attr , and .extras attributes for getting the components of the .value attribute, and .dist for obtaining information regarding the distribution package that provides the entry point.

Consultar todos los puntos de entrada: >>> eps = entry_points () The entry_points() function returns a EntryPoints object, a collection of all EntryPoint objects with names and groups attributes for convenience: >>> sorted ( eps . groups ) ['console_scripts', 'distutils.commands', 'distutils.setup_keywords', 'egg_info.writers', 'setuptools.installation'] EntryPoints has a select() method to select entry points matching specific properties.

Select entry points in the console_scripts group: >>> scripts = eps . select ( group = 'console_scripts' ) Equivalently, since entry_points() passes keyword arguments through to select: >>> scripts = entry_points ( group = 'console_scripts' ) Elige un script específico llamado «wheel» (que se encuentra en el proyecto wheel ): >>> 'wheel' in scripts . names True >>> wheel = scripts [ 'wheel' ] De manera equivalente, consulta por ese punto de entrada durante la selección: >>> ( wheel ,) = entry_points ( group = 'console_scripts' , name = 'wheel' ) >>> ( wheel ,) = entry_points () . select ( group = 'console_scripts' , name = 'wheel' ) Inspeccionar el punto de entrada resuelto: >>> wheel EntryPoint(name='wheel', value='wheel.cli:main', group='console_scripts') >>> wheel . module 'wheel.cli' >>> wheel . attr 'main' >>> wheel . extras [] >>> main = wheel . load () >>> main <function main at 0x103528488> The group and name are arbitrary values defined by the package author and usually a client will wish to resolve all entry points for a particular group.

Read the setuptools docs for more information on entry points, their definition, and usage. Distinto en la versión 3.12: The «selectable» entry points were introduced in importlib_metadata 3.6 and Python 3.10. Prior to those changes, entry_points accepted no parameters and always returned a dictionary of entry points, keyed by group. With importlib_metadata 5.0 and Python 3.12, entry_points always returns an EntryPoints object.

See backports.entry_points_selectable for compatibility options. Distinto en la versión 3.13: EntryPoint objects no longer present a tuple-like interface ( __getitem__() ). Metadatos de distribución ¶ importlib.metadata. metadata ( distribution_name ) ¶ Return the distribution metadata corresponding to the named distribution package as a PackageMetadata instance. Raises PackageNotFoundError if the named distribution package is not installed in the current Python environment.

Raises MetadataNotFound if a distribution package is present but no METADATA file is present. class importlib.metadata. PackageMetadata ¶ A concrete implementation of the PackageMetadata protocol . In addition to providing the defined protocol methods and attributes, subscripting the instance is equivalent to calling the get() method. Every Distribution Package includes so

The rest of this page is on the live site.