Skip to main content

Print and packaging math utilities for developers

Project description

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.

Project details


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.1.0.tar.gz (15.5 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.1.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pkgprint-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dd863b3f86105ffad4e0d7486ce4970f68136a45ebf06510cf71830b73e1ea27
MD5 2468b27402033c4b81083ca27a059277
BLAKE2b-256 8c1b0733244ec78ab5fa61c061814d2cb1423c1f7b1e716294f7245e7a56e548

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pkgprint-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9cc8f88ecae9f26f8c4dfd79c66b515c33932a267348f7bc7361fe101a5b8959
MD5 faef701cbef4e306ab3b69e7df9a4d72
BLAKE2b-256 98217a284f74acc4fca303796da06c7755ecdef1f58a3b569e205bfe25357445

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 Pingdom Monitoring Sentry Error logging StatusPage Status page