Architecture
H9A is an installable Python package. The package (h9a/) contains four modules and an entry point, and the project is described by pyproject.toml.
Package layout
h9a/
├── __init__.py # public API exports and __version__
├── __main__.py # enables `python -m h9a`
├── cli.py # argparse command-line interface (h9a console script)
├── core.py # counting logic (DigitCount, count_digit, place_name)
├── render.py # styled output lines (build_lines, render_text)
└── screenshot.py # Pillow screenshot generator (generate_screenshot)
Call flow
flowchart TD
CLI["h9a/cli.py (argparse)"]
API["h9a/__init__.py (public API)"]
Core["h9a/core.py - count_digit()"]
Render["h9a/render.py - build_lines()"]
Shot["h9a/screenshot.py - generate_screenshot()"]
CLI --> Core
CLI --> Render
CLI --> Shot
API --> Core
API --> Render
API --> Shot
Render --> Core
Shot --> Render
Modules
| Module | Purpose |
|---|---|
h9a/core.py |
Defines the DigitCount dataclass and the count_digit() function, which counts each digit per decimal place using a closed-form, per-place formula (O(log n)) instead of iterating the range. Also provides place_name(). |
h9a/render.py |
Turns a DigitCount into a list of (text, style) lines via build_lines(), and into plain text via render_text(). Uses pyfiglet for the banner. |
h9a/cli.py |
argparse-based CLI. Maps style names to rich styles, supports --json, --no-color, and --screenshot. Registered as the h9a console script in pyproject.toml. |
h9a/screenshot.py |
generate_screenshot() renders the output lines to a terminal-style PNG using Pillow. Imports Pillow lazily so the rest of the package works without it. |
h9a/__init__.py |
Re-exports the public API (count_digit, DigitCount, place_name, build_lines, render_text, generate_screenshot) and __version__. |
Repository layout
h9a/
├── .github/
│ └── workflows/
│ ├── docs.yml # documentation -> GitHub Pages
│ └── publish-container.yml # container -> GHCR
├── Dockerfile
├── LICENSE # MIT
├── README.md
├── Screenshots/
│ └── home.png # generated by `h9a --screenshot`
├── docs/ # project documentation
├── h9a/ # installable package
│ ├── __init__.py
│ ├── __main__.py
│ ├── cli.py
│ ├── core.py
│ ├── render.py
│ └── screenshot.py
├── logo/
│ └── logo.svg
├── pyproject.toml # package metadata and h9a entry point
└── tests/ # pytest suite