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")
References
- Based on go-pix repository
- Regulamento PIX
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python_brcode-0.2.0.tar.gz
.
File metadata
- Download URL: python_brcode-0.2.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.12 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2bcfa918cd6d10980c7afc5b102c5a4cb997c598c596aaa30d030ea667763d4 |
|
MD5 | e7937e331796c7876858069c86a1cfc4 |
|
BLAKE2b-256 | f8406301e43dd9d60641958fc670928113a42e8604d431a68340d3f75a1d04f8 |
File details
Details for the file python_brcode-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: python_brcode-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.12 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 390ea87a4ed1701bdb13a0a01ed85dce078befc0295058618c90b29ff3466d86 |
|
MD5 | ae26f56ad1016a2262e2cf303a178759 |
|
BLAKE2b-256 | 3493692998e64ebb45f5c14d23ce760de0704e1ee3437631afd9a67dfc19ac4a |