Archived, see #23
ZATCA (Fatoora) QR-Code Implementation
An unofficial package help developers to implement ZATCA (Fatoora) QR code easily which required for e-invoicing
Table of Contents
Requirements
- Python >= 3.8
Installation
PyPi
$ pip3 install fatoora
GitHub
$ git clone https://github.com/TheAwiteb/fatoora/
$ cd fatoora
$ python3 setup.py install
Usage
Variables
Here the features of the variables of the Fatoora class will be explained
- Seller’s name.
- Seller’ tax number, which is the VAT registration number.
- Invoice date, which is the timestamp of the electronic invoice.
- Invoice total amount, which is the electronic invoice total with VAT.
- Tax amount, which is the VAT total.
| Name | Feature | How will it be in the tag | How will it be when you call |
|---|---|---|---|
| seller_name | saved directly without processing | No changes will be made to it | No changes will be made to it |
| tax_number | receives the tax number as a text and a number as well, and save it as string | number as string | number as string |
| invoice_date | receives the date as timestamp or datetime object, or string ISO 8601 Zulu format | string of date as ISO 8601 Zulu format | datetime object |
| total_amount | receives the tax number as a text and a number as well | It is of type str as float | It is of type float |
| tax_amount | same total_amount + Accept None value to get VAT auto from total_amount |
same total_amount | same total_amount |
Note: The
tax_amountis rounded to the nearest two decimal places, if it is greater than that ( iftax_amount==15its will be15.0)
Note: If you set
tax_amounttoNonethevat_rates==0.15you can change it inFatooraobject
Generate Base64
from fatoora import Fatoora
fatoora_obj = Fatoora(
seller_name="Awiteb",
tax_number=1234567891, # or "1234567891"
invoice_date=1635872693.3186214, # timestamp or datetime object, or string ISO 8601 Zulu format
total_amount=100, # or 100.0, 100.00, "100.0", "100.00"
tax_amount=15, # or 15.0, 15.00, "15.0", "15.00"
)
print(fatoora_obj.base64)
# AQZBd2l0ZWICCjEyMzQ1Njc4OTEDFDIwMjEtMTEtMDJUMTc6MDQ6NTNaBAUxMDAuMAUEMTUuMA==
Render A QR Code Image
You can render the tags as QR code image easily
The content is the base64 of the invoice
from fatoora import Fatoora
fatoora_obj = Fatoora(
seller_name="Awiteb",
tax_number=1234567891,
invoice_date=1635872693.3186214,
total_amount=100,
tax_amount=15,
)
fatoora_obj.qrcode("qr_code.png")
The content is the invoice url
from fatoora import Fatoora
fatoora_obj = Fatoora(
seller_name="Awiteb",
tax_number=1234567891,
invoice_date=1635872693.3186214,
total_amount=100,
tax_amount=15,
qrcode_url="https://example.com"
)
fatoora_obj.qrcode("qr_code_with_url.png")
Generate hash (sha256)
from fatoora import Fatoora
fatoora_obj = Fatoora(
seller_name="Awiteb",
tax_number=1234567891,
invoice_date=1635872693.3186214,
total_amount=100,
tax_amount=15,
)
print(fatoora_obj.hash)
# 20b8ddb6ed9cb98be3d8535a1f4f28e35888842c1b0aed0e90c3e7fb51080dd9
Read qr code
from fatoora import Fatoora
fatoora_obj = Fatoora(
seller_name="Awiteb",
tax_number=1234567891,
invoice_date=1635872693.3186214,
total_amount=100,
tax_amount=15,
)
fatoora_obj.qrcode("qr_code.png")
print(Fatoora.read_qrcode("qr_code.png", dct=True))
# {'seller_name': 'Awiteb', 'tax_number': '1234567891', 'invoice_date': '2021-11-02T17:04:53Z', 'total_amount': '100.0', 'tax_amount': '15.0'}
print(Fatoora.read_qrcode("qr_code.png", dct=False))
# AQZBd2l0ZWICCjEyMzQ1Njc4OTEDFDIwMjEtMTEtMDJUMTc6MDQ6NTNaBAUxMDAuMAUEMTUuMA==
Extra Methods
from fatoora import Fatoora
fatoora_obj = Fatoora(
seller_name="Awiteb",
tax_number=1234567891,
invoice_date=1635872693.3186214,
total_amount=100,
tax_amount=15,
)
print(fatoora_obj.invoice_date.year)
# 2021
print(fatoora_obj.invoice_date.isoformat())
# 2021-11-02T17:04:53
print(fatoora_obj.invoice_date.timestamp())
# 1635861893.0
print(fatoora_obj.json())
# '{"seller_name": "Awiteb", "tax_number": "1234567891", "invoice_date": "2021-11-02T17:04:53Z", "total_amount": "100.0", "tax_amount": "15.0"}'
print(fatoora_obj.dict())
# {'seller_name': 'Awiteb', 'tax_number': '1234567891', 'invoice_date': '2021-11-02T17:04:53Z', 'total_amount': '100.0', 'tax_amount': '15.0'}
# Use class to get fatoora details by base64
print(Fatoora.base2dict(fatoora_obj.base64))
# {'seller_name': 'Awiteb', 'tax_number': '1234567891', 'invoice_date': '2021-11-02T17:04:53Z', 'total_amount': '100.0', 'tax_amount': '15.0'}
Extra Functions
import fatoora
print(fatoora.is_valid_iso8601_zulu_format("invalid date"))
# False
print(fatoora.is_valid_iso8601_zulu_format("2021-11-02T17:04:53Z"))
# True
Discussions
Question, feature request, discuss about fatoora here
Issues
You can report a bug from here
Security
If you discover any security related issues.
Donating
| Currency | Address |
|---|---|
| Binance BNB BEP20 | 0xD89c146B03B72191be91064D313610981dCAF6d4 |
| USD Coin USDC BEP20 | 0xD89c146B03B72191be91064D313610981dCAF6d4 |
| Bitcoin BTC | bc1q0ltmqmsc4qs740ssyf9k9jq99nwxtqu8aupmdj |
| Bitcoin Cash BCH | qrpm6zyte3d4z2u9r24l04m3havc2wd9vgqlz8sjgr |
License
The MIT License (MIT). Please see License File for more information.
Metadata
Release files for fatoora 3.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fatoora-3.0.3.tar.gz | 7.7 kB | Without provenance | Details for fatoora-3.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fatoora-3.0.3-py3-none-any.whl | Python 3 | none | any | Details for fatoora-3.0.3-py3-none-any.whl |
Total release size: 16.2 kB
Release files / fatoora-3.0.3.tar.gz
| Download URL | fatoora-3.0.3.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8146bdbbf2b0f26189984e6a8e0380ec8dceb46011fe24cb302b167f7e3bcf49
|
|
BLAKE2b-256 checksum How to use checksums |
d371caca708cd50b06a0566edceaf5bf1cd78da8665401a30a5314384b8306ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.0
|
Release files / fatoora-3.0.3-py3-none-any.whl
| Download URL | fatoora-3.0.3-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3394066f1bfcec5bfcdf92db0cf6ba1bb7b831f5db828e292fd6d8a026539f93
|
|
BLAKE2b-256 checksum How to use checksums |
e9377cdc3c2dfee4d4bdeefb88375127e59bca47924a84ed6d12a06723e7a083
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.0
|
Security for fatoora 3.0.3
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.