Skip to main content

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

Metadata

Release files for python-brcode 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-brcode 0.2.0
File Size Uploaded Provenance Actions
python_brcode-0.2.0.tar.gz 2.9 kB Without provenance Details for python_brcode-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-brcode 0.2.0
File Interpreter ABI Platform Actions
python_brcode-0.2.0-py3-none-any.whl Python 3 none any Details for python_brcode-0.2.0-py3-none-any.whl

Total release size: 6.3 kB

Release files / python_brcode-0.2.0.tar.gz

Download URL python_brcode-0.2.0.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e2bcfa918cd6d10980c7afc5b102c5a4cb997c598c596aaa30d030ea667763d4
BLAKE2b-256 checksum
How to use checksums
f8406301e43dd9d60641958fc670928113a42e8604d431a68340d3f75a1d04f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.12 Darwin/22.3.0

Release files / python_brcode-0.2.0-py3-none-any.whl

Download URL python_brcode-0.2.0-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
390ea87a4ed1701bdb13a0a01ed85dce078befc0295058618c90b29ff3466d86
BLAKE2b-256 checksum
How to use checksums
3493692998e64ebb45f5c14d23ce760de0704e1ee3437631afd9a67dfc19ac4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.12 Darwin/22.3.0

Security for python-brcode 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page