Skip to main content

SOAP client for the Brazilian Fiscal Authorities

Project description

Build Status codecov PyPI

brazil-fiscal-client

A simple, modern and well tested SOAP client for the Brazilian Fiscal Authority.

This client is designed to be inherited by specialized clients such as for electronic invoicing (NFe). But with some extra boiler plate code to deal with the SOAP enveloppe, it can still be used alone as you can see in the usage section below.

It uses xsdata for the databinding and it overrides its SOAP client

Installation

pip install brazil-fiscal-client

Usage

For instance, with an appropriate pkcs12 certificate, you can query the NFe server status (remember specialized clients make all this simpler):

from brazil_fiscal_client.fiscal_client import FiscalClient
from tests.fixtures.nfestatusservico4 import NfeStatusServico4SoapNfeStatusServicoNf
from nfelib.nfe.bindings.v4_0.cons_stat_serv_v4_00 import ConsStatServ
from nfelib.nfe.bindings.v4_0.ret_cons_stat_serv_v4_00 import RetConsStatServ

ambiente = "2"
path_to_your_pkcs12_certificate = "/path_to_your_certificate/pkcs12_certificate.p12"
certificate_password = "your_certificate_password"

with open(path_to_your_pkcs12_certificate, "rb") as pkcs12_buffer:
    pkcs12_data = pkcs12_buffer.read()

client = FiscalClient(
    ambiente=ambiente,
    versao="4.00",
    pkcs12_data=pkcs12_data,
    pkcs12_password=your_certificate_password,
)

result = client.send(
    NfeStatusServico4SoapNfeStatusServicoNf,
    "https://nfe-homologacao.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx",
    {
        "Body": {
            "nfeDadosMsg": {
                "content": [
                    ConsStatServ(
                        tpAmb="2",
                        cUF="42",
                        xServ="STATUS",
                        versao="4.00",
                    ),
                ]
            }
        }
    },
)

>>> result.body.nfeResultMsg.content[0]
RetConsStatServ(tpAmb=<Tamb.VALUE_2: '2'>, verAplic='SVRS202401251654', cStat='107', xMotivo='Servico SVC em Operacao', cUF=<TcodUfIbge.VALUE_42: '42'>, dhRecbto='2024-04-01T16:18:03-03:00', tMed='1', dhRetorno=None, xObs=None, versao='4.00')
>>> result.body.nfeResultMsg.content[0].cStat
'107'

Notice this example uses the ConsStatServ and RetConsStatServ bindings from nfelib. In this example NfeStatusServico4SoapNfeStatusServicoNf has been generated from a previously downloaded wsdl file and using the WSDL xsdata generator. All this is usually done in the specialized clients that override this base brazil-fiscal-clientSOAP client.

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

brazil_fiscal_client-0.3.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

brazil_fiscal_client-0.3.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file brazil_fiscal_client-0.3.0.tar.gz.

File metadata

  • Download URL: brazil_fiscal_client-0.3.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for brazil_fiscal_client-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c5a59a38db141accdf9f03b6425a1ae9975327388579905b607a632d8e890324
MD5 314d8c8b7cc1e851f54bfb0368f9b481
BLAKE2b-256 9d4a8953bd17891641e4a0677e7869f66c205b082bc87e062be75221ed3cdbe2

See more details on using hashes here.

Provenance

The following attestation bundles were made for brazil_fiscal_client-0.3.0.tar.gz:

Publisher: publish.yml on akretion/brazil-fiscal-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file brazil_fiscal_client-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for brazil_fiscal_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6ce7c8a9bc72dc0e8e7af69d8add25e90266d3def9a4078566263f192c62603
MD5 8ca76d71f902f7593170cb86dd0a7589
BLAKE2b-256 3e18d70b9f056131b7c6bd7b2a483cd97980603497c55fb10f7f0a8ff3e1d3a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for brazil_fiscal_client-0.3.0-py3-none-any.whl:

Publisher: publish.yml on akretion/brazil-fiscal-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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