API Reference


Import the required subclasses of BaseImage from the qrcode library with a fallback to SVG format when the Pillow library is not available.


Tools for generating QR codes. This module depends on the qrcode python library.

class qr_code.qrcode.maker.SvgEmbeddedInHtmlImage(*args, **kwargs)[source]
qr_code.qrcode.maker.make_embedded_qr_code(text, qr_code_options=<qr_code.qrcode.utils.QRCodeOptions object>)[source]

Generates a <svg> or <img> tag representing the QR code for the given text. This tag can be embedded into an HTML document.

qr_code.qrcode.maker.make_qr_code_image(text, image_factory, qr_code_options=<qr_code.qrcode.utils.QRCodeOptions object>)[source]

Generates an image object (from the qrcode library) representing the QR code for the given text.

Any invalid argument is silently converted into the default value for that argument.



Generate a signed token to handle view protection.

qr_code.qrcode.serve.get_qr_url_protection_token(qr_code_options, random_token)[source]

Generate a random token for the QR code image.

The token contains image attributes so that a user cannot use a token provided somewhere on a website to generate bigger QR codes. The random_token part ensures that the signed token is not predictable.

qr_code.qrcode.serve.make_qr_code_url(text, qr_code_options=<qr_code.qrcode.utils.QRCodeOptions object>, cache_enabled=True, include_url_protection_token=True)[source]

Build an URL to a view that handle serving QR code image from the given parameters. Any invalid argument related to the size or the format of the image is silently converted into the default value for that argument.

The parameter cache_enabled (bool) allows to skip caching the QR code (when set to False) when caching has been enabled.

The parameter include_url_protection_token (bool) tells whether the random token for protecting the URL against external requests is added to the returned URL. It defaults to True.


Utility classes and functions for configuring and setting up the content and the look of a QR code.

class qr_code.qrcode.utils.ContactDetail(**kwargs)[source]

Represents the detail of a contact.

The following fields are provided:
  • first_name
  • last_name
  • first_name_reading: the sound of the first name.
  • last_name_reading: the sound of the last name.
  • tel: the phone number, it can appear multiple times.
  • tel_av: the video-phone number, it can appear multiple times.
  • email: the email address, it can appear multiple times.
  • memo: notes.
  • birthday: the birth date (Python date).
  • address: the fields divided by commas (,) denote PO box, room number, house number, city, prefecture, zip code and country, in order.
  • url: homepage URL.
  • nickname: display name.
  • org: organization or company name (non-standard,but often recognized, ORG field).

Make a text for configuring a contact in a phone book. The MeCARD format is used, with an optional, non-standard (but often recognized) ORG field.

See this archive of the format specifications: https://web.archive.org/web/20160304025131/https://www.nttdocomo.co.jp/english/service/developer/make/content/barcode/function/application/addressbook/index.html

Returns:the MeCARD contact description.
class qr_code.qrcode.utils.QRCodeOptions(**kwargs)[source]

Represents the options used to draw a QR code.

The following fields are provided:
  • size (int, str): the size of the QR code as an integer or a string. Default is ‘m’.
  • border (int): the size of the border (blank space around the code).
  • version (int): the version of the QR code gives the size of the matrix. Default is None which mean automatic in order to avoid data overflow.
  • image_format (str): the graphics format used to render the QR code. It can be either ‘svg’ or ‘png’. Default is ‘svg’.
  • error_correction: how much error correction that might be required to read the code. It can be either ‘L’, ‘M’, ‘Q’, or ‘H’. Default is ‘M’.
The size parameter gives the size of each module of the QR code matrix. It can be either a positive integer or one of the following letters:
  • t or T: tiny (value: 6)
  • s or S: small (value: 12)
  • m or M: medium (value: 18)
  • l or L: large (value: 30)
  • h or H: huge (value: 48)

For PNG image format the size unit is in pixels, while the unit is 0.1 mm for SVG format.

The border parameter controls how many modules thick the border should be (blank space around the code). The default is 4, which is the minimum according to the specs.

The version parameter is an integer from 1 to 40 that controls the size of the QR code matrix. Set to None to determine this automatically. The smallest, version 1, is a 21 x 21 matrix. The biggest, version 40, is 177 x 177 matrix. The size grows by 4 modules/side.

There are 4 error correction levels used for QR codes, with each one adding different amounts of “backup” data depending on how much damage the QR code is expected to suffer in its intended environment, and hence how much error correction may be required. The correction level can be configured with the error_correction parameter as follow:

  • l or L: error correction level L – up to 7% damage
  • m or M: error correction level M – up to 15% damage
  • q or Q: error correction level Q – up to 25% damage
  • h or H: error correction level H – up to 30% damage
class qr_code.qrcode.utils.WifiConfig(**kwargs)[source]

Represents the configuration of a Wi-Fi connexion.

The following fields are provided:
  • ssid: the name of the SSID
  • authentication: the authentication type for the SSID; can be AUTHENTICATION.wep or AUTHENTICATION.wpa, or AUTHENTICATION.nopass for no password. Or, omit for no password.
  • password: the password, ignored if “authentsication” is ‘nopass’ (in which case it may be omitted).
  • hidden: tells whether the SSID is hidden or not; can be True or False.

Make a text for configuring a Wi-Fi connexion. The syntax is inspired by the MeCARD format used for contacts.

Returns:the WIFI configuration text that can be translated to a QR code.


Tags for Django template system that help generating QR codes.


Accepts a ‘coordinates’ keyword argument or a triplet ‘latitude’, ‘longitude’, and ‘altitude’.


Accepts a ‘coordinates’ keyword argument or a pair ‘latitude’ and ‘longitude’.


Accepts a ‘coordinates’ keyword argument or a triplet ‘latitude’, ‘longitude’, and ‘altitude’.


Accepts a ‘coordinates’ keyword argument or a pair ‘latitude’ and ‘longitude’.