# 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:** 16

<div class="post-metadata">

**Author:** ![pf\_moore](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pf_moore/32/35_2.png) [@pf\_moore](https://discuss.python.org/u/pf_moore)\
**Post date:** [April 7, 2024, 11:16am UTC](https://discuss.python.org/t/why-do-script-entrypoints-require-a-function-be-specified/14090/16 "2024-04-07T11:16:33Z")

</div>

> [@kpfleming](#):
>
> Your proposal gives special meaning to a module named ` __main__.py`

` __main__.py` is already special - see [the documentation](https://docs.python.org/3.12/using/cmdline.html#interface-options) (specifically, the discussion of the `<script>` argument) and [the documentation of the `runpy.run_module` function](https://docs.python.org/3.12/library/runpy.html#runpy.run_module).

The proposal is that

```python
[project.scripts]
foo_cmd = foo

```

will create an entry point that’s equivalent to running `python -m foo`.

The specific specification change would be to [this text](https://packaging.python.org/en/latest/specifications/entry-points/#use-for-scripts)

> The object reference points to a function which will be called with no arguments when this command is run.

which would need to be amended to say

> The object reference points to a function which will be called with no arguments when this command is run, or a module which will be run as if invoked via `python -m module`.

The spec change would require a change to any code that currently creates entry point wrappers - that’s at least [`distlib`](https://github.com/pypa/distlib/blob/master/distlib/scripts.py#L224) (which would handle pip as well), [`installer`](https://github.com/pypa/installer/blob/main/src/installer/scripts.py#L93), and [`uv`](https://github.com/astral-sh/uv/blob/main/crates/install-wheel-rs/src/wheel.rs#L45), and possibly others. It might also need changes to build backends to allow the module-only form of the script specification - the [`pyproject.toml` specification for entry points](https://packaging.python.org/en/latest/specifications/pyproject-toml/#entry-points) doesn’t prohibit the module form for scripts, but backends might do so, given that it’s not currently possible to generate a script wrapper for that form.

It mostly just needs someone to do the work to (a) create PRs implementing this proposal, both to the spec and to the installers, and (b) collect agreement to the change from installers and any affected backends, as evidence that the proposal change is acceptable.

---

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