Entrypoints

raw JSON →
0.4 verified Tue May 12 auth: no python install: verified quickstart: stale maintenance

The `entrypoints` library facilitates the discovery and loading of entry points advertised by installed Python packages. It offers a lightweight and faster alternative to `pkg_resources` for this specific functionality, avoiding the full package scans that can slow down `pkg_resources` at import time. The current version is 0.4. The package is in maintenance-only mode, with new code advised to use the `importlib.metadata` module from the Python standard library for entry point management.

pip install entrypoints
error AttributeError: 'EntryPoints' object has no attribute 'get'
cause This error typically occurs when using an older API for accessing entry points (like `get()`) on an `EntryPoints` object, which has changed its interface in `importlib-metadata` versions 5.0 and higher. The `entrypoints` library itself is in maintenance mode and newer Python versions often implicitly use `importlib.metadata`.
fix
Pin your importlib-metadata package to version 4.13.0 or earlier (pip install 'importlib-metadata<5'). Alternatively, if using importlib.metadata directly, adopt the modern select() method to retrieve entry points by group or name, rather than dictionary-like access.
error ModuleNotFoundError: No module named 'your_package_name' (when running a console_script)
cause This usually happens when a console script defined in `pyproject.toml` or `setup.py` (which internally uses entry points) cannot find the module it's supposed to execute. This can be due to incorrect package structure, missing `__init__.py` files, or the package not being properly installed in the environment where the script is run.
fix
Ensure your package has __init__.py files in all its directories to be recognized as a package. Verify the module path specified in your console_scripts entry point (e.g., my_script=my_package.module:function) is correct and that the package is installed in the active Python environment (use pip install -e . for development installs).
error DeprecationWarning: SelectableGroups dict interface is deprecated. Use select().
cause This warning indicates that code is using a dictionary-like interface on the `EntryPoints` object, which is being phased out in `importlib.metadata` (and thus affects `entrypoints` usage as well). While currently a warning, it will become an `AttributeError` in future versions.
fix
Refactor your code to use the select() method on the EntryPoints object to filter by group or name. For example, instead of entry_points()['my_group'], use entry_points(group='my_group') or entry_points().select(group='my_group').
breaking The `entrypoints` package is in maintenance-only mode. New code should use `importlib.metadata` (part of the Python standard library since 3.8, non-provisional since 3.10) for discovering and loading entry points. For Python versions older than 3.8, consider using the `importlib_metadata` backport.
fix Migrate to `importlib.metadata` for new implementations: `from importlib.metadata import entry_points` (or `from importlib_metadata import entry_points` for older Python).
gotcha When multiple versions of the same distribution are present in different directories on `sys.path`, `entrypoints` follows a 'first one wins' rule. This typically aligns with Python's import logic, but can lead to unexpected behavior if specific versions are expected.
fix Ensure a clean and controlled Python environment, ideally using virtual environments, where only the desired version of a package is available. Rely on `pip` to manage package installations to avoid multiple `.dist-info` or `.egg-info` directories for the same package.
gotcha `entrypoints` relies on `pip` (or similar tools) to ensure only one `.dist-info` or `.egg-info` directory exists for each installed package. If this assumption is violated, there's no reliable way to pick the correct metadata, which can lead to incorrect entry point resolution.
fix Always use standard package managers like `pip` for installation. Avoid manual manipulation of `site-packages` or `dist-info`/`egg-info` directories. If issues arise, a clean reinstallation in a fresh virtual environment is recommended.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.03s 17.8M
3.10 alpine (musl) - - 0.03s 17.8M
3.10 slim (glibc) wheel 1.5s 0.02s 18M
3.10 slim (glibc) - - 0.02s 18M
3.11 alpine (musl) wheel - 0.04s 19.6M
3.11 alpine (musl) - - 0.05s 19.6M
3.11 slim (glibc) wheel 1.6s 0.04s 20M
3.11 slim (glibc) - - 0.04s 20M
3.12 alpine (musl) wheel - 0.04s 11.5M
3.12 alpine (musl) - - 0.04s 11.5M
3.12 slim (glibc) wheel 1.4s 0.04s 12M
3.12 slim (glibc) - - 0.04s 12M
3.13 alpine (musl) wheel - 0.03s 11.2M
3.13 alpine (musl) - - 0.03s 11.1M
3.13 slim (glibc) wheel 1.5s 0.03s 12M
3.13 slim (glibc) - - 0.03s 12M
3.9 alpine (musl) wheel - 0.02s 17.3M
3.9 alpine (musl) - - 0.03s 17.3M
3.9 slim (glibc) wheel 1.8s 0.02s 18M
3.9 slim (glibc) - - 0.02s 18M

This quickstart demonstrates how to find and load entry points, specifically 'console_scripts'. It iterates through found entry points, prints their details, and attempts to load the associated Python object.

from entrypoints import get_group_all

# Example: Find all 'console_scripts' entry points
console_scripts = get_group_all('console_scripts')

print(f"Found {len(console_scripts)} console scripts:")
for ep in console_scripts:
    print(f"  - {ep.name}: {ep.module}.{ep.attr}")
    try:
        # Load the entry point (e.g., a function)
        loaded_object = ep.load()
        # You can then call the loaded_object if it's a function
        # print(f"    Loaded object: {loaded_object}")
    except Exception as e:
        print(f"    Could not load {ep.name}: {e}")