Build a `head`-style CLI in Python: takes one or more file paths (or reads stdin), accepts `-n <N>` to control the number of lines (default 10), and prints them with `==> filename <==` headers in multi-file mode. Ship as a real Python package with `pyproject.toml`, an editable-installable `[project.scripts]` entry point, ruff + mypy clean, and pytest covering both stdin and file modes.
argparse from stdlib for arg parsing — it's enough for this size and is one less dep.sys.stdin.isatty() returns False when piped. Iterate sys.stdin line by line — don't read all of it.open(path, 'r', encoding='utf-8') and use itertools.islice(f, n) to grab the first N lines. Don't load the whole file.def main() -> int: ... returning an exit code; the [project.scripts] shim calls sys.exit(main()).$ head-py -n 3 README.md
# head-py
A simple head clone in Python.
$ head-py README.md src/head_py/cli.py
==> README.md <==
# head-py
[... 10 lines ...]
==> src/head_py/cli.py <==
import argparse
[... 10 lines ...]
$ printf "a\nb\nc\nd\ne\n" | head-py -n 2
a
b
-c <BYTES> flag to print first N bytes (UTF-8 boundary aware via chunk = data[:n].decode('utf-8', errors='ignore')).--quiet flag that suppresses headers in multi-file mode.uv build && uv publish --publish-url https://test.pypi.org/legacy/. Verify pip install -i https://test.pypi.org/simple/ head-py works.