Barcode Generator API for Python
Generate barcodes in Python with a single requests.get() call - no barcode library, fonts or C extensions to install.
The BarGen REST API returns Code 128, EAN, UPC, GS1-128, DataMatrix or QR codes as SVG, PNG, PDF or EPS.
Authentication is one X-API-Key header; the free tier includes 1,000 calls per month.
GS1-128 and GS1 DataMatrix input is validated against GS1 Application Identifier rules server-side, so invalid element strings fail loudly instead of printing wrong labels.
Python has local barcode libraries, but they pull in image dependencies (Pillow, reportlab, custom fonts) and leave GS1 correctness entirely up to you. Using an API instead keeps your requirements.txt clean: the only dependency is requests, and rendering, validation and format quirks live server-side.
The pattern below covers most real uses: pick a barcode type, send the data, save or serve the bytes you get back. The same call works in Django and Flask views, Celery tasks, AWS Lambda functions and one-off scripts.
Setup
pip install requests
Generate barcodes in Python
import requests
API_KEY = "YOUR_API_KEY" # create one at bargen.pro/dashboard
BASE = "https://api.bargen.pro/v1"
def generate(barcode_type: str, data: str, fmt: str = "svg", **options) -> bytes:
"""Generate a barcode and return the image bytes."""
resp = requests.get(
f"{BASE}/barcode/{barcode_type}",
params={"data": data, "format": fmt, **options},
headers={"X-API-Key": API_KEY},
timeout=15,
)
resp.raise_for_status()
return resp.content
# A Code 128 barcode as SVG
svg = generate("code128", "ORDER-2026-0042")
with open("order.svg", "wb") as f:
f.write(svg)
# A GS1-128 barcode - Application Identifiers are validated server-side
gs1 = generate("gs1-128", "(01)09501101530003(17)261231(10)AB123")
# A QR code as PNG with a custom colour and scale
png = generate("qrcode", "https://bargen.pro", fmt="png", color="1a1a2e", scale=4)
Bulk generation with the batch endpoint
# Up to 50 barcodes in one request via the batch endpoint
resp = requests.post(
f"{BASE}/barcode/batch",
json={
"codes": [
{"type": "code128", "data": "SKU-0001"},
{"type": "code128", "data": "SKU-0002"},
{"type": "qrcode", "data": "https://example.com/p/1"},
],
"options": {"format": "svg"},
},
headers={"X-API-Key": API_KEY},
timeout=30,
)
resp.raise_for_status()
for item in resp.json()["results"]:
print(item["index"], item["success"])
Frequently asked questions
Do I need Pillow or any imaging library?
No. The API returns finished SVG, PNG, PDF or EPS bytes; requests is the only dependency. Write the bytes to a file, return them from a view, or attach them to a PDF - no local rendering stack involved.
How do I serve a generated barcode from Django or Flask?
Return the bytes with the right content type, e.g. HttpResponse(svg, content_type="image/svg+xml") in Django or Response(svg, mimetype="image/svg+xml") in Flask. For pages with many barcodes, generate server-side and cache, or use the batch endpoint (up to 50 codes per call).
What happens if my GS1 data is malformed?
The API rejects it with an HTTP error and a specific message (for example an invalid Application Identifier or a wrong field length) before anything is rendered, so raise_for_status() surfaces the problem in your logs instead of shipping a bad label.
Is there a free tier for development?
Yes - 1,000 API calls per month free, no credit card. That is enough for development and small production workloads; paid plans start at $29/month for 10,000 calls.
API basics
- Endpoint
- GET api.bargen.pro/v1/barcode/{type}
- Auth
- X-API-Key header
- Output
- SVG, PNG, PDF, EPS
- Formats
- 25 barcode types incl. GS1 and postal
- Free tier
- 1,000 calls/month
Other languages
Popular formats
Code on GitHub
Runnable examples for every language live in the public docs repository.
bargen-pro/bargen-api-docsStart generating barcodes from Python
Free tier with 1,000 API calls per month. No credit card required.