An "entry point" is typically a function (or other callable function-like object) that a developer or user of your Python package might want to use, though a non-callable object can be supplied as an entry point as well (as correctly pointed out in the comments!).

The most popular kind of entry point is the console_scripts entry point, which points to a function that you want made available as a command-line tool to whoever installs your package. This goes into your setup.py script like:

entry_points={
    'console_scripts': [
        'cursive = cursive.tools.cmd:cursive_command',
    ],
},

I have a package I've just deployed called cursive.tools, and I wanted it to make available a "cursive" command that someone could run from the command line, like:

$ cursive --help
usage: cursive ...

The way to do this is define a function, like maybe a cursive_command function in the file cursive/tools/cmd.py that looks like:

def cursive_command():
    args = sys.argv[1:]
    if len(args) < 1:
        print "usage: ..."

and so forth; it should assume that it's been called from the command line, parse the arguments that the user has provided, and ... well, do whatever the command is designed to do.

Install the docutils package for a great example of entry-point use: it will install something like a half-dozen useful commands for converting Python documentation to other formats.

Answer from Brandon Rhodes on Stack Overflow
🌐
Python Packaging
packaging.python.org › specifications › entry-points
Entry points specification - Python Packaging User Guide
The group that an entry point belongs to indicates what sort of object it provides. For instance, the group console_scripts is for entry points referring to functions which can be used as a command, while pygments.styles is the group for classes defining pygments styles.
Top answer
1 of 3
297

An "entry point" is typically a function (or other callable function-like object) that a developer or user of your Python package might want to use, though a non-callable object can be supplied as an entry point as well (as correctly pointed out in the comments!).

The most popular kind of entry point is the console_scripts entry point, which points to a function that you want made available as a command-line tool to whoever installs your package. This goes into your setup.py script like:

entry_points={
    'console_scripts': [
        'cursive = cursive.tools.cmd:cursive_command',
    ],
},

I have a package I've just deployed called cursive.tools, and I wanted it to make available a "cursive" command that someone could run from the command line, like:

$ cursive --help
usage: cursive ...

The way to do this is define a function, like maybe a cursive_command function in the file cursive/tools/cmd.py that looks like:

def cursive_command():
    args = sys.argv[1:]
    if len(args) < 1:
        print "usage: ..."

and so forth; it should assume that it's been called from the command line, parse the arguments that the user has provided, and ... well, do whatever the command is designed to do.

Install the docutils package for a great example of entry-point use: it will install something like a half-dozen useful commands for converting Python documentation to other formats.

2 of 3
234

EntryPoints provide a persistent, filesystem-based object name registration and name-based direct object import mechanism (implemented by the setuptools package).

They associate names of Python objects with free-form identifiers. So any other code using the same Python installation and knowing the identifier can access an object with the associated name, no matter where the object is defined. The associated names can be any names existing in a Python module; for example name of a class, function or variable. The entry point mechanism does not care what the name refers to, as long as it is importable.

As an example, let's use (the name of) a function, and an imaginary python module with a fully-qualified name 'myns.mypkg.mymodule':

def the_function():
   "function whose name is 'the_function', in 'mymodule' module"
   print "hello from the_function"

Entry points are registered via an entry points declaration in setup.py. To register the_function under entrypoint called 'my_ep_func':

    entry_points = {
        'my_ep_group_id': [
            'my_ep_func = myns.mypkg.mymodule:the_function'
        ]
    },

As the example shows, entry points are grouped; there's corresponding API to look up all entry points belonging to a group (example below).

Upon a package installation (ie. running 'python setup.py install'), the above declaration is parsed by setuptools. It then writes the parsed information in special file. After that, the pkg_resources API (part of setuptools) can be used to look up the entry point and access the object(s) with the associated name(s):

import pkg_resources

named_objects = {}
for ep in pkg_resources.iter_entry_points(group='my_ep_group_id'):
   named_objects.update({ep.name: ep.load()})

Here, setuptools read the entry point information that was written in special files. It found the entry point, imported the module (myns.mypkg.mymodule), and retrieved the_function defined there, upon call to pkg_resources.load().

Calling the_function would then be simple:

>>> named_objects'my_ep_func'
hello from the_function

Thus, while perhaps a bit difficult to grasp at first, the entry point mechanism is actually quite simple to use. It provides an useful tool for pluggable Python software development.

🌐
PyPA
setuptools.pypa.io › en › latest › userguide › entry_point.html
Entry Points - setuptools 84.0.0 documentation
The recommended approach for loading and importing entry points is the importlib.metadata module, which is a part of the standard library since Python 3.8 and is non-provisional since Python 3.10. For older versions of Python, its backport importlib_metadata should be used.
🌐
DEV Community
dev.to › demianbrecht › entry-points-in-python-34i3
Entry points in Python - DEV Community
April 9, 2020 - #!/usr/bin/env python def say_hi(): print('Hello world!') say_hi() Running this file directly gives us an implicit entry point: Just by running the script we get right into execution:
🌐
PyPI
pypi.org › project › entrypoints
entrypoints · PyPI
Entry points are a way for Python packages to advertise objects with some common interface.
🌐
DEV Community
dev.to › borisuu › python-entry-points-1idk
Python entry points - DEV Community
October 19, 2023 - You can see we've registered a "default" module within the "ender.plugins" entry point, which points to the actual module 'ender.empty', which just maps to ender/empty.py. Now when the load_plugins function is run, the module will be loaded.
🌐
Medium
johndanielraines.medium.com › level-up-in-python-with-dependency-inversion-and-entry-points-c648a1b087ee
Level Up in Python with Dependency Inversion and Entry Points | by John Raines | Medium
December 16, 2023 - What’s more, Python has a fantastic native feature called Entry Points (supported by most packaging tools) that allows you to get a lot of extensibility out of Dependency Inversion, easily.
🌐
Amirrachum
amirrachum.com › amir rachum's blog › python entry points explained
Python Entry Points Explained - Amir Rachum's Blog
July 28, 2017 - How to use entry points as a modular plug-in architecture, to let other Python packages interact or add abilities at runtime.
Find elsewhere
🌐
Pylonsproject
docs.pylonsproject.org › projects › pylons-webframework › en › latest › advanced_pylons › entry_points_and_plugins.html
Using Entry Points to Write Plugins — Pylons Framework 1.0.2 documentation
An entry point is a Python object in a project’s code that is identified by a string in the project’s setup.py file. The entry point is referenced by a group and a name so that the object may be discoverable.
🌐
Readthedocs
python-packaging.readthedocs.io › en › latest › command-line-scripts.html
Command Line Scripts — Python Packaging Tutorial
This has advantage of being ... The second approach is called an ‘entry point’. Setuptools allows modules to register entrypoints which other packages can hook into to provide certain functionality....
🌐
Fmind
mlops-coding-course.fmind.dev › 3. Productionizing › 3.3. Entrypoints.html
3.3. Entrypoints - MLOps Coding Course
Package entrypoints are a formal way to make your Python package's functionality accessible from the command line.
🌐
Rachum
amir.rachum.com › amir rachum's blog › python entry points explained
Python Entry Points Explained - Amir Rachum's
July 28, 2017 - How to use entry points as a modular plug-in architecture, to let other Python packages interact or add abilities at runtime.
🌐
Chriswarrick
chriswarrick.com › blog › 2014 › 09 › 15 › python-apps-the-right-way-entry_points-and-scripts
Python Apps the Right Way: entry points and scripts | Chris Warrick
September 15, 2014 - There are multiple ways to write an app in Python. However, not all of them provide your users with the best experience. One of the problems some people encounter is writing launch scripts. The best way to handle this is the Entry Points mechanism of Setuptools, and a __main__.py file.
🌐
GitHub
github.com › Pylons › pylons › blob › master › pylons › docs › en › advanced_pylons › entry_points_and_plugins.rst
pylons/pylons/docs/en/advanced_pylons/entry_points_and_plugins.rst at master · Pylons/pylons
An entry point is a Python object in a project's code that is identified by a string in the project's setup.py file. The entry point is referenced by a group and a name so that the object may be discoverable.
Author: Pylons
🌐
DNMTechs
dnmtechs.com › understanding-python-entry-points-a-comprehensive-explanation-in-python-3-programming
Understanding Python Entry Points: A Comprehensive Explanation in Python 3 Programming – DNMTechs – Sharing and Storing Technology Knowledge
In Python, an entry point is a way to define a function or method that can be invoked from the command line or as part of a larger Python project. Entry points serve as the starting point for executing specific functionality within an application or library.
🌐
PyPI
pypi.org › project › entrypoint
entrypoint · PyPI
Decorated functions as entry points. In python, an entry point can be thought of as an explicit function that gets called when the script is run directly from the console.
🌐
Reddit
reddit.com › r/learnpython › how to specify entry points in "modern" python packages?
r/learnpython on Reddit: How to specify entry points in "modern" Python packages?
February 6, 2025 -

Instead of using the entry_points argument to setuptools.setup(), I'm as of recently supposed to put the file entry_points.txt into the .dist-info directory. But I don't understand how to do that because that directory gets automatically created during the package installation.

[EDIT]

I found that I have to make a [project.scripts] section in pyproject.toml, which upon installation creates the appropriate .dist-info/entry_points.txt. But it still doesn't install the actual callable command.

[EDIT 2]

I found that I made a totally stupid mistake and my executable ended up being named console_scripts. Please don't answer any more. I've downvoted my own OP.

Author: takluyver
🌐
Reddit
reddit.com › r/learnpython › can someone please explain entry points please?
r/learnpython on Reddit: Can someone please explain entry points please?
June 20, 2021 -

I understand what entry points are, but I don't necessarily understand how they work. The only two entry point methods I know are, using the cli as an entry point and the if name = main to trigger the main function.

If you use a single function as an entry point, does that trigger a kind of snowball effect which causes def statements to start triggering one after another as they call each other?

How would an entry point work in automation? Say you have a package with a module made up of def statements to do some task. These are commands you can run manually in the cli, but you want to automate it. What would be used as the entry point? Just a helper.py with minimal lines to get the process going?

This might need to be its own question, but how would an entry point work for a flask or django web app? If everything is an object and everything is a def statement, what do web apps use for an entry point? Does each app just have it's own setup.py. But even still, if something is triggered by interaction on the website - how does an entry point work in that kind of situation?

🌐
Readthedocs
entrypoints.readthedocs.io
entrypoints 0.4 — entrypoints 0.4 documentation
Entry points are a way for Python packages to advertise objects with some common interface.