Python library for generating Brazilian auxiliary fiscal documents in PDF from XML documents.
Project description
Brazil Fiscal Report
Python library for generating Brazilian auxiliary fiscal documents in PDF from XML documents.
Supported Documents 📄
- DANFE - Documento Auxiliar da Nota Fiscal Eletrônica (NF-e)
- DACCe - Documento Auxiliar da Carta de Correção Eletrônica (CC-e )
Beta Stage Notice 🚧
This library is currently in the beta stage of development. While it has many of the intended features implemented, it is still undergoing testing and improvements. Users should note that during this phase, functionality may change and some instability may occur. We welcome feedback on any issues or suggestions for enhancements. Use in production environments should be approached with caution.
Dependencies 🛠️
- FPDF2 - PDF creation library for Python
- phonenumbers
- python-barcode
To install 🔧
pip install brazilfiscalreport
Usage examples 🚀
DANFE
from brazilfiscalreport.danfe import Danfe
# Path to the XML file
xml_file_path = 'nfe.xml'
# Load XML Content
with open(xml_file_path, "r", encoding="utf8") as file:
xml_content = file.read()
# Instantiate the DANFE object with the loaded XML content
danfe = Danfe(xml=xml_content)
# Save the generated PDF to a file
danfe.output('danfe.pdf')
DACCe
from brazilfiscalreport.dacce import DaCCe
# Path to the XML file
xml_file_path = 'cce.xml'
# Load XML Content
with open(xml_file_path, "r", encoding="utf8") as file:
xml_content = file.read()
# Instantiate the CC-e PDF object with the loaded XML content
cce = DaCCe(xml=xml_content)
# Save the generated PDF to a file
cce.output('cce.pdf')
Samples 📝
Some sample PDFs generated by our unit tests are available for viewing in the tests/generated directory.
Customizing DANFE 🎨
This section describes how to customize the PDF output of the DANFE using the DanfeConfig
class. You can adjust various settings such as margins, fonts, and tax configurations according to your needs.
Configuration Options ⚙️
Here is a breakdown of all the configuration options available in DanfeConfig
:
-
Logo
- Type:
str
,BytesIO
, orbytes
- Description: Path to the logo file or binary image data to be included in the PDF. You can use a file path string or pass image data directly.
- Example:
config.logo = "path/to/logo.jpg" # Using a file path
- Default: No logo.
- Type:
-
Margins
- Type:
Margins
- Fields:
top
,right
,bottom
,left
(all of typeNumber
) - Description: Sets the page margins for the PDF document.
- Example:
config.margins = Margins(top=5, right=5, bottom=5, left=5)
- Default: top, right, bottom and left is 2 mm.
- Type:
-
Receipt Position
- Type:
ReceiptPosition
(Enum) - Values:
TOP
,BOTTOM
,LEFT
- Description: Position of the receipt section in the DANFE.
- Example:
config.receipt_pos = ReceiptPosition.BOTTOM
- Default:
TOP
when portrait,LEFT
when landscape orientation. - Note: In landscape orientation, the receipt position is far left; customization is not permitted.
- Type:
-
Decimal Configuration
- Type:
DecimalConfig
- Fields:
price_precision
,quantity_precision
(bothint
) - Description: Defines the number of decimal places for prices and quantities.
- Example:
config.decimal_config = DecimalConfig(price_precision=2, quantity_precision=3)
- Default: 4
- Type:
-
Tax Configuration
- Type:
TaxConfiguration
(Enum) - Values:
STANDARD_ICMS_IPI
,ICMS_ST_ONLY
,WITHOUT_IPI
- Description: Specifies the tax fields to be displayed.
- Example:
config.tax_configuration = TaxConfiguration.WITHOUT_IPI
- Default:
STANDARD_ICMS_IPI
- WARNING: This feature is not yet implemented.
- Type:
-
Invoice Display
- Type:
InvoiceDisplay
(Enum) - Values:
DUPLICATES_ONLY
,FULL_DETAILS
- Description: Controls the detail level in the invoice section of the DANFE.
- Example::
config.invoice_display = InvoiceDisplay.DUPLICATES_ONLY
- Default:
FULL_DETAILS
- Type:
-
Font Type
- Type:
FontType
(Enum) - Values:
COURIER
,TIMES
- Description: Font style used throughout the PDF document.
- Example::
config.font_type = FontType.COURIER
- Default:
TIMES
- Type:
-
Display PIS COFINS
- Type:
Bool
- Values:
True
,False
- Description: Displays PIS and COFINS taxes in the DANFE totals.
- Example::
config.display_pis_cofins = True
- Default:
False
- Type:
Usage Example with Customization
Here’s how to set up a DanfeConfig
object with a full set of customizations::
from brazilfiscalreport.danfe import (
Danfe,
DanfeConfig,
DecimalConfig,
FontType,
InvoiceDisplay,
Margins,
ReceiptPosition,
TaxConfiguration,
)
# Path to the XML file
xml_file_path = 'nfe.xml'
# Load XML Content
with open(xml_file_path, "r", encoding="utf8") as file:
xml_content = file.read()
# Create a configuration instance
config = DanfeConfig(
logo='path/to/logo.png',
margins=Margins(top=10, right=10, bottom=10, left=10),
receipt_pos=ReceiptPosition.BOTTOM,
decimal_config=DecimalConfig(price_precision=2, quantity_precision=2),
tax_configuration=TaxConfiguration.ICMS_ST,
invoice_display=InvoiceDisplay.FULL_DETAILS,
font_type=FontType.TIMES
)
# Use this config when creating a Danfe instance
danfe = Danfe(xml_content, config=config)
danfe.output('output_danfe.pdf')
Credits 🙌
This is a fork of the nfe_utils project, originally created by Edson Bernardino.
Maintainer 🛠️
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 brazilfiscalreport-0.4.1.tar.gz
.
File metadata
- Download URL: brazilfiscalreport-0.4.1.tar.gz
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0468f5e994eb6b57a16a97512b75165ce8dce41e90565ad21bf6f7ed5e2ee2d3 |
|
MD5 | 395c32c9af83b012d7e0b9d5abab2af0 |
|
BLAKE2b-256 | ee188cc57d50052026f1ea72ce38a10d417ca3a9ee831bd623105de3c0743c91 |
File details
Details for the file BrazilFiscalReport-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: BrazilFiscalReport-0.4.1-py3-none-any.whl
- Upload date:
- Size: 31.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 099d7013a362f1f8a3d99ed4e9bcd70993a19648e56ed4529e64a3dcf014d8d2 |
|
MD5 | aefc2f6277ddd41f2126f0bf786a849a |
|
BLAKE2b-256 | fd657efd23ffdf2da7585e5e0ab1538f73ea927cf755b0b04357a43441755fc1 |