$ show akretion/nfelib
nfelib is a Python library providing data bindings, serialization, and SOAP client support for Brazilian electronic fiscal documents (NF-e, CT-e, MDF-e, NFSe, BP-e). It uses xsdata to auto-generate Python dataclasses from official XSD schemas (versions v4.0, v3.0, v1.0). The library includes a CommonMixin base class for common XML operations (to_xml, from_xml, sign_xml, to_pdf, validate_xml), SOAP service bindings generated from WSDLs, and server endpoint configurations per Brazilian state (UF). It also provides code generation tools (generate_bindings.py) and server endpoint scraping utilities (servers_scraper.py). The architecture mixes auto-generated binding code with handcrafted integration patterns and testing utilities. The project has strong test coverage, including round-trip XML serialization tests, protocol buffer validation, and fingerprint-based detection of external schema changes. It is designed for ERP integration (e.g., Odoo) and fiscal compliance software.
The LLM identified 2 files worth highlighting for reuse:
A script that automatically generates all Python dataclass bindings from official XSD schemas using xsdata. It encapsulates schema paths, package names, and applies runtime patches for chameleon schema ordering and Odoo-specific attribute merging. The script is parameterized, supports selective generation by document type, and can download schemas from government portals. It is a self-contained code generation pipeline that could be adapted to generate bindings for any XSD-based fiscal or regulatory schema.
A utility that scrapes Brazilian SEFAZ (state tax authority) web pages to discover SOAP endpoint URLs for production and homologation environments for each fiscal document type (NF-e, CT-e, MDF-e). It outputs structured Python dictionaries (TypedDicts, Endpoint enums) that can be used directly by client code. The script handles both SOAP 1.1 and 1.2 detection, uses requests with PKCS12 certificates, and is parameterized by document type. It could be extracted and reused for any dynamic endpoint discovery problem in government or enterprise API integration.