
Python Entry Points Explained - Nurdok
http://amir.rachum.com/blog/2017/07/28/python-entry-points/
======
rajathagasthya
I highly recommend reading Stevedore package's excellent documentation [1] to
see practical examples of how entry points can be used as a plugin manager in
applications.

[1] -
[https://docs.openstack.org/stevedore/latest/index.html](https://docs.openstack.org/stevedore/latest/index.html)

------
jwilk
Entry points are excellent at making your scripts start slooooooooow.

Compare

    
    
      $ time python -m pyflakes /dev/null
      
      real	0m0.225s
      user	0m0.103s
      sys	0m0.008s
    

with

    
    
      $ time pyflakes /dev/null
      
      real	0m2.468s
      user	0m1.738s
      sys	0m0.055s

~~~
ericfrederich
I did not get as dramatic of results as you.

    
    
      # python3 -m venv example
      # source example/bin/activate
      (example) # pip install pyflakes
      Collecting pyflakes
        Downloading pyflakes-1.5.0-py2.py3-none-any.whl (225kB)
          100% || 225kB 892kB/s 
      Installing collected packages: pyflakes
      Successfully installed pyflakes-1.5.0
      (example) # time for i in {00..99}; do python -m pyflakes /dev/null; done
      real    0m7.167s
      user    0m6.407s
      sys 0m0.750s
      (example) # time for i in {00..99}; do pyflakes /dev/null; done
      
      real    0m7.661s
      user    0m6.894s
      sys 0m0.753s

~~~
jwilk
I guess it gets worse when you have more stuff installed in the environment.

------
pmoriarty
Way too much ink wasted on cuteness and too little on explanation.

I got stumped at:

 _" In particular, the magic happens in get_sneks. The call to
pkg_resources.iter_entry_points('snek_types') iterates over all the entry
points that were registered under the name "snek_types". So, external packages
can define an entry point called "snek_types" in their setup.py, and snek will
dynamically load it at runtime."_

Wait. What entry points were registered under the name "snek_types"? Where
were they regeistered as such? I think I must be missing something, or maybe
that registration was hidden somewhere among all the fancy snakes. Can someone
help explain this in a clearer way?

~~~
antoncohen
"Snek Pro Solutions" distributes a package (pip installed) called cute-snek.
In the cute-snek setup.py it has:

    
    
        entry_points={
            'snek_types': [
                'cute = cute_snek:cute_snek',
            ],
        }
    

The main snek codebase has:

    
    
        for entry_point in pkg_resources.iter_entry_points('snek_types'):
            sneks[entry_point.name] = entry_point.load()
    

pkg_resources.iter_entry_points() iterates through all the snek_types an end
user has installed on their system. When the end user does `pip install snek`
they will only have the built-in sneks, when they also do `pip install cute-
snek` the will have the "cute" snek installed, allowing them to run `snek
--type cute` to see it.

------
sjburt
What is the actual value of entry points over just marking a script +x and
putting somewhere on the path? All I see is a bunch of added complexity.

~~~
rcthompson
Answering this question was pretty much the entire point of the article. I
felt that each section gave a concrete example of a situation where the
solution in the previous section fell short and then introducing some new
complexity to handle it.

