### Sign NF-e XML with Certificate Source: https://github.com/akretion/nfelib/blob/master/README.md Example of signing an NF-e XML using a PKCS12 certificate and password. This is typically done before transmitting the document. ```python >>> # Assinar o XML de uma nota: >>> with open(path_to_your_pkcs12_certificate, "rb") as pkcs12_buffer: pkcs12_data = pkcs12_buffer.read() >>> signed_xml = nfe.sign_xml(xml, pkcs12_data, cert_password, nfe.NFe.infNFe.Id) ``` -------------------------------- ### Read and Serialize NFS-e XML Source: https://github.com/akretion/nfelib/blob/master/README.md Provides examples for reading and serializing NFS-e (Nota Fiscal de Serviço eletrônica) XML files. Also includes reading a DPS (Documento de Prestação de Serviço). ```python >>> # Ler uma NFS-e: >>>> from nfelib.nfse.bindings.v1_0.nfse_v1_00 import Nfse >>> nfse = Nfse.from_path("alguma_nfse.xml") >>> >>> # Serializar uma NFS-e: >>> nfse.to_xml() >>> # Ler uma DPS: >>>> from nfelib.nfse.bindings.v1_0.dps_v1_00 import Dps >>> dps = Nfse.from_path("nfelib/nfse/samples/v1_0/GerarNFSeEnvio-env-loterps.xml") >>> >>> # Serializar uma DPS: >>> dps.to_xml() ``` -------------------------------- ### Read and Serialize CT-e XML Source: https://github.com/akretion/nfelib/blob/master/README.md Provides examples for reading and serializing CT-e (Conhecimento de Transporte Eletrônico) XML files. This document is used for freight services. ```python >>> # Ler um CT-e: >>>> from nfelib.cte.bindings.v4_0.cte_v4_00 import Cte >>> cte = Cte.from_path("nfelib/cte/samples/v4_0/43120178408960000182570010000000041000000047-cte.xml") >>> >>> # Serializar um CT-e: >>> cte.to_xml() ``` -------------------------------- ### Create and Validate NF-e from Scratch Source: https://github.com/akretion/nfelib/blob/master/README.md Shows how to construct an NF-e object programmatically and then validate its XML structure. Validation checks for missing required attributes. ```python >>> # Montar uma NFe do zero: >>> from nfelib.nfe.bindings.v4_0.nfe_v4_00 import Nfe >>> nfe=Nfe(infNFe=Nfe.InfNfe(emit=Nfe.InfNfe.Emit(xNome="Minha Empresa", CNPJ='59594315000157'))) >>> nfe Nfe(infNFe=Tnfe.InfNfe(ide=None, emit=Tnfe.InfNfe.Emit(CNPJ='59594315000157', CPF=None, xNome='Minha Empresa', xFant=None, enderEmit=None, IE=None, IEST=None, IM=None, CNAE=None, CRT=None), avulsa=None, dest=None, retirada=None, entrega=None, autXML=[], det=[], total=None, transp=None, cobr=None, pag=None, infIntermed=None, infAdic=None, exporta=None, compra=None, cana=None, infRespTec=None, infSolicNFF=None, versao=None, Id=None), infNFeSupl=None, signature=None) >>> >>> # Validar o XML de uma nota: >>> nfe.validate_xml() ["Element '{http://www.portalfiscal.inf.br/nfe}infNFe': The attribute 'versao' is required but missing.", "Element '{http://www.portalfiscal.inf.br/nfe}infNFe': The attribute 'Id' is required but missing." [...] ``` -------------------------------- ### Read and Serialize BP-e XML Source: https://github.com/akretion/nfelib/blob/master/README.md Demonstrates how to read and serialize BP-e (Bilhete de Passagem Eletrônico) XML files. This is used for passenger transportation services. ```python >>> # Ler um BP-e: >>>> from nfelib.bpe.bindings.v1_0.bpe_v1_00 import Bpe >>> bpe = Bpe.from_path("algum_bpe.xml") >>> >>> # Serializar um BP-e: >>> bpe.to_xml() ``` -------------------------------- ### Read and Serialize MDF-e XML Source: https://github.com/akretion/nfelib/blob/master/README.md Shows how to read and serialize MDF-e (Manifesto Eletrônico de Documentos Fiscais) XML files. This is used for tracking goods transportation. ```python >>> # Ler um MDF-e: >>>> from nfelib.mdfe.bindings.v3_0.mdfe_v3_00 import Mdfe >>> mdfe = Mdfe.from_path("nfelib/mdfe/samples/v3_0/ComPagtoPIX_41210780568835000181580010402005751006005791-procMDFe.xml") >>> >>> # Serializar um MDF-e: >>> mdfe.to_xml() ``` -------------------------------- ### Generate NF-e PDF (DANFE) Source: https://github.com/akretion/nfelib/blob/master/README.md Demonstrates generating a PDF representation (DANFE) of an NF-e. Supports different PDF generation engines and can include signing. ```python >>> # Imprimir o pdf de uma nota usando BrazilFiscalReport: >>> pdf_bytes = nfe.to_pdf() >>> # Imprimir o pdf de uma nota usando erpbrasil.edoc.pdf: >>> pdf_bytes = nfe.to_pdf(engine="erpbrasil.edoc.pdf") >>> # Ou então para imprimir e assinar junto: >>> pdf_bytes = nfe.to_pdf( pkcs12_data=cert_data, pkcs12_password=cert_password, doc_id=nfe.NFe.infNFe.Id, ) ``` -------------------------------- ### Read and Access NF-e XML Data Source: https://github.com/akretion/nfelib/blob/master/README.md Demonstrates how to read an NF-e XML file and access its emission information. Supports reading from a file path or an XML string. ```python >>> # Ler o XML de uma NF-e: >>> from nfelib.nfe.bindings.v4_0.proc_nfe_v4_00 import NfeProc >>> nfe_proc = NfeProc.from_path("nfelib/nfe/samples/v4_0/leiauteNFe/NFe35200159594315000157550010000000012062777161.xml") >>> # (pode ser usado também o metodo from_xml(xml) ) >>> >>> nfe_proc.NFe.infNFe.emit.CNPJ '59594315000157' >>> nfe_proc.NFe.infNFe.emit Tnfe.InfNfe.Emit(CNPJ='59594315000157', CPF=None, xNome='Akretion LTDA', xFant='Akretion', enderEmit=TenderEmi(xLgr='Rua Paulo Dias', nro='586', xCpl=None, xBairro=None, cMun='3501152', xMun='Alumínio', UF=, CEP='18125000', cPais=, xPais=, fone='2130109965'), IE='755338250133', IEST=None, IM=None, CNAE=None, CRT=) >>> nfe_proc.NFe.infNFe.emit.enderEmit.UF.value 'SP' ``` -------------------------------- ### Serialize NF-e to XML Source: https://github.com/akretion/nfelib/blob/master/README.md Converts an NF-e object back into its XML representation. This is useful for saving or transmitting the data. ```python >>> nfe_proc.to_xml() '\n\n \n \n \n 35\n 06277716\n Venda\n 55\n 1\n 1\n 2020-01-01T12:00:00+01:00\n 2020-01-01T12:00:00+01:00\n 1\n 1\n [...] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.