Skip to main content

Generates static BR Codes that could be used for PIX payments using simple value copy and paste or generating QR Codes.

Project description

python-brcode

Generates static BR Codes that could be used for PIX payments using simple value copy and paste or generating QR Codes.

Notes:

Although this initial version is functional, it's yet very simple. We're not performing proper data validation and the user is responsible for providing valid PIX Keys.

For example:

  • email addresses should be valid
  • CPF and CNPJ should contain only digits
  • phone numbers should follow international patterns and begin with a + sign
  • the amount should not be a negative number

Always check the resulting codes or code generation routines before exposing them in production environments.

Tested with Nubank, Inter, Banco do Brasil, and BTG banks.

Installing

pip install python-brcode

Usage

Including all parameters

from decimal import Decimal
from brcode import BRCode

brcode = BRCode(
    name="Victor Torres",
    key="vpaivatorres@gmail.com",
    city="Natal",
    amount=Decimal(10.00),                    # optional
    description="Biblioteca python-brcode",   # optional
    transaction_id="***",                     # optional
)
assert str(brcode) == "00020126720014br.gov.bcb.pix0122vpaivatorres@gmail.com0224Biblioteca python-brcode520400005303986540510.005802BR5913Victor Torres6005Natal62070503***6304C1FA"

Omitting optional parameters

from decimal import Decimal
from brcode import BRCode

brcode = BRCode(
    name="Victor Torres",
    key="vpaivatorres@gmail.com",
    city="Natal",
)
assert str(brcode) == "00020126480014br.gov.bcb.pix0122vpaivatorres@gmail.com02005204000053039865802BR5913Victor Torres6005Natal62070503***6304A5EE"

Generating QR Code

This library does not handle QR Code generation.

To generate a QR Code that could be scanned by most bank apps, you should use a third-party library of your choice. The QR Code should be generated using the BR Code as its text.

Example

Using the library python-qrcode:

Install the library:

pip install qrcode

Generate a new BR Code and then a QR Code out of it:

from decimal import Decimal
from brcode import BRCode
import qrcode

brcode = (
    name="Victor Torres",
    key="vpaivatorres@gmail.com",
    city="Natal",
)

img = qrcode.make(str(brcode))
img.save("qrcode.png")

QR Code

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_brcode-0.2.0.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

python_brcode-0.2.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page