━━━━━━━━━━━━ c o d e c h u · f m t ━━━━━━━━━━━━
format_duration(90) → 1m 30s
format_duration(0.0005) → 500µs
format_size(1536) → 1.5 KiB
format_size(-1024) → -1.0 KiB
format_rate(1.5e6, unit="bytes") → 1.5 MB/s
format_bitrate(2.5e9) → 2.5 Gbps
format_percent(0.42, locale="tr") → %42,0
format_compact(2_500_000_000) → 2.5B
━━━━━━━━━ raw numbers in. human strings out. ━━━━━━━━━
Precision formatters for durations, rates and byte sizes.
Stdlib-only human-readable formatters: durations, rates, byte sizes, bitrates, percent, large-number compact. Consistent NaN / negative handling across the family, locale support where it matters.
pip install codechu-fmtPython 3.10+. Zero third-party dependencies.
from codechu_fmt import format_duration, format_size, format_rate
print(format_duration(elapsed_secs)) # '1m 30s'
print(format_size(file.stat().st_size)) # '1.5 MiB'
print(format_rate(bytes_read / elapsed_secs,
unit="bytes")) # '3.2 MB/s'format_duration— two-unit human durations (0.5s/45.3s/1m 30s/1h 15m/ …).compact=Truefor tight status lines,integer_seconds=Truefor progress bars.format_rate— items/bytes/ops/custom-label per-second formatter withprecision="auto"(magnitude-adaptive decimals).format_size— IEC (KiB) or SI (kB) byte sizes. Negative values render with a leading-so size deltas read cleanly.format_bitrate— SI (1000-based) bitrate ladder for networking (bps→Kbps→Mbps→Gbps…).format_percent— 0–1 ratio → percent string, with"en"/"tr"locale variants.format_compact— large numbers →K/M/B/Tshort form for dashboards and counters.
NaN renders as "?" consistently. Negative inputs keep their
sign for size/rate/duration deltas.
- API reference — every formatter with signatures, edge cases, and rounding rules.
- Recipes — idiomatic patterns for log lines, progress bars, status fields.
- Migration guide — between major versions.
- Changelog
| Library | Purpose |
|---|---|
| codechu-meter | Timing — stopwatch, ETA, rate, histogram |
| codechu-spark | Unicode sparklines, mini bar charts, heatmaps |
| codechu-cli | CLI primitives — colors, progress, prompts |
| codechu-color | Color palettes, WCAG contrast |
| codechu-i18n | Internationalization — locale, plural rules, RTL |
Full ecosystem: github.com/codechu.
- IEC byte units per IEC 80000-13.
- SI bitrate conventions per Wikipedia: Data-rate units.
MIT — see LICENSE.
Part of Codechu.