Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 807 Bytes

20230821155645.md

File metadata and controls

52 lines (40 loc) · 807 Bytes

How to add a console script to your Python package:

1️⃣ Init a package - going with uv of course 😍

$ uv init --lib mypackage
$ tree mypackage
mypackage
├── README.md
├── pyproject.toml
└── src
 └── mypackage
 ├── __init__.py
 └── py.typed

3 directories, 4 files

2️⃣ Add a module + function

$ cat src/mypackage/script.py
def hello():
 print("Hello, world!")

3️⃣ Add your console script "entry point" to pyproject.toml -> package.module:callable ->

# pyproject.toml
...
...
[project.scripts]
hello = "mypackage.script:hello"

4️⃣ Build it 📈

$ uv build

5️⃣ Test it out 🎉

$ uv pip install -e .
# linked here now -> .venv/bin/hello
$ uv run hello
Hello, world!

#packaging #uv #commandline