Metadata-Version: 2.2
Name: pkgprint
Version: 0.1.0
Summary: Print and packaging math utilities for developers
Author: Rishabh
License: MIT
Project-URL: Homepage, https://github.com/Rishabh55122/pkgprint
Project-URL: Bug Tracker, https://github.com/Rishabh55122/pkgprint/issues
Keywords: print,packaging,design,cmyk,dpi,bleed,typography
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Intended Audience :: Developers
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"

# pkgprint

**Print and packaging math utilities for Python developers.**

[![PyPI version](https://badge.fury.io/py/pkgprint.svg)](https://pypi.org/project/pkgprint/)
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

`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

```bash
pip install pkgprint
```

---

## Quick Start

```python
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) |

```python
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. |

```python
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.

```python
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. |

```python
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

```bash
# 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

```bash
pip install pytest
pytest
```

---

## License

MIT — see [LICENSE](LICENSE).
