up:: [[Click MOC]], [[Python Poetry MOC]] same:: [[Using Poetry to Change Python Versions and Create New Virtual Environment]] # Using Entry Points in Poetry If you need to use [entry points](https://stackoverflow.com/questions/774824/explain-python-entry-points) in a Poetry project, you can use a feature in `pyproject.toml` for the same behavior as in setuptools. This feature is the heading `[tool.poetry.scripts]`. Under this, you create the linkage between a command and a function in your script in the form of `cmd = "package.module.path:function"`, giving the fully qualified location of the function using the same dot notation as you would with an `import` statement. ## Example with [[Click Quickstart and Reference|Click]] Given the script `yourscript.py`: ```python import click @click.command() def cli(): """Example script.""" click.echo('Hello World!') ``` In Poetry, you'll add this to your `pyproject.toml` ```toml [tool.poetry.scripts] yourscript_cmd = "yourscript:cli" # command_name = "package.module.path:function" ``` The setuptools equivalent would be: ```python setup( ..., entry_points={ "console_scripts": [ "yourscript_cmd = yourscript:cli", # 1st yourscript is the callable name, then the rest defines import path, and after colon is the Click command ] } ) ``` To call this example, you would call `yourscript_cmd` in your favorite terminal emulator. ## Sources - [Setuptools](https://setuptools.pypa.io/en/latest/userguide/entry_point.html?highlight=entry%20point) - [Click-Setuptools Integration](https://click.palletsprojects.com/en/8.1.x/setuptools/#setuptools-integration) - [Poetry Scripts](https://python-poetry.org/docs/pyproject/#scripts) [^1] - [[Research Data Migration#^utgyyx|Original note]] [^1]: This documentation claims that plugins are the equivalent to setuptools' entry_points, but that does not work as expected.