DEV Community

Cover image for How to Automate Metafield Meta Description Generation with Python
Oddshop
Oddshop

Posted on • Originally published at oddshop.work

How to Automate Metafield Meta Description Generation with Python

Managing hundreds of product meta descriptions manually is a time sink that breaks when you scale. A proper python meta description generator can automate this process by pulling data from your existing product fields and metafields.

The Manual Way (And Why It Breaks)

Creating meta descriptions for each product involves opening every item in your admin panel, copying product details, crafting unique descriptions, and pasting them back. For a store with 200+ products, this takes hours of repetitive work. You end up with inconsistent lengths, missed opportunities to include key product attributes like material types or sizes, and inevitable typos. When you add new products or update existing ones, you must repeat the entire process. This approach doesn't scale and introduces human error at every step while consuming development time that could focus on actual improvements to your shopify metafields and overall seo automation strategy.

The Python Approach

Here's a minimal script that handles basic template replacement:

import pandas as pd
import re
from pathlib import Path

def generate_meta_descriptions(input_file, template):
    df = pd.read_csv(input_file)  # Load product data
    output_rows = []

    for _, row in df.iterrows():
        processed_template = template
        # Find all {field_name} patterns
        matches = re.findall(r'\{([^}]+)\}', template)

        for field in matches:
            value = str(row.get(field, '')) if not pd.isna(row.get(field)) else ''
            processed_template = processed_template.replace(f'{{{field}}}', value)

        row['meta_description'] = processed_template[:160]  # Truncate to SEO limit
        output_rows.append(row)

    return pd.DataFrame(output_rows)
Enter fullscreen mode Exit fullscreen mode

This handles basic field substitution but lacks error handling, fallback values, and bulk processing capabilities. It works for simple cases but won't handle complex shopify metafields or missing data gracefully.

What the Full Tool Handles

Parse Shopify product CSV/JSON exports — extracts titles, descriptions, and metafields with proper error handling
Template engine for meta descriptions — uses {braces} to insert metafield values with validation
Bulk processing — generates descriptions for hundreds of products in one run without memory issues

Output to CSV or HTML — creates files ready for import or direct use in your workflow
Custom fallback values — defines text to use if a metafield is empty or missing
Dynamic meta descriptions — automatically pulls from your custom field extraction without manual intervention

The full python meta description generator handles edge cases like nested metafields, special characters, and different file formats while maintaining consistent output quality.

Running It

metagen --input products.csv --template "Handmade {material} {product_type}. {custom.description_short}" --output meta_updated.csv
Enter fullscreen mode Exit fullscreen mode

The --input flag specifies your product export file, --template defines how to structure descriptions using field names in braces, and --output creates the updated CSV with generated meta descriptions. The tool processes each line, substitutes the dynamic values, and enforces standard SEO length limits automatically.

Get the Script

Skip the build and get production-ready functionality immediately.

Download Metafield Meta Description Generator →

$29 one-time. No subscription. Works on Windows, Mac, and Linux.


Built by OddShop — Python automation tools for developers and businesses.

Top comments (0)