Metadata-Version: 2.4
Name: printify-automation
Version: 0.1.0
Summary: Python automation package for Printify product creation, image placement, and batch processing
Author: DevPK
Project-URL: Homepage, https://github.com/imprashant98/printify-automation
Project-URL: Repository, https://github.com/imprashant98/printify-automation
Project-URL: Issues, https://github.com/imprashant98/printify-automation/issues
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.28.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: pillow>=9.0.0
Requires-Dist: rich>=12.0.0

# Printify Automation Python Package

A modular, extensible Python package and CLI automation suite for **Printify**. Dynamically configure image path, image size/scale, placement (x, y, angle), pricing markups, color variants, and AI metadata generation to create Printify products.

Based on production TypeScript automation scripts and converted into an idiomatic, reusable Python package.

---

## Sizing Modes & Resolution

### Sizing Modes (`--size-mode`)
- **`fit`** *(default)*: Proportional safe fit (`scale: 0.85`, centered `x: 0.5, y: 0.5`). Prevents edge cropping.
- **`center`**: Classic chest placement with comfortable margins (`scale: 0.80`, centered `x: 0.5, y: 0.5`).
- **`stretch`**: Full-bleed maximum printable width (`scale: 0.98`, edge-to-edge).
- **`custom`**: Explicit manual `--scale`, `--x`, and `--y` values.

### Output Resolutions (`--resolution`)
- Options: `original` (default), `1800px`, `2400px`, `3600px`, `4500px`.
- High-quality Lanczos resampling maintains exact aspect ratios and caches resized files in `.cache/resized/`.

### Test-1-First Gate (`--test-first`)
When processing batches, test 1 product first before running all images:
1. Creates the first sample product in Printify.
2. Displays the direct Printify Dashboard review URL.
3. Asks user to confirm mockup quality before processing remaining images.

```bash
# Batch with Test-1-First and Fit mode
printify-batch --folder /path/to/art --size-mode fit --resolution 2400px --test-first
```
- **Single & Batch Product Creation**: Create one product or batch process entire artwork directories with automatic progress tracking (`sweatshirt_progress.json`), resume capability, and rate-limiting delays.
- **Smart Upload Caching**: Disk-backed cache (`.cache/printify_uploads.json`) calculates file SHA256 hashes to prevent redundant image uploads.
- **Variant Filtering & Markup**: Auto-filters catalog variants by allowed color palettes (e.g. Comfort Colors: *Pepper, Blue Spruce, Seafoam, Terracotta...*) and applies dynamic profit markups (e.g. `1.5` = +50%).
- **Interactive Wizard & CLI**: Run with an interactive terminal wizard or execute directly via command-line flags.
- **AI-Powered Copywriting (Optional)**: Automatically generates SEO-optimized product titles, descriptions, and tags using local Ollama (Llava/Vision models) with dependable rule-based fallbacks.
- **Product Utilities**: Bulk-update product variants or move products between stores.

---

## Installation

```bash
cd printify-python

# Install package in editable mode
pip install -e .
```

### Environment Configuration

Create a `.env` or `.env.local` file:

```env
PRINTIFY_API_TOKEN=your_printify_api_token
PRINTIFY_SHOP_ID=your_shop_id

# Optional: Local Ollama for AI metadata generation
OLLAMA_URL=http://localhost:11434/api/generate
OLLAMA_MODEL=llava
```

---

## Quick Start (Interactive Wizard)

Run the wizard without arguments to be prompted for inputs dynamically:

```bash
printify-automation
# or:
python scripts/create_product.py
```

The wizard prompts you for:
1. Shop ID (or select from your connected shops)
2. Mode (Single Image or Batch Directory)
3. Product preset (Sweatshirt, T-shirt, Hoodie, or custom blueprint)
4. Image placement & scale (e.g., `0.8`, `x: 0.5`, `y: 0.5`)
5. Price markup multiplier
6. Metadata (Manual or AI generated)

---

## CLI Usage

### 1. Create a Single Product Dynamically

```bash
# Basic creation with dynamic image and custom scale
printify-create --image /path/to/design.png --scale 0.85 --title "Sunset Beach Sweatshirt"

# Advanced with custom placement, shop, and color filters
printify-create \
  --image /path/to/design.png \
  --scale 0.8 \
  --x 0.5 --y 0.48 \
  --shop-id 12345678 \
  --blueprint-id 1296 \
  --provider-id 39 \
  --markup 1.5 \
  --colors "pepper,blue spruce,seafoam,white" \
  --ai
```

### 2. Batch Create from Folder

```bash
printify-batch \
  --folder /path/to/artwork_folder \
  --scale 0.8 \
  --markup 1.5 \
  --progress-file sweatshirt_progress.json \
  --delay 2.0
```

### 3. List Shops & Blueprints

```bash
# List all connected shops
printify-automation shops

# Inspect variants for a blueprint & provider
printify-automation variants --blueprint-id 1296 --provider-id 39
```

### 4. Move Products Between Shops

```bash
printify-automation move --from-shop 12345678 --to-shop 87654321 --filter "hoodie"
```

---

## Python API Usage

You can also use the package inside your own Python code:

```python
from printify_automation import ProductBuilder, ImagePlacement, PrintifyClient

client = PrintifyClient(api_token="your_token")
builder = ProductBuilder(client=client)

# Define custom placement dynamically
placement = ImagePlacement(
    x=0.5,
    y=0.48,
    scale=0.82,
    position="front"
)

product = builder.create(
    image="/path/to/artwork.png",
    shop_id="12345678",
    blueprint_id=1296,        # Comfort Colors Sweatshirt
    print_provider_id=39,     # SwiftPOD
    placement=placement,
    price_markup=1.5,
    allowed_colors=["pepper", "seafoam", "white"],
    title="Coastal Comfort Sweatshirt",
    description="Heavyweight garment-dyed sweatshirt with premium graphic print."
)

print(f"Created product: {product['id']}")
```

---

## Project Structure

```
printify-python/
├── printify_automation/          # Main package
│   ├── __init__.py
│   ├── client.py                 # Printify REST API client
│   ├── image_utils.py            # Image metadata & dynamic placement calculation
│   ├── cache.py                  # Disk cache for uploads
│   ├── ai.py                     # Ollama / Llava metadata generator & fallback
│   ├── builder.py                # High-level product orchestrator
│   ├── batch.py                  # Directory batch processor & progress tracking
│   └── cli.py                    # Interactive wizard & CLI subcommands
├── scripts/
│   ├── create_product.py         # Standalone single product runner
│   ├── batch_create.py           # Standalone batch runner
│   └── update_variants.py        # Bulk variant updater
├── tests/
│   └── test_automation.py        # Automated test suite
├── pyproject.toml
└── README.md
```

## Running Tests

```bash
python -m unittest discover tests
```
