# Python QR code libraries

Python QR code libraries encode text or a URL as a QR code and write it out as an image, a vector file, or terminal text. An encoder builds the grid of dark and light modules before a serializer draws it. These libraries let apps print payment links, tickets, and sign-in codes that a phone camera can scan.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [qrcode](#qrcode) | 36.3M | 5.0K | May 2025 | BSD |
| [Segno](#segno) | 12.0M | 823 | Mar 2025 | BSD-3-Clause |
| [PyQRCode](#pyqrcode-library) | 1.6M | 428 | Jun 2016 | BSD-3-Clause |
| [Treepoem](#treepoem) | 48.6K | 165 | Sep 2026 | MIT |
| [qrcodegen](#qrcodegen) | 27.4K | 6.8K | Apr 2022 | MIT |

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

[qrcode](#qrcode) has the most monthly downloads in this comparison, at 36.3M.

## Capabilities

| Library | SVG serializer | PNG serializer |
| --- | --- | --- |
| [qrcode](#qrcode) | Yes | Via plugin |
| [Segno](#segno) | Yes | Yes |
| [PyQRCode](#pyqrcode-library) | Yes | Via plugin |
| [Treepoem](#treepoem) | No | Via plugin |
| [qrcodegen](#qrcodegen) | No | No |

## Libraries

### qrcode

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

Creates QR symbols with configurable image factories and styled module rendering.

- Downloads / mo: 36.3M
- Stars: 5.0K
- Last release: 8.2
- License: BSD
- Capabilities: [From the qrcode docs](https://pypi.org/project/qrcode/)

**Strengths**

- **Provides PNG and SVG factories.** Render raster images or scalable vectors from the same QR generation API.
- **Supports styled QR modules.** Customize module shapes, colors, and embedded images through image factories.

**Watch out for**

- **Styled codes need reader testing.** Check styled output with target readers before using it in a product.
- **Appending data preserves previous content.** Clear the QR object before replacing its payload.

```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=Python%20projects%20using%20qrcode%20for%20enrollment%20QR%20image%20responses%2C%20SVG%20normalization%20and%20configurable%20encoding&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)

**Edinburgh-Genome-Foundry/blabel** (207 stars)

[Edinburgh-Genome-Foundry/blabel](https://github.com/Edinburgh-Genome-Foundry/blabel) 

```python
def qr_code(
    data, optimize=20, fill_color="black", back_color="white", **qr_code_params
):
    """Return a QR code's image data.

    Powered by the Python library ``qrcode``. See this library's documentation
    for more details.

    Parameters
    ----------
    data
      Data to be encoded in the QR code.

    optimize
      Chunk length optimization setting.

    fill_color, back_color
      Colors to use for QRcode and its background.

    **qr_code_params
      Parameters of the ``qrcode.QRCode`` constructor, such as ``version``,
      ``error_correction``, ``box_size``, ``border``.

    Returns
    -------
    image_base64_data
      A string ``data:image/png;base64,xxxxxxxxx`` which you can provide as a
      "src" parameter to a ``<img/>`` tag.

    Examples
    --------

    >>> data = qr_code('egf45728')
    >>> html_data = '<img src="%s"/>' % data
    """
    params = dict(box_size=5, border=0)
    params.update(qr_code_params)
    qr = qrcode.QRCode(**params)
    qr.add_data(data, optimize=20)
    qri = qr.make_image(fill_color=fill_color, back_color=back_color)
    return pil_to_html_imgdata(qri.get_image())

```

[blabel/label_tools.py](https://github.com/Edinburgh-Genome-Foundry/blabel/blob/9accd2dc00aabb4199fedad788f71384e7340096/blabel/label_tools.py#L66-L106) · [More projects using qrcode →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20qrcode%20for%20enrollment%20QR%20image%20responses%2C%20SVG%20normalization%20and%20configurable%20encoding&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 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/)

Creates QR and Micro QR symbols with dependency-free vector and raster serializers.

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

**Strengths**

- **Generates Micro QR symbols.** Create compact symbols or explicitly require standard QR output.
- **Exports without image dependencies.** Write SVG, PNG, and PDF using the included serializers.

**Watch out for**

- **Small payloads can become Micro.** Use make_qr or micro=False when the receiving system requires standard QR.
- **Error correction can increase automatically.** Disable boost_error when the selected error correction level must remain unchanged.

```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=Python%20projects%20using%20segno%20for%20enrollment%20QR%20image%20responses%2C%20SVG%20normalization%20and%20configurable%20encoding&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 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)

### PyQRCode

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

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

- Downloads / mo: 1.6M
- Stars: 428
- Last release: 1.2.1
- License: BSD-3-Clause
- Capabilities: [From the PyQRCode docs](https://pypi.org/project/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)

### Treepoem

[GitHub](https://github.com/adamchainz/treepoem) · [PyPI](https://pypi.org/project/treepoem) · [Docs](https://pypi.org/project/treepoem/)

Renders QR and other barcodes through BWIPP and Ghostscript, returning Pillow images.

- Downloads / mo: 48.6K
- Stars: 165
- Last release: 3.29.0
- License: MIT
- Capabilities: [From the Treepoem docs](https://pypi.org/project/treepoem/)

**Strengths**

- **Handles several barcode symbologies.** Use the same renderer for QR, Aztec, and linear barcode formats.
- **Returns images for further composition.** Add borders or combine the generated Pillow image with other graphics.

**Watch out for**

- **Requires external Ghostscript.** Install the Ghostscript executable alongside the Python package.
- **Options follow the barcode engine.** Pass barcode-specific BWIPP options rather than the other libraries’ QR keyword arguments.

```sh
pip install treepoem
```

**Quickstart**

```python
import treepoem
image = treepoem.generate_barcode(barcode_type='qrcode', data='Hello, world!')
image.save('qr.png')

```

From [README.rst](https://github.com/adamchainz/treepoem) · [Find projects using Treepoem →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20treepoem%20for%20enrollment%20QR%20image%20responses%2C%20SVG%20normalization%20and%20configurable%20encoding&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)

### qrcodegen

[GitHub](https://github.com/nayuki/QR-Code-generator) · [PyPI](https://pypi.org/project/qrcodegen) · [Docs](https://pypi.org/project/qrcodegen/)

Generates QR Code symbols in Python.

- Downloads / mo: 27.4K
- Stars: 6.8K
- Last release: 1.8.0
- License: MIT
- Capabilities: [From the qrcodegen docs](https://pypi.org/project/qrcodegen/)

```sh
pip install qrcodegen
```

**9001/copyparty** (47.4K stars)

[9001/copyparty](https://github.com/9001/copyparty) 

```python
def _qrgen(data: Union[bytes, Sequence[int]]) -> "QrCode":
    ret = None
    V = QrCode.Ecc
    for e in [V.HIGH, V.QUARTILE, V.MEDIUM, V.LOW]:
        qr = QrCode.encode_binary(data, e)
        qr.size = qr._size
        qr.modules = qr._modules
        if not ret or ret.size > qr.size:
            ret = qr
    return ret

```

[copyparty/qrkode.py](https://github.com/9001/copyparty/blob/deb0380511737ad10b89c9ea929215d9330cf18f/copyparty/qrkode.py#L29-L38) · [More projects using qrcodegen →](https://dashboard.exa.ai/playground/search?q=qrcodegen%20GitHub%20projects)

**Quickstart**

```python
from qrcodegen import QrCode
qr = QrCode.encode_text('Hello, world!', QrCode.Ecc.MEDIUM)

```

From [qrcodegen.py](https://raw.githubusercontent.com/nayuki/QR-Code-generator/v1.8.0/python/qrcodegen.py)

## FAQ

### Which Python QR code library should I use?

[qrcode](#qrcode) suits applications that style QR modules and embed images through image factories. [Segno](#segno) suits code that needs Micro QR symbols or SVG, PNG, and PDF output without other dependencies. [Treepoem](#treepoem) suits systems that render QR codes alongside other barcode formats.

### What is Segno?

[Segno](#segno) is a pure Python QR Code and Micro QR Code generator with no dependencies. It writes SVG, PNG, PDF, and other formats through its own serializers.

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

[qrcode](#qrcode) builds a code through its QRCode class and encodes it as an SVG or PNG image. [Segno](#segno) writes the same kind of code to SVG, PNG, or PDF without image dependencies.

### Why does a styled QR code fail on some readers?

[qrcode](#qrcode) does not guarantee that styled codes work with all readers. Its documentation recommends testing them and setting error correction to high, especially when embedding an image.

### Why did Segno produce a Micro QR symbol?

Segno's default factory picks the smallest version that fits the content, including Micro QR versions. The make_qr function requires a standard QR code instead.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python QR code generator libraries qrcode Segno PyQRCode Treepoem SVG PNG code examples",
    "numResults": 5
  }
}
```

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