Skip to main content

crochetpatterngen-engine

The deterministic photo-to-crochet-chart engine behind crochetpatterngen.com — packaged as a Python library, CLI, and MCP server so AI agents (Claude Desktop, Cursor, etc.) can turn photos into crochet charts with exact stitch counts.

Deterministic, not generative. There is no AI image generation here — just resize, median-cut color quantization, and confetti cleanup. Same input, same chart, same stitch counts, every time. No hallucinated rows.

Why this engine

  • Real stitch counts — every chart comes with per-color hex + stitch counts that sum exactly to the grid size. What you see is what you crochet.
  • C2C block aspect correction — C2C blocks are physically wider than tall (0.7:1 h:w). The engine adjusts grid dimensions so the worked piece keeps the photo's proportions instead of coming out squashed.
  • 5 technique presets — graph, c2c, tapestry, mosaic, filet.
  • Yarn estimation — per-color yardage for 6 yarn weights (fingering → super bulky).
  • Zero heavy deps — Pillow + numpy only. Optional rembg extra for background removal.

Install

pip install crochetpatterngen-engine          # core
pip install crochetpatterngen-engine[mcp]     # + MCP server
pip install crochetpatterngen-engine[rembg]   # + background removal

Python API

from PIL import Image
from crochet_chart_engine import generate_chart, render_design, estimate_yarn

png_bytes, meta = generate_chart(
    Image.open("photo.jpg"),
    technique="c2c",     # graph | c2c | tapestry | mosaic | filet
    grid_w=60,           # 20..120
    n_colors=8,          # 2..16
)
# meta: {"grid_w", "grid_h", "colors": [{"hex", "count"}],
#        "total_stitches", "technique", "warning"}

yarn = estimate_yarn(meta, weight="worsted")
# {"total_yards": ..., "colors": [{"hex", "count", "yards"}], ...}

png_bytes, meta = render_design("designs/frog.txt")  # ASCII design -> chart

CLI

crochet-chart chart photo.jpg out.png --technique c2c --grid-w 60 --colors 8
crochet-chart design designs/frog.txt frog.png
crochet-chart yarn photo.jpg --technique graph --weight worsted

MCP server (Claude Desktop & friends)

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "crochet": {
      "command": "uvx",
      "args": ["--from", "crochetpatterngen-engine[mcp]", "crochetpatterngen-mcp"]
    }
  }
}

Or with a regular pip install:

{
  "mcpServers": {
    "crochet": {
      "command": "python",
      "args": ["-m", "crochet_chart_engine.mcp_server"]
    }
  }
}

Tools exposed (stdio transport):

Tool What it does
photo_to_chart Local image path → chart PNG (base64 or saved to output_path) + per-color stitch counts JSON
render_ascii_design ASCII design file → chart PNG + stitch counts
estimate_yarn_tool Stitch counts → per-color yardage for one yarn weight or all

ASCII design format

See designs/frog.txt and designs/dragon.txt:

# comment
palette: G=#58A05C, W=#FFFFFF, .=#FAFAF7
title: Frog Face
technique: graph
---
..GGGG..........GGGG....
.GGWWGG........GGWWGG...

One character per stitch; . is the background/padding color. Rows are padded to the longest row.

Development

pip install -e .[dev,mcp]
pytest tests/

License

MIT — see LICENSE.


Free web tool + pattern library at crochetpatterngen.com.

Metadata

Release files for crochetpatterngen-engine 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crochetpatterngen-engine 0.1.1
File Size Uploaded Provenance
crochetpatterngen_engine-0.1.1.tar.gz 14.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for crochetpatterngen-engine 0.1.1
File Interpreter ABI Platform
crochetpatterngen_engine-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 28.9 kB

Release files / crochetpatterngen_engine-0.1.1.tar.gz

Download URL crochetpatterngen_engine-0.1.1.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4504b676d72e90105e8593f50eebcb287933d8216e44530173432efc463a1911
BLAKE2b-256 checksum
How to use checksums
30b1c9daab0021de78a0d6a3e3a326d56ddf6e58836330a3e688d9533b330d33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / crochetpatterngen_engine-0.1.1-py3-none-any.whl

Download URL crochetpatterngen_engine-0.1.1-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5398b055a30dec14fec7dd1e996100fc8c07e7fdcc30b41d8ff485faa4ec68b
BLAKE2b-256 checksum
How to use checksums
5151145998516453d6c7ed8452ea934bffa1fecd133db8232bbe400657c7a2e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Security for crochetpatterngen-engine 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page