Skip to main content

Python library for generating Brazilian auxiliary fiscal documents in PDF from XML documents.

Project description

tests codecov pypi license contributors pypi-downloads Open in Streamlit

Brazil Fiscal Report

Python library for generating Brazilian auxiliary fiscal documents in PDF from XML documents.

Every Brazilian electronic invoice is issued by the tax authority as an XML file. This library turns that XML into the official, printable PDF that has to accompany the goods or service: NF-e → DANFE, CT-e → DACTE, MDF-e → DAMDFE and NFS-e → DANFSe. It also renders the DACCe, the printout for the NF-e correction-letter event (CC-e).

🇧🇷 Biblioteca Python para gerar em PDF os documentos fiscais auxiliares — DANFE, DACTE, DAMDFE e DANFSe — a partir do XML de NF-e, CT-e, MDF-e e NFS-e. Também gera a DACCe, representação da carta de correção (CC-e) da NF-e. Documentação em português →

Documentation | PyPI | Try it Online

Output Examples

DANFE DACTE DAMDFE DANFSe
DANFE generated in PDF DACTE generated in PDF DAMDFE generated in PDF DANFSe generated in PDF
NF-e → PDF
Electronic invoice (goods)
CT-e → PDF
Freight bill
MDF-e → PDF
Cargo manifest
NFS-e → PDF
Service invoice

Why BrazilFiscalReport?

  • 🐍 Pure Python — built on fpdf2; no wkhtmltopdf, no headless browser, no HTML templates
  • 📄 4 document types — DANFE, DACTE, DAMDFE and DANFSe (plus the DACCe correction-letter event), straight from the official XML
  • 🎨 Customizable — issuer logo, margins, fonts, decimal precision, cancellation watermarks and more
  • 3 ways to use it — Python API, bfrep command line, or the online demo
  • Python 3.8+ — tested on Python 3.8 through 3.13

Installation

pip install brazilfiscalreport

This installs the core library with support for DANFE and DACCe. For additional document types and features:

pip install 'brazilfiscalreport[dacte]'   # DACTE support (requires qrcode)
pip install 'brazilfiscalreport[damdfe]'  # DAMDFE support (requires qrcode)
pip install 'brazilfiscalreport[danfse]'  # DANFSe support (requires qrcode)
pip install 'brazilfiscalreport[cli]'     # CLI tool
pip install 'brazilfiscalreport[dacte,damdfe,danfse,cli]'  # All extras

Quick Start

from brazilfiscalreport.danfe import Danfe

with open("nfe.xml", "r", encoding="utf8") as file:
    xml_content = file.read()

danfe = Danfe(xml=xml_content)
danfe.output("danfe.pdf")

nfe.xml is the authorized XML your ERP or the SEFAZ portal returns once the invoice is approved.

The same pattern works for every document type — import the matching class (Dacte, Damdfe, Danfse, DaCCe), pass the XML and call .output().

Customization

Need a logo, custom margins or a different font? Pass a config object:

from brazilfiscalreport.danfe import Danfe, DanfeConfig, Margins, FontType

with open("nfe.xml", encoding="utf8") as file:
    xml_content = file.read()

config = DanfeConfig(
    logo="logo.png",
    margins=Margins(top=5, right=5, bottom=5, left=5),
    font_type=FontType.TIMES,
)
danfe = Danfe(xml=xml_content, config=config)
danfe.output("danfe.pdf")

See the documentation for every option — watermarks, decimal precision, receipt position and more.

🚀 No setup? Try it online — upload your fiscal XML, download the PDF.

CLI

pip install 'brazilfiscalreport[cli]'

bfrep danfe nfe.xml        # writes nfe.pdf in the current folder

bfrep ships one subcommand per document — danfe, dacte, damdfe and danfse (plus dacce for the NF-e correction letter) — each turning its XML into the matching PDF. Drop a config.yaml next to your files to set issuer data, logo and margins.

See the CLI documentation for all options.

License

BrazilFiscalReport is free software licensed under the LGPL-3.0 license.

Maintainer

Developed and maintained by Engenere. Issues and pull requests are welcome — see the contributing guide.

Engenere

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

brazilfiscalreport-1.0.1.tar.gz (223.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

brazilfiscalreport-1.0.1-py3-none-any.whl (223.8 kB view details)

Uploaded Python 3

File details

Details for the file brazilfiscalreport-1.0.1.tar.gz.

File metadata

  • Download URL: brazilfiscalreport-1.0.1.tar.gz
  • Upload date:
  • Size: 223.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for brazilfiscalreport-1.0.1.tar.gz
Algorithm Hash digest
SHA256 eb5b4317cdaa8ab1624a0c5ade86235da4d3006637d9be3069771bb48b19965e
MD5 7e4bf9107d18e1f5e773957507c72181
BLAKE2b-256 54af250c87ff8860857d3a93ce03a5f5e4b7526353cc8d00e26e0e90b32062f2

See more details on using hashes here.

File details

Details for the file brazilfiscalreport-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for brazilfiscalreport-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e03b7dc34d134273baa40e30787c90d1050f1b3af105cbf0548e14d08a8811fb
MD5 0995481c2b05c720d3fd6eca997c4691
BLAKE2b-256 527d1d95f7aa44a6e7160c35c1eedb8bad71eb06f0d2345a513349bc1a5cd566

See more details on using hashes here.

Supported by

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