METADATA 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. Metadata-Version: 2.1
  2. Name: qrcode
  3. Version: 8.2
  4. Summary: QR Code image generator
  5. Home-page: https://github.com/lincolnloop/python-qrcode
  6. License: BSD
  7. Keywords: qr,denso-wave,IEC18004
  8. Author: Lincoln Loop
  9. Author-email: info@lincolnloop.com
  10. Requires-Python: >=3.9,<4.0
  11. Classifier: Development Status :: 5 - Production/Stable
  12. Classifier: Intended Audience :: Developers
  13. Classifier: License :: OSI Approved :: BSD License
  14. Classifier: License :: Other/Proprietary License
  15. Classifier: Operating System :: OS Independent
  16. Classifier: Programming Language :: Python
  17. Classifier: Programming Language :: Python :: 3
  18. Classifier: Programming Language :: Python :: 3.9
  19. Classifier: Programming Language :: Python :: 3.10
  20. Classifier: Programming Language :: Python :: 3.11
  21. Classifier: Programming Language :: Python :: 3.12
  22. Classifier: Programming Language :: Python :: 3 :: Only
  23. Classifier: Programming Language :: Python :: 3.13
  24. Classifier: Topic :: Multimedia :: Graphics
  25. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  26. Provides-Extra: all
  27. Provides-Extra: pil
  28. Provides-Extra: png
  29. Requires-Dist: colorama ; sys_platform == "win32"
  30. Requires-Dist: pillow (>=9.1.0) ; extra == "pil" or extra == "all"
  31. Requires-Dist: pypng ; extra == "png" or extra == "all"
  32. Description-Content-Type: text/x-rst
  33. =============================
  34. Pure python QR Code generator
  35. =============================
  36. Generate QR codes.
  37. A standard install uses pypng_ to generate PNG files and can also render QR
  38. codes directly to the console. A standard install is just::
  39. pip install qrcode
  40. For more image functionality, install qrcode with the ``pil`` dependency so
  41. that pillow_ is installed and can be used for generating images::
  42. pip install "qrcode[pil]"
  43. .. _pypng: https://pypi.python.org/pypi/pypng
  44. .. _pillow: https://pypi.python.org/pypi/Pillow
  45. What is a QR Code?
  46. ==================
  47. A Quick Response code is a two-dimensional pictographic code used for its fast
  48. readability and comparatively large storage capacity. The code consists of
  49. black modules arranged in a square pattern on a white background. The
  50. information encoded can be made up of any kind of data (e.g., binary,
  51. alphanumeric, or Kanji symbols)
  52. Usage
  53. =====
  54. From the command line, use the installed ``qr`` script::
  55. qr "Some text" > test.png
  56. Or in Python, use the ``make`` shortcut function:
  57. .. code:: python
  58. import qrcode
  59. img = qrcode.make('Some data here')
  60. type(img) # qrcode.image.pil.PilImage
  61. img.save("some_file.png")
  62. Advanced Usage
  63. --------------
  64. For more control, use the ``QRCode`` class. For example:
  65. .. code:: python
  66. import qrcode
  67. qr = qrcode.QRCode(
  68. version=1,
  69. error_correction=qrcode.constants.ERROR_CORRECT_L,
  70. box_size=10,
  71. border=4,
  72. )
  73. qr.add_data('Some data')
  74. qr.make(fit=True)
  75. img = qr.make_image(fill_color="black", back_color="white")
  76. The ``version`` parameter is an integer from 1 to 40 that controls the size of
  77. the QR Code (the smallest, version 1, is a 21x21 matrix).
  78. Set to ``None`` and use the ``fit`` parameter when making the code to determine
  79. this automatically.
  80. ``fill_color`` and ``back_color`` can change the background and the painting
  81. color of the QR, when using the default image factory. Both parameters accept
  82. RGB color tuples.
  83. .. code:: python
  84. img = qr.make_image(back_color=(255, 195, 235), fill_color=(55, 95, 35))
  85. The ``error_correction`` parameter controls the error correction used for the
  86. QR Code. The following four constants are made available on the ``qrcode``
  87. package:
  88. ``ERROR_CORRECT_L``
  89. About 7% or less errors can be corrected.
  90. ``ERROR_CORRECT_M`` (default)
  91. About 15% or less errors can be corrected.
  92. ``ERROR_CORRECT_Q``
  93. About 25% or less errors can be corrected.
  94. ``ERROR_CORRECT_H``.
  95. About 30% or less errors can be corrected.
  96. The ``box_size`` parameter controls how many pixels each "box" of the QR code
  97. is.
  98. The ``border`` parameter controls how many boxes thick the border should be
  99. (the default is 4, which is the minimum according to the specs).
  100. Other image factories
  101. =====================
  102. You can encode as SVG, or use a new pure Python image processor to encode to
  103. PNG images.
  104. The Python examples below use the ``make`` shortcut. The same ``image_factory``
  105. keyword argument is a valid option for the ``QRCode`` class for more advanced
  106. usage.
  107. SVG
  108. ---
  109. You can create the entire SVG or an SVG fragment. When building an entire SVG
  110. image, you can use the factory that combines as a path (recommended, and
  111. default for the script) or a factory that creates a simple set of rectangles.
  112. From your command line::
  113. qr --factory=svg-path "Some text" > test.svg
  114. qr --factory=svg "Some text" > test.svg
  115. qr --factory=svg-fragment "Some text" > test.svg
  116. Or in Python:
  117. .. code:: python
  118. import qrcode
  119. import qrcode.image.svg
  120. if method == 'basic':
  121. # Simple factory, just a set of rects.
  122. factory = qrcode.image.svg.SvgImage
  123. elif method == 'fragment':
  124. # Fragment factory (also just a set of rects)
  125. factory = qrcode.image.svg.SvgFragmentImage
  126. else:
  127. # Combined path factory, fixes white space that may occur when zooming
  128. factory = qrcode.image.svg.SvgPathImage
  129. img = qrcode.make('Some data here', image_factory=factory)
  130. Two other related factories are available that work the same, but also fill the
  131. background of the SVG with white::
  132. qrcode.image.svg.SvgFillImage
  133. qrcode.image.svg.SvgPathFillImage
  134. The ``QRCode.make_image()`` method forwards additional keyword arguments to the
  135. underlying ElementTree XML library. This helps to fine tune the root element of
  136. the resulting SVG:
  137. .. code:: python
  138. import qrcode
  139. qr = qrcode.QRCode(image_factory=qrcode.image.svg.SvgPathImage)
  140. qr.add_data('Some data')
  141. qr.make(fit=True)
  142. img = qr.make_image(attrib={'class': 'some-css-class'})
  143. You can convert the SVG image into strings using the ``to_string()`` method.
  144. Additional keyword arguments are forwarded to ElementTrees ``tostring()``:
  145. .. code:: python
  146. img.to_string(encoding='unicode')
  147. Pure Python PNG
  148. ---------------
  149. If Pillow is not installed, the default image factory will be a pure Python PNG
  150. encoder that uses `pypng`.
  151. You can use the factory explicitly from your command line::
  152. qr --factory=png "Some text" > test.png
  153. Or in Python:
  154. .. code:: python
  155. import qrcode
  156. from qrcode.image.pure import PyPNGImage
  157. img = qrcode.make('Some data here', image_factory=PyPNGImage)
  158. Styled Image
  159. ------------
  160. Works only with versions_ >=7.2 (SVG styled images require 7.4).
  161. .. _versions: https://github.com/lincolnloop/python-qrcode/blob/master/CHANGES.rst#72-19-july-2021
  162. To apply styles to the QRCode, use the ``StyledPilImage`` or one of the
  163. standard SVG_ image factories. These accept an optional ``module_drawer``
  164. parameter to control the shape of the QR Code.
  165. These QR Codes are not guaranteed to work with all readers, so do some
  166. experimentation and set the error correction to high (especially if embedding
  167. an image).
  168. Other PIL module drawers:
  169. .. image:: doc/module_drawers.png
  170. For SVGs, use ``SvgSquareDrawer``, ``SvgCircleDrawer``,
  171. ``SvgPathSquareDrawer``, or ``SvgPathCircleDrawer``.
  172. These all accept a ``size_ratio`` argument which allows for "gapped" squares or
  173. circles by reducing this less than the default of ``Decimal(1)``.
  174. The ``StyledPilImage`` additionally accepts an optional ``color_mask``
  175. parameter to change the colors of the QR Code, and an optional
  176. ``embedded_image_path`` to embed an image in the center of the code.
  177. Other color masks:
  178. .. image:: doc/color_masks.png
  179. Here is a code example to draw a QR code with rounded corners, radial gradient
  180. and an embedded image:
  181. .. code:: python
  182. import qrcode
  183. from qrcode.image.styledpil import StyledPilImage
  184. from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer
  185. from qrcode.image.styles.colormasks import RadialGradiantColorMask
  186. qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)
  187. qr.add_data('Some data')
  188. img_1 = qr.make_image(image_factory=StyledPilImage, module_drawer=RoundedModuleDrawer())
  189. img_2 = qr.make_image(image_factory=StyledPilImage, color_mask=RadialGradiantColorMask())
  190. img_3 = qr.make_image(image_factory=StyledPilImage, embedded_image_path="/path/to/image.png")
  191. Examples
  192. ========
  193. Get the text content from `print_ascii`:
  194. .. code:: python
  195. import io
  196. import qrcode
  197. qr = qrcode.QRCode()
  198. qr.add_data("Some text")
  199. f = io.StringIO()
  200. qr.print_ascii(out=f)
  201. f.seek(0)
  202. print(f.read())
  203. The `add_data` method will append data to the current QR object. To add new data by replacing previous content in the same object, first use clear method:
  204. .. code:: python
  205. import qrcode
  206. qr = qrcode.QRCode()
  207. qr.add_data('Some data')
  208. img = qr.make_image()
  209. qr.clear()
  210. qr.add_data('New data')
  211. other_img = qr.make_image()
  212. Pipe ascii output to text file in command line::
  213. qr --ascii "Some data" > "test.txt"
  214. cat test.txt
  215. Alternative to piping output to file to avoid PowerShell issues::
  216. # qr "Some data" > test.png
  217. qr --output=test.png "Some data"
  218. ==========
  219. Change log
  220. ==========
  221. 8.2 (01 May 2025)
  222. =================
  223. - Optimize QRColorMask apply_mask method for enhanced performance
  224. - Fix typos on StyledPilImage embeded_* parameters.
  225. The old parameters with the typos are still accepted
  226. for backward compatibility.
  227. 8.1 (02 April 2025)
  228. ====================
  229. - Added support for Python 3.13.
  230. 8.0 (27 September 2024)
  231. ========================
  232. - Added support for Python 3.11 and 3.12.
  233. - Drop support for Python <=3.8.
  234. - Change local development setup to use Poetry_.
  235. - Testsuite and code quality checks are done through Github Actions.
  236. - Code quality and formatting utilises ruff_.
  237. - Removed ``typing_extensions`` as a dependency, as it's no longer required
  238. with having Python 3.9+ as a requirement.
  239. having Python 3.9+ as a requirement.
  240. - Only allow high error correction rate (`qrcode.ERROR_CORRECT_H`)
  241. when generating
  242. QR codes with embedded images to ensure content is readable
  243. .. _Poetry: https://python-poetry.org
  244. .. _ruff: https://astral.sh/ruff
  245. 7.4.2 (6 February 2023)
  246. =======================
  247. - Allow ``pypng`` factory to allow for saving to a string (like
  248. ``qr.save("some_file.png")``) in addition to file-like objects.
  249. 7.4.1 (3 February 2023)
  250. =======================
  251. - Fix bad over-optimization in v7.4 that broke large QR codes. Thanks to
  252. mattiasj-axis!
  253. 7.4 (1 February 2023)
  254. =====================
  255. - Restructure the factory drawers, allowing different shapes in SVG image
  256. factories as well.
  257. - Add a ``--factory-drawer`` option to the ``qr`` console script.
  258. - Optimize the output for the ``SVGPathImage`` factory (more than 30% reduction
  259. in file sizes).
  260. - Add a ``pypng`` image factory as a pure Python PNG solution. If ``pillow`` is
  261. *not* installed, then this becomes the default factory.
  262. - The ``pymaging`` image factory has been removed, but its factory shortcut and
  263. the actual PymagingImage factory class now just link to the PyPNGImage
  264. factory.
  265. 7.3.1 (1 October 2021)
  266. ======================
  267. - Improvements for embedded image.
  268. 7.3 (19 August 2021)
  269. ====================
  270. - Skip color mask if QR is black and white
  271. 7.2 (19 July 2021)
  272. ==================
  273. - Add Styled PIL image factory, allowing different color masks and shapes in QR codes
  274. - Small performance inprovement
  275. - Add check for border size parameter
  276. 7.1 (1 July 2021)
  277. =================
  278. - Add --ascii parameter to command line interface allowing to output ascii when stdout is piped
  279. - Add --output parameter to command line interface to specify output file
  280. - Accept RGB tuples in fill_color and back_color
  281. - Add to_string method to SVG images
  282. - Replace inline styles with SVG attributes to avoid CSP issues
  283. - Add Python3.10 to supported versions
  284. 7.0 (29 June 2021)
  285. ==================
  286. - Drop Python < 3.6 support.
  287. 6.1 (14 January 2019)
  288. =====================
  289. - Fix short chunks of data not being optimized to the correct mode.
  290. - Tests fixed for Python 3
  291. 6.0 (23 March 2018)
  292. ===================
  293. - Fix optimize length being ignored in ``QRCode.add_data``.
  294. - Better calculation of the best mask pattern and related optimizations. Big
  295. thanks to cryptogun!
  296. 5.3 (18 May 2016)
  297. =================
  298. * Fix incomplete block table for QR version 15. Thanks Rodrigo Queiro for the
  299. report and Jacob Welsh for the investigation and fix.
  300. * Avoid unnecessary dependency for non MS platforms, thanks to Noah Vesely.
  301. * Make ``BaseImage.get_image()`` actually work.
  302. 5.2 (25 Jan 2016)
  303. =================
  304. * Add ``--error-correction`` option to qr script.
  305. * Fix script piping to stdout in Python 3 and reading non-UTF-8 characters in
  306. Python 3.
  307. * Fix script piping in Windows.
  308. * Add some useful behind-the-curtain methods for tinkerers.
  309. * Fix terminal output when using Python 2.6
  310. * Fix terminal output to display correctly on MS command line.
  311. 5.2.1
  312. -----
  313. * Small fix to terminal output in Python 3 (and fix tests)
  314. 5.2.2
  315. -----
  316. * Revert some terminal changes from 5.2 that broke Python 3's real life tty
  317. code generation and introduce a better way from Jacob Welsh.
  318. 5.1 (22 Oct 2014)
  319. =================
  320. * Make ``qr`` script work in Windows. Thanks Ionel Cristian Mărieș
  321. * Fixed print_ascii function in Python 3.
  322. * Out-of-bounds code version numbers are handled more consistently with a
  323. ValueError.
  324. * Much better test coverage (now only officially supporting Python 2.6+)
  325. 5.0 (17 Jun 2014)
  326. =================
  327. * Speed optimizations.
  328. * Change the output when using the ``qr`` script to use ASCII rather than
  329. just colors, better using the terminal real estate.
  330. * Fix a bug in passing bytecode data directly when in Python 3.
  331. * Substation speed optimizations to best-fit algorithm (thanks Jacob Welsh!).
  332. * Introduce a ``print_ascii`` method and use it as the default for the ``qr``
  333. script rather than ``print_tty``.
  334. 5.0.1
  335. -----
  336. * Update version numbers correctly.
  337. 4.0 (4 Sep 2013)
  338. ================
  339. * Made qrcode work on Python 2.4 - Thanks tcely.
  340. Note: officially, qrcode only supports 2.5+.
  341. * Support pure-python PNG generation (via pymaging) for Python 2.6+ -- thanks
  342. Adam Wisniewski!
  343. * SVG image generation now supports alternate sizing (the default box size of
  344. 10 == 1mm per rectangle).
  345. * SVG path image generation allows cleaner SVG output by combining all QR rects
  346. into a single path. Thank you, Viktor Stískala.
  347. * Added some extra simple SVG factories that fill the background white.
  348. 4.0.1
  349. -----
  350. * Fix the pymaging backend not able to save the image to a buffer. Thanks ilj!
  351. 4.0.2
  352. -----
  353. * Fix incorrect regex causing a comma to be considered part of the alphanumeric
  354. set.
  355. * Switch to using setuptools for setup.py.
  356. 4.0.3
  357. -----
  358. * Fix bad QR code generation due to the regex comma fix in version 4.0.2.
  359. 4.0.4
  360. -----
  361. * Bad version number for previous hotfix release.
  362. 3.1 (12 Aug 2013)
  363. =================
  364. * Important fixes for incorrect matches of the alphanumeric encoding mode.
  365. Previously, the pattern would match if a single line was alphanumeric only
  366. (even if others wern't). Also, the two characters ``{`` and ``}`` had snuck
  367. in as valid characters. Thanks to Eran Tromer for the report and fix.
  368. * Optimized chunking -- if the parts of the data stream can be encoded more
  369. efficiently, the data will be split into chunks of the most efficient modes.
  370. 3.1.1
  371. -----
  372. * Update change log to contain version 3.1 changes. :P
  373. * Give the ``qr`` script an ``--optimize`` argument to control the chunk
  374. optimization setting.
  375. 3.0 (25 Jun 2013)
  376. =================
  377. * Python 3 support.
  378. * Add QRCode.get_matrix, an easy way to get the matrix array of a QR code
  379. including the border. Thanks Hugh Rawlinson.
  380. * Add in a workaround so that Python 2.6 users can use SVG generation (they
  381. must install ``lxml``).
  382. * Some initial tests! And tox support (``pip install tox``) for testing across
  383. Python platforms.
  384. 2.7 (5 Mar 2013)
  385. ================
  386. * Fix incorrect termination padding.
  387. 2.6 (2 Apr 2013)
  388. ================
  389. * Fix the first four columns incorrectly shifted by one. Thanks to Josep
  390. Gómez-Suay for the report and fix.
  391. * Fix strings within 4 bits of the QR version limit being incorrectly
  392. terminated. Thanks to zhjie231 for the report.
  393. 2.5 (12 Mar 2013)
  394. =================
  395. * The PilImage wrapper is more transparent - you can use any methods or
  396. attributes available to the underlying PIL Image instance.
  397. * Fixed the first column of the QR Code coming up empty! Thanks to BecoKo.
  398. 2.5.1
  399. -----
  400. * Fix installation error on Windows.
  401. 2.4 (23 Apr 2012)
  402. =================
  403. * Use a pluggable backend system for generating images, thanks to Branko Čibej!
  404. Comes with PIL and SVG backends built in.
  405. 2.4.1
  406. -----
  407. * Fix a packaging issue
  408. 2.4.2
  409. -----
  410. * Added a ``show`` method to the PIL image wrapper so the ``run_example``
  411. function actually works.
  412. 2.3 (29 Jan 2012)
  413. =================
  414. * When adding data, auto-select the more efficient encoding methods for numbers
  415. and alphanumeric data (KANJI still not supported).
  416. 2.3.1
  417. -----
  418. * Encode unicode to utf-8 bytestrings when adding data to a QRCode.
  419. 2.2 (18 Jan 2012)
  420. =================
  421. * Fixed tty output to work on both white and black backgrounds.
  422. * Added `border` parameter to allow customizing of the number of boxes used to
  423. create the border of the QR code
  424. 2.1 (17 Jan 2012)
  425. =================
  426. * Added a ``qr`` script which can be used to output a qr code to the tty using
  427. background colors, or to a file via a pipe.