Skip to main content

pkgprint

Print and packaging math utilities for Python developers.

PyPI version Python 3.8+ License: MIT

pkgprint is a zero-dependency Python library that handles the fiddly maths behind print and packaging production: unit conversions, colour model translations, standard paper and box sizes, and bleed/margin arithmetic.


Installation

pip install pkgprint

Quick Start

import pkgprint

# Get A4 dimensions and convert to inches
w, h = pkgprint.paper_size("A4")
print(pkgprint.mm_to_inches(w), pkgprint.mm_to_inches(h))
# → 8.267716535433071 11.692913385826772

# Add 3 mm bleed to a business card
bleed_w, bleed_h = pkgprint.add_bleed(89, 51, bleed_mm=3)
print(bleed_w, bleed_h)
# → 95 57

# Convert a brand colour from CMYK to RGB
rgb = pkgprint.cmyk_to_rgb(0, 100, 100, 0)   # Pantone-ish red
print(rgb)
# → (255, 0, 0)

# Convert back from hex to RGB
print(pkgprint.hex_to_rgb("#FF5733"))
# → (255, 87, 51)

API Reference

units — Measurement Conversions

Function Description
mm_to_inches(mm) Millimetres → inches
inches_to_mm(inches) Inches → millimetres
mm_to_points(mm) Millimetres → typographic points (1 pt = 1/72 in)
points_to_mm(points) Points → millimetres
dpi_to_ppi(dpi) DPI → PPI (semantic alias, same unit)
ppi_to_dpi(ppi) PPI → DPI (semantic alias, same unit)
import pkgprint

pkgprint.mm_to_inches(25.4)     # → 1.0
pkgprint.inches_to_mm(8.5)      # → 215.9  (US Letter width)
pkgprint.mm_to_points(210)      # → 595.28 (A4 width in points)
pkgprint.points_to_mm(72)       # → 25.4
pkgprint.dpi_to_ppi(300)        # → 300
pkgprint.ppi_to_dpi(96)         # → 96

color — Colour Model Conversions

Function Description
cmyk_to_rgb(c, m, y, k) CMYK → RGB. Accepts 0–100 or 0–1 inputs.
rgb_to_cmyk(r, g, b) RGB → approximate CMYK (device-independent).
hex_to_rgb(hex_code) CSS hex string → RGB tuple. Supports #fff shorthand.
rgb_to_hex(r, g, b) RGB tuple → uppercase CSS hex string.
import pkgprint

pkgprint.cmyk_to_rgb(0, 100, 100, 0)   # → (255, 0, 0)  red
pkgprint.cmyk_to_rgb(0, 1, 1, 0)       # → (255, 0, 0)  same, 0–1 range
pkgprint.rgb_to_cmyk(0, 0, 255)         # → (100.0, 100.0, 0.0, 0.0)  blue
pkgprint.hex_to_rgb("#FF5733")          # → (255, 87, 51)
pkgprint.hex_to_rgb("#fff")             # → (255, 255, 255)  shorthand ok
pkgprint.rgb_to_hex(255, 87, 51)        # → '#FF5733'

paper — Standard Sizes

Function Description
paper_size(name) (width, height) in mm for a named paper size. Case-insensitive.
list_paper_sizes() Sorted list of all supported paper size names.
box_size(style) (length, width, height) in mm for a named packaging box. Case-insensitive.

Supported paper sizes: ISO A0–A8, B0–B6, C4–C6 (envelopes), Letter, Legal, Tabloid, Executive, ANSI A–E, Business Card, Postcard, and more.

Supported box styles: RSC Small/Medium/Large, Mailer A4/A5, Gift Small/Medium/Large, Tuck Small/Medium/Large.

import pkgprint

pkgprint.paper_size("A4")           # → (210, 297)
pkgprint.paper_size("letter")       # → (216, 279)  case-insensitive
pkgprint.box_size("RSC Medium")     # → (305, 229, 152)
pkgprint.list_paper_sizes()         # → ['A0', 'A1', ..., 'Tabloid', ...]

print_specs — Print Production Math

Function Description
add_bleed(width, height, bleed_mm=3) Trim size → artwork size with bleed on all four sides.
safe_margin(width, height, margin_mm=5) Trim size → safe content area (removes margins).
trim_size(width, height, bleed_mm=3) Artwork size (with bleed) → trim size.
import pkgprint

# Business card: 89 × 51 mm → with 3 mm bleed → 95 × 57 mm
pkgprint.add_bleed(89, 51)               # → (95, 57)

# A4 safe content area with 5 mm margins
pkgprint.safe_margin(210, 297, margin_mm=5)  # → (200, 287)

# Reverse: what is the trim size of a 220 × 307 mm file with 5 mm bleed?
pkgprint.trim_size(220, 307, bleed_mm=5)     # → (210, 297)

Build & Publish

# Install build tools
pip install build twine

# Build source + wheel
python -m build

# Test publish (TestPyPI)
twine upload --repository testpypi dist/*

# Real publish
twine upload dist/*

Running Tests

pip install pytest
pytest

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pkgprint-0.2.0.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pkgprint-0.2.0-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file pkgprint-0.2.0.tar.gz.

File metadata

  • Download URL: pkgprint-0.2.0.tar.gz
  • Upload date:
  • Size: 29.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for pkgprint-0.2.0.tar.gz
Algorithm Hash digest
SHA256 59858b3763213115190aed64920f7a6cca945a886bbbaaf80db59a05008e3635
MD5 8aa0368e2ebb85ebad88b6f02bca4ea0
BLAKE2b-256 b25bde01d23d55f5a06192522e6c9a160b1f5718732969238efbeb828fad977e

See more details on using hashes here.

File details

Details for the file pkgprint-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pkgprint-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for pkgprint-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5797346d7ac388f1781b464d8ec0da1de607c09527fd159afb80d3ef4d528f8e
MD5 694816549df62fedb2ef1a9113cbdf9f
BLAKE2b-256 4ac88535e8366658ebc790d8f9477e0017f46a6e23cb4ea8a773b758aba938ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page