API के माध्यम से बैच QR Code जनरेशन
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:
- Submit batch job via API with list of data items
- Receive a job ID immediately
- Server processes items asynchronously (queue + workers)
- Poll for completion or receive a webhook callback
- 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:
- Randomly select 1-5% of generated QR codes
- Decode each with a QR reader library
- Verify decoded data matches expected data
- Check image dimensions and file size consistency
- 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