{"id":13595510,"url":"https://github.com/lincolnloop/python-qrcode","last_synced_at":"2025-05-12T03:36:54.533Z","repository":{"id":1823323,"uuid":"2747590","full_name":"lincolnloop/python-qrcode","owner":"lincolnloop","description":"Python QR Code image generator","archived":false,"fork":false,"pushed_at":"2025-04-02T14:22:09.000Z","size":905,"stargazers_count":4603,"open_issues_count":95,"forks_count":702,"subscribers_count":121,"default_branch":"main","last_synced_at":"2025-05-01T13:49:14.924Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/qrcode","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"apiguy/flask-classy","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lincolnloop.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2011-11-10T09:36:22.000Z","updated_at":"2025-05-01T12:36:45.000Z","dependencies_parsed_at":"2023-07-07T14:16:16.966Z","dependency_job_id":"c508f73b-b7ea-4aad-95d2-d3b6de2b75a2","html_url":"https://github.com/lincolnloop/python-qrcode","commit_stats":{"total_commits":334,"total_committers":57,"mean_commits":5.859649122807017,"dds":0.4640718562874252,"last_synced_commit":"d44a409c21b91409d25c35eee94bcacea5ffa878"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lincolnloop%2Fpython-qrcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lincolnloop%2Fpython-qrcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lincolnloop%2Fpython-qrcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lincolnloop%2Fpython-qrcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lincolnloop","download_url":"https://codeload.github.com/lincolnloop/python-qrcode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253668896,"owners_count":21945054,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T16:01:51.452Z","updated_at":"2025-05-12T03:36:54.523Z","avatar_url":"https://github.com/lincolnloop.png","language":"Python","readme":"=============================\nPure python QR Code generator\n=============================\n\nGenerate QR codes.\n\nA standard install uses pypng_ to generate PNG files and can also render QR\ncodes directly to the console. A standard install is just::\n\n    pip install qrcode\n\nFor more image functionality, install qrcode with the ``pil`` dependency so\nthat pillow_ is installed and can be used for generating images::\n\n    pip install \"qrcode[pil]\"\n\n.. _pypng: https://pypi.python.org/pypi/pypng\n.. _pillow: https://pypi.python.org/pypi/Pillow\n\n\nWhat is a QR Code?\n==================\n\nA Quick Response code is a two-dimensional pictographic code used for its fast\nreadability and comparatively large storage capacity. The code consists of\nblack modules arranged in a square pattern on a white background. The\ninformation encoded can be made up of any kind of data (e.g., binary,\nalphanumeric, or Kanji symbols)\n\nUsage\n=====\n\nFrom the command line, use the installed ``qr`` script::\n\n    qr \"Some text\" \u003e test.png\n\nOr in Python, use the ``make`` shortcut function:\n\n.. code:: python\n\n    import qrcode\n    img = qrcode.make('Some data here')\n    type(img)  # qrcode.image.pil.PilImage\n    img.save(\"some_file.png\")\n\nAdvanced Usage\n--------------\n\nFor more control, use the ``QRCode`` class. For example:\n\n.. code:: python\n\n    import qrcode\n    qr = qrcode.QRCode(\n        version=1,\n        error_correction=qrcode.constants.ERROR_CORRECT_L,\n        box_size=10,\n        border=4,\n    )\n    qr.add_data('Some data')\n    qr.make(fit=True)\n\n    img = qr.make_image(fill_color=\"black\", back_color=\"white\")\n\nThe ``version`` parameter is an integer from 1 to 40 that controls the size of\nthe QR Code (the smallest, version 1, is a 21x21 matrix).\nSet to ``None`` and use the ``fit`` parameter when making the code to determine\nthis automatically.\n\n``fill_color`` and ``back_color`` can change the background and the painting\ncolor of the QR, when using the default image factory. Both parameters accept\nRGB color tuples.\n\n.. code:: python\n\n\n    img = qr.make_image(back_color=(255, 195, 235), fill_color=(55, 95, 35))\n\nThe ``error_correction`` parameter controls the error correction used for the\nQR Code. The following four constants are made available on the ``qrcode``\npackage:\n\n``ERROR_CORRECT_L``\n    About 7% or less errors can be corrected.\n``ERROR_CORRECT_M`` (default)\n    About 15% or less errors can be corrected.\n``ERROR_CORRECT_Q``\n    About 25% or less errors can be corrected.\n``ERROR_CORRECT_H``.\n    About 30% or less errors can be corrected.\n\nThe ``box_size`` parameter controls how many pixels each \"box\" of the QR code\nis.\n\nThe ``border`` parameter controls how many boxes thick the border should be\n(the default is 4, which is the minimum according to the specs).\n\nOther image factories\n=====================\n\nYou can encode as SVG, or use a new pure Python image processor to encode to\nPNG images.\n\nThe Python examples below use the ``make`` shortcut. The same ``image_factory``\nkeyword argument is a valid option for the ``QRCode`` class for more advanced\nusage.\n\nSVG\n---\n\nYou can create the entire SVG or an SVG fragment. When building an entire SVG\nimage, you can use the factory that combines as a path (recommended, and\ndefault for the script) or a factory that creates a simple set of rectangles.\n\nFrom your command line::\n\n    qr --factory=svg-path \"Some text\" \u003e test.svg\n    qr --factory=svg \"Some text\" \u003e test.svg\n    qr --factory=svg-fragment \"Some text\" \u003e test.svg\n\nOr in Python:\n\n.. code:: python\n\n    import qrcode\n    import qrcode.image.svg\n\n    if method == 'basic':\n        # Simple factory, just a set of rects.\n        factory = qrcode.image.svg.SvgImage\n    elif method == 'fragment':\n        # Fragment factory (also just a set of rects)\n        factory = qrcode.image.svg.SvgFragmentImage\n    else:\n        # Combined path factory, fixes white space that may occur when zooming\n        factory = qrcode.image.svg.SvgPathImage\n\n    img = qrcode.make('Some data here', image_factory=factory)\n\nTwo other related factories are available that work the same, but also fill the\nbackground of the SVG with white::\n\n    qrcode.image.svg.SvgFillImage\n    qrcode.image.svg.SvgPathFillImage\n\nThe ``QRCode.make_image()`` method forwards additional keyword arguments to the\nunderlying ElementTree XML library. This helps to fine tune the root element of\nthe resulting SVG:\n\n.. code:: python\n\n    import qrcode\n    qr = qrcode.QRCode(image_factory=qrcode.image.svg.SvgPathImage)\n    qr.add_data('Some data')\n    qr.make(fit=True)\n\n    img = qr.make_image(attrib={'class': 'some-css-class'})\n\nYou can convert the SVG image into strings using the ``to_string()`` method.\nAdditional keyword arguments are forwarded to ElementTrees ``tostring()``:\n\n.. code:: python\n\n    img.to_string(encoding='unicode')\n\n\nPure Python PNG\n---------------\n\nIf Pillow is not installed, the default image factory will be a pure Python PNG\nencoder that uses `pypng`.\n\nYou can use the factory explicitly from your command line::\n\n    qr --factory=png \"Some text\" \u003e test.png\n\nOr in Python:\n\n.. code:: python\n\n    import qrcode\n    from qrcode.image.pure import PyPNGImage\n    img = qrcode.make('Some data here', image_factory=PyPNGImage)\n\n\nStyled Image\n------------\n\nWorks only with versions_ \u003e=7.2 (SVG styled images require 7.4).\n\n.. _versions: https://github.com/lincolnloop/python-qrcode/blob/master/CHANGES.rst#72-19-july-2021\n\nTo apply styles to the QRCode, use the ``StyledPilImage`` or one of the\nstandard SVG_ image factories. These accept an optional ``module_drawer``\nparameter to control the shape of the QR Code.\n\nThese QR Codes are not guaranteed to work with all readers, so do some\nexperimentation and set the error correction to high (especially if embedding\nan image).\n\nOther PIL module drawers:\n\n    .. image:: doc/module_drawers.png\n\nFor SVGs, use ``SvgSquareDrawer``, ``SvgCircleDrawer``,\n``SvgPathSquareDrawer``, or ``SvgPathCircleDrawer``.\n\nThese all accept a ``size_ratio`` argument which allows for \"gapped\" squares or\ncircles by reducing this less than the default of ``Decimal(1)``.\n\n\nThe ``StyledPilImage`` additionally accepts an optional ``color_mask``\nparameter to change the colors of the QR Code, and an optional\n``embedded_image_path`` to embed an image in the center of the code.\n\nOther color masks:\n\n    .. image:: doc/color_masks.png\n\nHere is a code example to draw a QR code with rounded corners, radial gradient\nand an embedded image:\n\n.. code:: python\n\n    import qrcode\n    from qrcode.image.styledpil import StyledPilImage\n    from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer\n    from qrcode.image.styles.colormasks import RadialGradiantColorMask\n\n    qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)\n    qr.add_data('Some data')\n\n    img_1 = qr.make_image(image_factory=StyledPilImage, module_drawer=RoundedModuleDrawer())\n    img_2 = qr.make_image(image_factory=StyledPilImage, color_mask=RadialGradiantColorMask())\n    img_3 = qr.make_image(image_factory=StyledPilImage, embedded_image_path=\"/path/to/image.png\")\n\nExamples\n========\n\nGet the text content from `print_ascii`:\n\n.. code:: python\n\n    import io\n    import qrcode\n    qr = qrcode.QRCode()\n    qr.add_data(\"Some text\")\n    f = io.StringIO()\n    qr.print_ascii(out=f)\n    f.seek(0)\n    print(f.read())\n\nThe `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:\n\n.. code:: python\n\n    import qrcode\n    qr = qrcode.QRCode()\n    qr.add_data('Some data')\n    img = qr.make_image()\n    qr.clear()\n    qr.add_data('New data')\n    other_img = qr.make_image()\n\nPipe ascii output to text file in command line::\n\n    qr --ascii \"Some data\" \u003e \"test.txt\"\n    cat test.txt\n\nAlternative to piping output to file to avoid PowerShell issues::\n\n    # qr \"Some data\" \u003e test.png\n    qr --output=test.png \"Some data\"\n","funding_links":[],"categories":["Imagery","Image Processing","资源列表","Python","图像处理","Image Processing [🔝](#readme)","Data Processing","Awesome Python","Uncategorized"],"sub_categories":["图像处理","Image Processing","Uncategorized","Drone Frames"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flincolnloop%2Fpython-qrcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flincolnloop%2Fpython-qrcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flincolnloop%2Fpython-qrcode/lists"}