# tadasoftware/pynfe architecture

> Architecture diagram of the GitHub repository tadasoftware/pynfe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tadasoftware/pynfe
- Repository: https://github.com/tadasoftware/pynfe

## Overview

PyNFe is a Python library for assembling Brazilian electronic fiscal documents and interacting with SEFAZ, Receita Federal, and municipal NFS-e services. The main workflow is to create document and party entities, serialize them to XML, optionally sign and validate the XML, then communicate with the relevant service and handle its response. The README documents NF-e/NFC-e, MDF-e, and NFS-e capabilities; CT-e emission is explicitly listed as unfinished. Relationships are limited to the README example and the source imports or calls visible in the supplied excerpts and index.

Main entry points: [`pynfe/processamento/comunicacao.py`](https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/comunicacao.py) (SEFAZ communication), [`pynfe/processamento/serializacao.py`](https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/serializacao.py) (XML serialization), [`pynfe/entidades/notafiscal.py`](https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/notafiscal.py) (NF-e / NFC-e), [`pynfe/entidades/manifesto.py`](https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/manifesto.py) (MDF-e)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_domain["Fiscal entities"]
  node_nfe["NF-e / NFC-e<br/>[notafiscal.py]"]
  node_mdfe["MDF-e<br/>[manifesto.py]"]
  node_nfse["NFS-e data<br/>[servico.py]"]
  node_parties["Parties and products<br/>[cliente.py]"]
  node_events["Fiscal events<br/>[evento.py]"]
  node_lots["Document lots<br/>[lotes.py]"]
  node_entitybase["Entity base<br/>[base.py]"]
  node_data_source["Entity data source<br/>[fonte_dados.py]"]
end

subgraph group_pipeline["Document processing"]
  node_serialize["XML serialization<br/>[serializacao.py]"]
  node_sign["XML signature<br/>[assinatura.py]"]
  node_validate["XML validation<br/>[validacao.py]"]
  node_response["Response handling<br/>[resposta.py]"]
end

subgraph group_services["Service integrations"]
  node_communication["SEFAZ communication<br/>[comunicacao.py]"]
  node_nfse_authorizer["NFS-e serializers"]
end

subgraph group_shared["Shared utilities"]
  node_certificate["Digital certificate<br/>[certificado.py]"]
  node_webservice_map["Service endpoints<br/>[webservices.py]"]
  node_flags["Fiscal constants<br/>[flags.py]"]
  node_xml_tools["XML utilities<br/>[xml_writer.py]"]
  node_ginfes_types["Ginfes schema types<br/>[_tipos.py]"]
  node_ginfes_signature["Ginfes signature types<br/>[_dsig.py]"]
end

node_user(("Library caller"))
node_sefa_service{{"SEFAZ services"}}
node_municipal_service{{"Municipal services"}}

node_user -->|"requests service status"| node_communication
node_user -.->|"builds documents"| node_nfe
node_user -.->|"builds manifests"| node_mdfe
node_user -.->|"builds service invoices"| node_nfse
node_entitybase -->|"registers entities"| node_data_source
node_nfe -.->|"inherits"| node_entitybase
node_mdfe -->|"inherits"| node_entitybase
node_parties -->|"inherits"| node_entitybase
node_serialize -->|"serializes"| node_nfe
node_serialize -.->|"serializes"| node_mdfe
node_serialize -->|"dispatches NFS-e"| node_nfse_authorizer
node_serialize -->|"uses XML writer"| node_xml_tools
node_sign -->|"uses certificate"| node_certificate
node_communication -->|"uses signing"| node_sign
node_communication -->|"delegates NFS-e"| node_nfse_authorizer
node_communication -->|"resolves endpoints"| node_webservice_map
node_communication -->|"loads certificate"| node_certificate
node_communication -->|"posts requests"| node_sefa_service
node_communication -->|"posts requests"| node_municipal_service
node_communication -.->|"returns responses"| node_response
node_nfse_authorizer -->|"loads schema types"| node_ginfes_types
node_ginfes_types -->|"imports signature types"| node_ginfes_signature
node_nfe -->|"uses fiscal constants"| node_flags
node_mdfe -->|"uses fiscal constants"| node_flags
node_validate -->|"uses fiscal constants"| node_flags

click node_nfe "https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/notafiscal.py"
click node_mdfe "https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/manifesto.py"
click node_nfse "https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/servico.py"
click node_parties "https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/cliente.py"
click node_events "https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/evento.py"
click node_lots "https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/lotes.py"
click node_entitybase "https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/base.py"
click node_data_source "https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/fonte_dados.py"
click node_serialize "https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/serializacao.py"
click node_sign "https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/assinatura.py"
click node_validate "https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/validacao.py"
click node_response "https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/resposta.py"
click node_communication "https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/comunicacao.py"
click node_nfse_authorizer "https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/autorizador_nfse.py"
click node_certificate "https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/certificado.py"
click node_webservice_map "https://github.com/tadasoftware/pynfe/blob/main/pynfe/utils/webservices.py"
click node_flags "https://github.com/tadasoftware/pynfe/blob/main/pynfe/utils/flags.py"
click node_xml_tools "https://github.com/tadasoftware/pynfe/blob/main/pynfe/utils/xml_writer.py"
click node_ginfes_types "https://github.com/tadasoftware/pynfe/blob/main/pynfe/utils/nfse/ginfes/_tipos.py"
click node_ginfes_signature "https://github.com/tadasoftware/pynfe/blob/main/pynfe/utils/nfse/ginfes/_dsig.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_nfe,node_mdfe,node_nfse,node_parties,node_events,node_lots,node_entitybase,node_data_source toneBlue
class node_serialize,node_sign,node_validate,node_response toneAmber
class node_communication,node_nfse_authorizer toneMint
class node_certificate,node_webservice_map,node_flags,node_xml_tools,node_ginfes_types,node_ginfes_signature toneRose
class node_user,node_sefa_service,node_municipal_service toneIndigo
```

## Components

### Fiscal entities

- [NF-e / NFC-e](https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/notafiscal.py): `pynfe/entidades/notafiscal.py`
- [MDF-e](https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/manifesto.py): `pynfe/entidades/manifesto.py`
- [NFS-e data](https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/servico.py): `pynfe/entidades/servico.py`
- [Parties and products](https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/cliente.py): `pynfe/entidades/cliente.py`
- [Fiscal events](https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/evento.py): `pynfe/entidades/evento.py`
- [Document lots](https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/lotes.py): `pynfe/entidades/lotes.py`
- [Entity base](https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/base.py): `pynfe/entidades/base.py`
- [Entity data source](https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/fonte_dados.py): `pynfe/entidades/fonte_dados.py`

### Document processing

- [XML serialization](https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/serializacao.py): `pynfe/processamento/serializacao.py`
- [XML signature](https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/assinatura.py): `pynfe/processamento/assinatura.py`
- [XML validation](https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/validacao.py): `pynfe/processamento/validacao.py`
- [Response handling](https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/resposta.py): `pynfe/processamento/resposta.py`

### Service integrations

- [SEFAZ communication](https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/comunicacao.py): `pynfe/processamento/comunicacao.py`
- [NFS-e serializers](https://github.com/tadasoftware/pynfe/blob/main/pynfe/processamento/autorizador_nfse.py): `pynfe/processamento/autorizador_nfse.py`

### Shared utilities

- [Digital certificate](https://github.com/tadasoftware/pynfe/blob/main/pynfe/entidades/certificado.py): `pynfe/entidades/certificado.py`
- [Service endpoints](https://github.com/tadasoftware/pynfe/blob/main/pynfe/utils/webservices.py): `pynfe/utils/webservices.py`
- [Fiscal constants](https://github.com/tadasoftware/pynfe/blob/main/pynfe/utils/flags.py): `pynfe/utils/flags.py`
- [XML utilities](https://github.com/tadasoftware/pynfe/blob/main/pynfe/utils/xml_writer.py): `pynfe/utils/xml_writer.py`
- [Ginfes schema types](https://github.com/tadasoftware/pynfe/blob/main/pynfe/utils/nfse/ginfes/_tipos.py): `pynfe/utils/nfse/ginfes/_tipos.py`
- [Ginfes signature types](https://github.com/tadasoftware/pynfe/blob/main/pynfe/utils/nfse/ginfes/_dsig.py): `pynfe/utils/nfse/ginfes/_dsig.py`

### Other components

- **Library caller**
- **SEFAZ services**
- **Municipal services**

## Connections

- Library caller → SEFAZ communication: requests service status
- Library caller → NF-e / NFC-e: builds documents
- Library caller → MDF-e: builds manifests
- Library caller → NFS-e data: builds service invoices
- Entity base → Entity data source: registers entities (evidence: `pynfe/entidades/base.py`)
- NF-e / NFC-e → Entity base: inherits (evidence: `pynfe/entidades/notafiscal.py`)
- MDF-e → Entity base: inherits (evidence: `pynfe/entidades/manifesto.py`)
- Parties and products → Entity base: inherits (evidence: `pynfe/entidades/cliente.py`)
- XML serialization → NF-e / NFC-e: serializes (evidence: `pynfe/processamento/serializacao.py`)
- XML serialization → MDF-e: serializes
- XML serialization → NFS-e serializers: dispatches NFS-e (evidence: `pynfe/processamento/serializacao.py`)
- XML serialization → XML utilities: uses XML writer (evidence: `pynfe/processamento/serializacao.py`)
- XML signature → Digital certificate: uses certificate (evidence: `pynfe/processamento/assinatura.py`)
- SEFAZ communication → XML signature: uses signing (evidence: `pynfe/processamento/comunicacao.py`)
- SEFAZ communication → NFS-e serializers: delegates NFS-e (evidence: `pynfe/processamento/comunicacao.py`)
- SEFAZ communication → Service endpoints: resolves endpoints (evidence: `pynfe/processamento/comunicacao.py`)
- SEFAZ communication → Digital certificate: loads certificate (evidence: `pynfe/processamento/comunicacao.py`)
- SEFAZ communication → SEFAZ services: posts requests (evidence: `pynfe/processamento/comunicacao.py`)
- SEFAZ communication → Municipal services: posts requests (evidence: `pynfe/processamento/comunicacao.py`)
- SEFAZ communication → Response handling: returns responses
- NFS-e serializers → Ginfes schema types: loads schema types (evidence: `pynfe/processamento/autorizador_nfse.py`)
- Ginfes schema types → Ginfes signature types: imports signature types (evidence: `pynfe/utils/nfse/ginfes/_tipos.py`)
- NF-e / NFC-e → Fiscal constants: uses fiscal constants (evidence: `pynfe/entidades/notafiscal.py`)
- MDF-e → Fiscal constants: uses fiscal constants (evidence: `pynfe/entidades/manifesto.py`)
- XML validation → Fiscal constants: uses fiscal constants (evidence: `pynfe/processamento/validacao.py`)
