通过API批量生成QR Code

Embed This Widget

Theme


      
    

Widget powered by . Free, no account required.

Generating thousands of QR codes programmatically: REST APIs, rate limiting, async processing, and file management.

Batch QR Code Generation via API

Generating thousands of QR codes programmatically for product labels, event tickets, or personalised marketing requires efficient batch processing.

API-Based Batch Generation

Most dynamic QR platforms provide batch endpoints or CSV import. For custom implementations:

import segno
import os

urls = [f"https://example.com/product/{i}" for i in range(1, 10001)]

os.makedirs("qr_output", exist_ok=True)
for i, url in enumerate(urls):
    qr = segno.make(url, error="m")
    qr.save(f"qr_output/product_{i+1:05d}.png", scale=8)

Async Processing

For large batches, use async processing:

  1. Submit batch job via API with list of data items
  2. Receive a job ID immediately
  3. Server processes items asynchronously (queue + workers)
  4. Poll for completion or receive a webhook callback
  5. Download results as a ZIP archive

Rate Limiting Strategies

When calling external QR generation APIs:

  • Fixed delay: Simple time.sleep(0.1) between requests
  • Token bucket: Allow bursts within an overall rate limit
  • Exponential backoff: Increase delay on 429 (rate limited) responses
  • Connection pooling: Reuse HTTP connections for efficiency

File Organisation

For print integration:

qr_output/
  batch_001/
    product_00001.svg
    product_00002.svg
    ...
  batch_002/
    product_10001.svg
    ...
  manifest.csv  # Maps filename to encoded data

The manifest file enables verification and print merge operations.

Quality Verification

After batch generation, verify a sample:

  1. Randomly select 1-5% of generated QR codes
  2. Decode each with a QR reader library
  3. Verify decoded data matches expected data
  4. Check image dimensions and file size consistency
  5. Flag any generation failures for re-processing

Key Takeaways

  • segno (Python) efficiently generates thousands of QR codes locally
  • Async processing with job queues handles large batches without timeout
  • Rate limiting prevents API throttling for external service calls
  • Manifest files link generated images to their encoded data
  • Sample verification catches generation errors before printing