# Why do script entrypoints require a function be specified?

**URL:** <https://discuss.python.org/t/why-do-script-entrypoints-require-a-function-be-specified/14090>\
**Category:** Packaging\
**Created:** [March 6, 2022, 7:08pm UTC](https://discuss.python.org/t/why-do-script-entrypoints-require-a-function-be-specified/14090 "2022-03-06T19:08:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![CAM-Gerlach](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cam-gerlach/32/3688_2.png) [@CAM-Gerlach](https://discuss.python.org/u/CAM-Gerlach)\
**Post date:** [March 6, 2022, 7:46pm UTC](https://discuss.python.org/t/why-do-script-entrypoints-require-a-function-be-specified/14090/2 "2022-03-06T19:46:24Z")

</div>

Just for others’ reference, this concern was [originally raised](https://discuss.python.org/t/help-testing-experimental-features-in-setuptools/13821/24) on the [PEP 621 Setuptools testing thread](https://discuss.python.org/t/help-testing-experimental-features-in-setuptools/13821), and discussed at some length there, which readers here might want to peruse first, particularly @abravalheri 's [detailed response](https://discuss.python.org/t/help-testing-experimental-features-in-setuptools/13821/30) giving some additional background on the current situation.

In any case, at least to my naive analysis, it would seem quite possible and desirable, either via a specification update PR or a short PEP (which I’m happy to help with), to modify this section to allow the behavior implied above (i.e. that of `runpy`)—specifically, if a module is specified, execute it as a script with ` __name__ == " __main__"`, and if a package, execute ` __main__ ,py` inside of it. This would simplify and, thusly, encourage a consistent best-practice approach to declaring a package’s main entrypoint, if it has one; namely, for package `spam`,

```ini
[project.scripts]
spam-cli = "spam"

```

instead of the following,

```ini
[project.scripts]
spam-cli = "spam. __main__.main"

```

for an entry point that would work equally by executing it via `spam-cli` and via `python -m spam`.

@pf_moore what do you think about this?

---

_[View the full topic](https://discuss.python.org/t/why-do-script-entrypoints-require-a-function-be-specified/14090)._
