# Python barcode libraries

Python barcode libraries generate barcode and QR code images and decode them from photos or scans. A generator encodes the data as bars or modules and writes the result to SVG, PNG, or PDF. These libraries let inventory, ticketing, and shipping systems print and scan codes from Python.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [ReportLab](#reportlab) | 91.2M | 88 | Oct 2026 | BSD |
| [opencv-python-headless](#opencv-python-headless) | 64.1M | 5.5K | Nov 2026 | Apache 2.0 |
| [qrcode](#qrcode) | 36.5M | 5.0K | May 2025 | BSD |
| [Segno](#segno) | 12.2M | 823 | Mar 2025 | BSD-3-Clause |
| [zxing-cpp](#zxing-cpp) | 5.9M | 2.1K | Jul 2026 | Apache-2.0 |
| [pyzbar](#pyzbar) | 3.0M | 831 | Mar 2022 | MIT |
| [python-barcode](#python-barcode) | 2.8M | 659 | Aug 2025 | MIT |
| [PyQRCode](#pyqrcode) | 1.7M | 428 | Jun 2016 | BSD |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[qrcode](#qrcode) has the most monthly downloads among dedicated barcode and QR code libraries in this comparison, at 36.5M.

## Capabilities

| Library | Encode symbols | Decode images |
| --- | --- | --- |
| [ReportLab](#reportlab) | Yes | No |
| [opencv-python-headless](#opencv-python-headless) | Yes | Yes |
| [qrcode](#qrcode) | Yes | No |
| [Segno](#segno) | Yes | No |
| [zxing-cpp](#zxing-cpp) | Yes | Yes |
| [pyzbar](#pyzbar) | No | Yes |
| [python-barcode](#python-barcode) | Yes | No |
| [PyQRCode](#pyqrcode) | Yes | No |

## Libraries

### ReportLab

[GitHub](https://github.com/MrBitBucket/reportlab-mirror) · [PyPI](https://pypi.org/project/reportlab) · [Docs](https://docs.reportlab.com/)

Provides the ReportLab PDF toolkit.

- Downloads / mo: 91.2M
- Stars: 88
- Last release: 5.1.0
- License: BSD
- Capabilities: [From the ReportLab docs](https://docs.reportlab.com/)

```sh
pip install reportlab
```

**Quickstart**

```python
from reportlab.graphics.barcode import createBarcodeDrawing

drawing = createBarcodeDrawing('Code128', value='ABC123')
svg = drawing.asString('svg')

```

From [__init__.py](https://github.com/MrBitBucket/reportlab-mirror/blob/master/src/reportlab/graphics/barcode/__init__.py) · [Find projects using ReportLab →](https://dashboard.exa.ai/playground/search?q=reportlab%20GitHub%20projects)

### opencv-python-headless

[GitHub](https://github.com/opencv/opencv-python) · [PyPI](https://pypi.org/project/opencv-python-headless) · [Docs](https://docs.opencv.org/5.1.0/)

Wraps the OpenCV Python bindings.

- Downloads / mo: 64.1M
- Stars: 5.5K
- Last release: 5.1.0.95
- License: Apache 2.0
- Capabilities: [From the opencv-python-headless docs](https://docs.opencv.org/5.1.0/)

```sh
pip install opencv-python-headless
```

**opencv/opencv** (91.6K stars)

[opencv/opencv](https://github.com/opencv/opencv) 

```python
def runQR(self, qrCode, inputimg):
    if not self.multi:
        if not self.detect:
            decode_info, points, _ = qrCode.detectAndDecode(inputimg)
            dec_info = decode_info
        else:
            _, points = qrCode.detect(inputimg)
            dec_info = []
    else:
        if not self.detect:
            _, decode_info, points, _ = qrCode.detectAndDecodeMulti(
                inputimg)
            dec_info = decode_info
        else:
            _, points = qrCode.detectMulti(inputimg)
            dec_info = []
    if points is None:
        points = []
    return points, dec_info

```

[samples/python/qrcode.py](https://github.com/opencv/opencv/blob/3e1cb2371a4c51a2da690ed64f763e94eeb1797e/samples/python/qrcode.py#L93-L111) · [More projects using opencv-python-headless →](https://dashboard.exa.ai/playground/search?q=opencv-python-headless%20GitHub%20projects)

**Quickstart**

```python
import cv2

image = cv2.imread('barcode.png')
detector = cv2.QRCodeDetector()
text, points, straight = detector.detectAndDecode(image)

```

From [README.md](https://docs.opencv.org/5.1.0/de/dc3/classcv_1_1QRCodeDetector.html)

### qrcode

[GitHub](https://github.com/lincolnloop/python-qrcode) · [PyPI](https://pypi.org/project/qrcode)

Generates QR code images.

- Downloads / mo: 36.5M
- Stars: 5.0K
- Last release: 8.2
- License: BSD
- Capabilities: [From the qrcode docs](https://github.com/lincolnloop/python-qrcode)

```sh
pip install "qrcode[pil]"
```

**jazzband/django-two-factor-auth** (1.9K stars)

[jazzband/django-two-factor-auth](https://github.com/jazzband/django-two-factor-auth) 

```python
def get(self, request, *args, **kwargs):
    # Get the data from the session
    try:
        key = self.request.session[self.session_key_name]
    except KeyError:
        raise Http404()

    # Get data for qrcode
    image_factory_string = getattr(settings, 'TWO_FACTOR_QR_FACTORY', self.default_qr_factory)
    image_factory = import_string(image_factory_string)
    content_type = self.image_content_types[image_factory.kind]
    username = self.get_username()

    otpauth_url = get_otpauth_url(accountname=username,
                                  issuer=self.get_issuer(),
                                  secret=key,
                                  digits=totp_digits())

    # Make and return QR code
    img = qrcode.make(otpauth_url, image_factory=image_factory)
    resp = HttpResponse(content_type=content_type)
    img.save(resp)
    return resp
```

[two_factor/views/core.py](https://github.com/jazzband/django-two-factor-auth/blob/a9c0b2e5d12f2848e646a8af4a251b2afc358e08/two_factor/views/core.py#L725-L747) · [More projects using qrcode →](https://dashboard.exa.ai/playground/search?q=qrcode%20GitHub%20projects)

**Quickstart**

```python
import qrcode
image = qrcode.make('Hello, world!')
image.save('qr.png')

```

From [README.rst](https://pypi.org/pypi/qrcode/8.2/json#info.description)

### Segno

[GitHub](https://github.com/heuer/segno) · [PyPI](https://pypi.org/project/segno) · [Docs](https://segno.readthedocs.io/en/stable/)

Generates QR codes and Micro QR codes.

- Downloads / mo: 12.2M
- Stars: 823
- Last release: 1.6.6
- License: BSD-3-Clause
- Capabilities: [From the Segno docs](https://segno.readthedocs.io/en/stable/)

```sh
pip install segno
```

**dprog-philippe-docourt/django-qr-code** (175 stars)

[dprog-philippe-docourt/django-qr-code](https://github.com/dprog-philippe-docourt/django-qr-code) 

```python
@validate_call(config=PYDANTIC_CONFIG)
def make_qr(data: Any, qr_code_options: QRCodeOptions, force_text: bool = True):
    """Creates a QR code that encodes the given `data` with the given `qr_code_options`.

    :param str data: The data to encode
    :param qr_code_options: Options to create and serialize the QR code.
    :param bool force_text: Tells whether we want to force the `data` to be considered as text string and encoded in byte mode.
    :rtype: segno.QRCode
    """
    # WARNING: For compatibility reasons, we still allow to pass __proxy__ class (lazy string). Moreover, it would be
    # OK to pass anything that has __str__ attribute (e.g. class instance that handles phone numbers).
    if force_text:
        return segno.make(str(data), **qr_code_options.kw_make(), mode="byte")
    return segno.make(data, **qr_code_options.kw_make())
```

[qr_code/qrcode/maker.py](https://github.com/dprog-philippe-docourt/django-qr-code/blob/2803a185e56c8e286d77d24b4b7c46dfa1de2445/qr_code/qrcode/maker.py#L23-L36) · [More projects using Segno →](https://dashboard.exa.ai/playground/search?q=segno%20GitHub%20projects)

**Quickstart**

```python
import segno
qr = segno.make_qr('Hello, world!')
qr.save('qr.png', scale=5)

```

From [README.rst](https://pypi.org/pypi/segno/1.6.6/json#info.description)

### zxing-cpp

[GitHub](https://github.com/zxing-cpp/zxing-cpp) · [PyPI](https://pypi.org/project/zxing-cpp) · [Docs](https://github.com/zxing-cpp/zxing-cpp/tree/master/wrappers/python)

Provides Python bindings for reading and generating barcode images with ZXing-C++.

- Downloads / mo: 5.9M
- Stars: 2.1K
- Last release: 3.1.1
- License: Apache-2.0
- Capabilities: [From the zxing-cpp docs](https://github.com/zxing-cpp/zxing-cpp/tree/master/wrappers/python)

**Strengths**

- **Reads and writes barcodes.** Decode image data or construct a barcode for rendering.
- **Accepts multiple image containers.** Read OpenCV, Pillow, Qt, or supported array buffers.

**Watch out for**

- **Color arrays default to BGR.** Convert RGB arrays or declare their memory layout with ImageView.

```sh
pip install zxing-cpp
```

**paperless-ngx/paperless-ngx** (48.2K stars)

[paperless-ngx/paperless-ngx](https://github.com/paperless-ngx/paperless-ngx) 

```python
def read_barcodes_zxing(image: Image.Image) -> list[tuple[str, str]]:
    """
    Returns the text and format (zxing enum name) of each barcode found in
    the image
    """
    barcodes = []

    import zxingcpp

    detected_barcodes = zxingcpp.read_barcodes(image)
    for barcode in detected_barcodes:
        if barcode.text:
            barcodes.append((barcode.text, barcode.format.name))
            logger.debug(
                f"Barcode of type {barcode.format} found: {barcode.text}",
            )

    return barcodes

```

[src/documents/barcodes.py](https://github.com/paperless-ngx/paperless-ngx/blob/28bb63824f795e8b4dc61e60c3b9919e36ff6855/src/documents/barcodes.py#L494-L511) · [More projects using zxing-cpp →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20zxing-cpp%20for%20barcode%20generation%20and%20image%20decoding&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import zxingcpp

barcode = zxingcpp.create_barcode('Hello, world!', zxingcpp.BarcodeFormat.QRCode)

```

From [README.md](https://github.com/zxing-cpp/zxing-cpp/blob/master/wrappers/python/README.md)

### pyzbar

[GitHub](https://github.com/NaturalHistoryMuseum/pyzbar) · [PyPI](https://pypi.org/project/pyzbar)

Reads linear barcodes and QR codes through the ZBar library.

- Downloads / mo: 3.0M
- Stars: 831
- Last release: 0.1.9
- License: MIT
- Capabilities: [From the pyzbar docs](https://github.com/NaturalHistoryMuseum/pyzbar)

**Strengths**

- **Returns barcode locations.** Use rectangle and polygon coordinates alongside each decoded payload.
- **Accepts common image objects.** Decode Pillow images, image arrays, or raw pixel buffers.

**Watch out for**

- **Unix systems need ZBar installed.** Install the shared library separately on non-Windows systems.
- **Bundled Windows builds omit orientation.** Bundled Windows DLLs cannot report barcode orientation.

```sh
pip install pyzbar pillow
```

**paperless-ngx/paperless-ngx** (48.2K stars)

[paperless-ngx/paperless-ngx](https://github.com/paperless-ngx/paperless-ngx) 

```python
@staticmethod
def read_barcodes_pyzbar(image: Image.Image) -> list[str]:
    barcodes = []

    from pyzbar import pyzbar

    # Decode the barcode image
    detected_barcodes = pyzbar.decode(image)

    # Traverse through all the detected barcodes in image
    for barcode in detected_barcodes:
        if barcode.data:
            decoded_barcode = barcode.data.decode("utf-8")
            barcodes.append(decoded_barcode)
            logger.debug(
                f"Barcode of type {barcode.type} found: {decoded_barcode}",
            )

    return barcodes

```

[src/documents/barcodes.py](https://github.com/paperless-ngx/paperless-ngx/blob/df5af5c8adbb6892f26c8240da8565c9a9fb143b/src/documents/barcodes.py#L199-L217) · [More projects using pyzbar →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20pyzbar%20for%20barcode%20generation%20and%20image%20decoding&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from PIL import Image
from pyzbar.pyzbar import decode

results = decode(Image.open('barcode.png'))

```

From [README.rst](https://github.com/NaturalHistoryMuseum/pyzbar/blob/master/README.rst)

### python-barcode

[GitHub](https://github.com/WhyNotHugo/python-barcode) · [PyPI](https://pypi.org/project/python-barcode) · [Docs](https://python-barcode.readthedocs.io/en/stable/)

Generates barcodes with vector and optional raster image writers.

- Downloads / mo: 2.8M
- Stars: 659
- Last release: 0.16.1
- License: MIT
- Capabilities: [From the python-barcode docs](https://python-barcode.readthedocs.io/en/stable/)

**Strengths**

- **Creates SVG without external dependencies.** Generate scalable barcode artwork without installing an image engine.
- **Calculates checksums automatically.** Supply the barcode value without calculating its checksum yourself.

**Watch out for**

- **Raster output needs Pillow.** Install the images extra before generating raster images.

```sh
pip install python-barcode
```

**inventree/InvenTree** (7.9K stars)

[inventree/InvenTree](https://github.com/inventree/InvenTree) 

```python
@register.simple_tag()
def barcode(data: str, barcode_class='code128', **kwargs) -> str:
    """Render a 1D barcode.

    Arguments:
        data: Data to encode
        barcode_class (str): The type of barcode to generate (default = 'code128')

    Keyword Arguments:
        format (str): Image format (default = 'PNG')
        fill_color (str): Foreground color (default = 'black')
        back_color (str): Background color (default = 'white')
        scale (float): Scaling factor (default = 1)

    Returns:
        image (str): base64 encoded image data
    """
    data = str(data).strip()

    if not data:
        raise ValidationError("barcode: No data provided to 'barcode' template tag")

    constructor = python_barcode.get_barcode_class(barcode_class)

    img_format = kwargs.pop('format', 'PNG')

    data = str(data).zfill(constructor.digits)

    writer = python_barcode_writer.ImageWriter

    barcode_image = constructor(data, writer=writer())

    image = barcode_image.render(writer_options=kwargs)

    # Render to byte-encoded image
    return image_data(image, fmt=img_format)

```

[src/backend/InvenTree/report/templatetags/barcode.py](https://github.com/inventree/InvenTree/blob/1f51dfe64bf4717fd95df51f1055ffb7a991a01d/src/backend/InvenTree/report/templatetags/barcode.py#L200-L235) · [More projects using python-barcode →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20python-barcode%20for%20barcode%20generation%20and%20image%20decoding&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from io import BytesIO
from barcode import EAN13

output = BytesIO()
EAN13('100000902922').write(output)

```

From [getting-started.rst](https://python-barcode.readthedocs.io/en/stable/getting-started.html)

### PyQRCode

[GitHub](https://github.com/mnooner256/pyqrcode) · [PyPI](https://pypi.org/project/pyqrcode) · [Docs](https://pythonhosted.org/PyQRCode/)

Generates QR codes in pure Python with SVG, EPS, PNG, and terminal output.

- Downloads / mo: 1.7M
- Stars: 428
- Last release: 1.2.1
- License: BSD
- Capabilities: [From the PyQRCode docs](https://pythonhosted.org/PyQRCode/)

```sh
pip install pyqrcode
```

**home-assistant/core** (92.3K stars)

[home-assistant/core](https://github.com/home-assistant/core) 

```python
def _generate_qr_code(data: str) -> str:
    """Generate a base64 PNG string represent QR Code image of data."""
    import pyqrcode  # noqa: PLC0415

    qr_code = pyqrcode.create(data)

    with BytesIO() as buffer:
        qr_code.svg(file=buffer, scale=4)
        return str(
            buffer.getvalue()
            .decode("ascii")
            .replace("\n", "")
            .replace(
                (
                    '<?xml version="1.0" encoding="UTF-8"?>'
                    '<svg xmlns="http://www.w3.org/2000/svg"'
                ),
                "<svg",
            )
        )
```

[homeassistant/auth/mfa_modules/totp.py](https://github.com/home-assistant/core/blob/aef7c996cbf2a46a37215ea768ab274f2a302506/homeassistant/auth/mfa_modules/totp.py#L39-L58) · [More projects using PyQRCode →](https://dashboard.exa.ai/playground/search?q=pyqrcode%20GitHub%20projects)

**Quickstart**

```python
import pyqrcode
qr = pyqrcode.create('Hello, world!')
qr.svg('qr.svg', scale=4)

```

From [moddoc.html](https://pythonhosted.org/PyQRCode/moddoc.html)

## FAQ

### Which Python barcode library should I use?

[python-barcode](#python-barcode) suits generating linear barcodes such as EAN and UPC. [Segno](#segno) and [qrcode](#qrcode) suit QR codes. [zxing-cpp](#zxing-cpp) suits reading and writing many barcode formats from one package.

### What is Segno?

[Segno](#segno) generates QR codes and Micro QR codes in pure Python. It writes SVG, PNG, and other formats with no extra dependencies.

### How do I generate a QR code in Python?

Install [qrcode](#qrcode) or [Segno](#segno), pass the text or URL, and save the result as an image. Both control error correction and module size.

### What is pyzbar?

[pyzbar](#pyzbar) reads linear barcodes and QR codes from images through the ZBar library. It needs the ZBar shared library installed on the system.

### How do I generate a barcode in Python?

[python-barcode](#python-barcode) generates EAN, UPC, and other linear barcodes as SVG or, with Pillow, as raster images.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python barcode libraries python-barcode pyzbar zxing-cpp Treepoem code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
