tributus-engine 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. tributus_engine-0.2.0/PKG-INFO +186 -0
  2. tributus_engine-0.2.0/README.md +167 -0
  3. tributus_engine-0.2.0/pyproject.toml +46 -0
  4. tributus_engine-0.2.0/setup.cfg +4 -0
  5. tributus_engine-0.2.0/src/tributus_engine/__init__.py +9 -0
  6. tributus_engine-0.2.0/src/tributus_engine/engine.py +623 -0
  7. tributus_engine-0.2.0/src/tributus_engine/implementations/__init__.py +20 -0
  8. tributus_engine-0.2.0/src/tributus_engine/implementations/cofins.py +56 -0
  9. tributus_engine-0.2.0/src/tributus_engine/implementations/ibs_cbs.py +103 -0
  10. tributus_engine-0.2.0/src/tributus_engine/implementations/icms/__init__.py +27 -0
  11. tributus_engine-0.2.0/src/tributus_engine/implementations/icms/base.py +84 -0
  12. tributus_engine-0.2.0/src/tributus_engine/implementations/icms/cst.py +515 -0
  13. tributus_engine-0.2.0/src/tributus_engine/implementations/icms/fcp.py +36 -0
  14. tributus_engine-0.2.0/src/tributus_engine/implementations/ipi.py +49 -0
  15. tributus_engine-0.2.0/src/tributus_engine/implementations/pis.py +56 -0
  16. tributus_engine-0.2.0/src/tributus_engine/interfaces/__init__.py +25 -0
  17. tributus_engine-0.2.0/src/tributus_engine/interfaces/protocols.py +124 -0
  18. tributus_engine-0.2.0/src/tributus_engine.egg-info/PKG-INFO +186 -0
  19. tributus_engine-0.2.0/src/tributus_engine.egg-info/SOURCES.txt +20 -0
  20. tributus_engine-0.2.0/src/tributus_engine.egg-info/dependency_links.txt +1 -0
  21. tributus_engine-0.2.0/src/tributus_engine.egg-info/requires.txt +9 -0
  22. tributus_engine-0.2.0/src/tributus_engine.egg-info/top_level.txt +1 -0
@@ -0,0 +1,186 @@
1
+ Metadata-Version: 2.4
2
+ Name: tributus-engine
3
+ Version: 0.2.0
4
+ Summary: Tributus Engine - Brazilian Tax Engine and Calculator Library
5
+ Author-email: Mackilem Van der Laan <mack.vdl@gmail.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: pydantic>=2.13.4
12
+ Requires-Dist: pytest>=9.0.3
13
+ Requires-Dist: PyYAML>=6.0.0
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest; extra == "dev"
16
+ Requires-Dist: pytest-cov; extra == "dev"
17
+ Requires-Dist: build; extra == "dev"
18
+ Requires-Dist: twine; extra == "dev"
19
+
20
+ # Tributus Engine (Pacote Python)
21
+
22
+ Pacote Python da biblioteca Tributus Engine para calculo tributario brasileiro.
23
+
24
+ ## Instalacao
25
+
26
+ ```bash
27
+ pip install .
28
+ ```
29
+
30
+ ## O que a biblioteca cobre
31
+
32
+ - ICMS e CSTs principais
33
+ - FCP e DIFAL
34
+ - IPI
35
+ - PIS e COFINS
36
+ - IBS e CBS
37
+ - Biblioteca de calculo tributario com metodo centralizado via payload JSON
38
+ - Catalogo fiscal por NCM/CEST e UF
39
+
40
+ ## Casos de uso
41
+
42
+ - Calculo fiscal em ERP
43
+ - API REST de tributacao
44
+ - Simulacao de impacto tributario por produto
45
+ - Cenarios com aliquota manual para homologacao e testes
46
+
47
+ ## Uso Rapido
48
+
49
+ ### 1) Engine simplificada com payload dict
50
+
51
+ ```python
52
+ from tributus_engine import TaxEngine
53
+
54
+ engine = TaxEngine()
55
+
56
+ payload = {
57
+ "operation": {
58
+ "operation_type": "sale",
59
+ "document_type": "nfe",
60
+ "operation_date": "2026-06-02",
61
+ "issuer_state": "SP",
62
+ "recipient_state": "RJ",
63
+ "issuer_country": "BR",
64
+ "recipient_country": "BR",
65
+ "consumer_final": True,
66
+ "taxpayer_icms": False,
67
+ "presence_indicator": "2"
68
+ },
69
+ "company": {
70
+ "tax_regime": "lucro_presumido",
71
+ "crt": "3",
72
+ "has_pis_credit": False,
73
+ "has_cofins_credit": False,
74
+ "suframa": False,
75
+ "taxpayer_icms": False,
76
+ "taxpayer_ibs": False
77
+ },
78
+ "customer": {
79
+ "state": "RJ",
80
+ "taxpayer_icms": False,
81
+ "consumer_final": True,
82
+ "suframa": False,
83
+ "taxpayer_ibs": False
84
+ },
85
+ "product": {
86
+ "ncm": "22030000",
87
+ "cest": "0300100",
88
+ "origin": "0",
89
+ "fiscal_category": "industrialized",
90
+ "import_content": 0.0,
91
+ "benefit_code": None,
92
+ "is_imported": False,
93
+ "has_st": True,
94
+ "has_monophase": False,
95
+ "is_fuel": False,
96
+ "is_medicine": False
97
+ },
98
+ "values": {
99
+ "quantity": "5",
100
+ "unit_price": "200.00",
101
+ "gross_value": "1000.00",
102
+ "discount_value": "100.00",
103
+ "freight_value": "50.00",
104
+ "insurance_value": "10.00",
105
+ "other_expenses": "20.00"
106
+ }
107
+ }
108
+
109
+ result = engine.calculate_from_dict(payload)
110
+ print(result.to_dict())
111
+ ```
112
+
113
+ ### 2) Engine com taxas manuais (`taxes`)
114
+
115
+ ```python
116
+ payload["taxes"] = {
117
+ "enabled": ["ipi", "icms", "fcp", "pis", "cofins", "ibs", "cbs"],
118
+ "rates": {
119
+ "icms": "17.00",
120
+ "pis": "1.20",
121
+ "cofins": "5.40",
122
+ "ibs": "16.00",
123
+ "cbs": "8.50"
124
+ },
125
+ "icms": {
126
+ "cst": "00",
127
+ "aliquota_icms_proprio": "17.00"
128
+ },
129
+ "ipi": {
130
+ "aliquota_ipi": "10.00"
131
+ },
132
+ "pis": {
133
+ "aliquota_pis": "1.20"
134
+ },
135
+ "cofins": {
136
+ "aliquota_cofins": "5.40"
137
+ }
138
+ }
139
+
140
+ result = engine.calculate_from_dict(payload)
141
+ print(result.to_dict())
142
+ ```
143
+
144
+ ### 3) Estrutura de `taxes` suportada
145
+
146
+ Campos principais aceitos no payload JSON:
147
+
148
+ - `enabled`: lista dos tributos a calcular na sequencia centralizada.
149
+ - `rates`: aliquotas simples por tributo quando nao houver configuracao mais especifica.
150
+ - `ipi`: `aliquota_ipi` ou `mode: specific` + `aliquota_por_unidade`.
151
+ - `icms`: `cst`, `aliquota_icms_proprio`, `aliquota_icms_st`, `mva`, `percentual_reducao`, `percentual_reducao_st`, `percentual_diferimento`, `percentual_credito_sn`, `include_ipi_in_base`.
152
+ - `fcp`: `aliquota_fcp`, `aliquota_fcp_st`, `aliquota_diferimento_fcp`.
153
+ - `pis`: `aliquota_pis` ou `mode: specific` + `aliquota_por_unidade`.
154
+ - `cofins`: `aliquota_cofins` ou `mode: specific` + `aliquota_por_unidade`.
155
+ - `ibs`: `aliquota_efetiva_percentual`, `percentual_diferimento`.
156
+ - `cbs`: `aliquota_efetiva_percentual`, `percentual_diferimento`.
157
+
158
+ O retorno consolidado expõe `taxes.{nome}.base`, `taxes.{nome}.rate`, `taxes.{nome}.amount` e `total`.
159
+
160
+ ### 4) Consulta de impostos/taxas por NCM/CEST para todas as UFs
161
+
162
+ ```python
163
+ taxes_by_state = engine.list_taxes_for_sale_all_states_from_dict({
164
+ "product": {"ncm": "22030000", "cest": "0300100"}
165
+ })
166
+
167
+ print(taxes_by_state["SP"])
168
+ print(taxes_by_state["RJ"])
169
+ ```
170
+
171
+ ## Modo de resolucao de taxas
172
+
173
+ Prioridade da engine:
174
+
175
+ 1. `taxes` enviado no payload
176
+ 2. catalogo interno por NCM/CEST/UF
177
+ 3. fallback automatico do provider
178
+
179
+ Na versao atual do metodo centralizado, o fluxo principal esperado e receber as incidencias e aliquotas no proprio JSON. Catalogo/provider continuam como extensoes futuras da superficie publica.
180
+
181
+ ## Desenvolvimento
182
+
183
+ ```bash
184
+ python -m pip install -e .
185
+ python -m pytest tests
186
+ ```
@@ -0,0 +1,167 @@
1
+ # Tributus Engine (Pacote Python)
2
+
3
+ Pacote Python da biblioteca Tributus Engine para calculo tributario brasileiro.
4
+
5
+ ## Instalacao
6
+
7
+ ```bash
8
+ pip install .
9
+ ```
10
+
11
+ ## O que a biblioteca cobre
12
+
13
+ - ICMS e CSTs principais
14
+ - FCP e DIFAL
15
+ - IPI
16
+ - PIS e COFINS
17
+ - IBS e CBS
18
+ - Biblioteca de calculo tributario com metodo centralizado via payload JSON
19
+ - Catalogo fiscal por NCM/CEST e UF
20
+
21
+ ## Casos de uso
22
+
23
+ - Calculo fiscal em ERP
24
+ - API REST de tributacao
25
+ - Simulacao de impacto tributario por produto
26
+ - Cenarios com aliquota manual para homologacao e testes
27
+
28
+ ## Uso Rapido
29
+
30
+ ### 1) Engine simplificada com payload dict
31
+
32
+ ```python
33
+ from tributus_engine import TaxEngine
34
+
35
+ engine = TaxEngine()
36
+
37
+ payload = {
38
+ "operation": {
39
+ "operation_type": "sale",
40
+ "document_type": "nfe",
41
+ "operation_date": "2026-06-02",
42
+ "issuer_state": "SP",
43
+ "recipient_state": "RJ",
44
+ "issuer_country": "BR",
45
+ "recipient_country": "BR",
46
+ "consumer_final": True,
47
+ "taxpayer_icms": False,
48
+ "presence_indicator": "2"
49
+ },
50
+ "company": {
51
+ "tax_regime": "lucro_presumido",
52
+ "crt": "3",
53
+ "has_pis_credit": False,
54
+ "has_cofins_credit": False,
55
+ "suframa": False,
56
+ "taxpayer_icms": False,
57
+ "taxpayer_ibs": False
58
+ },
59
+ "customer": {
60
+ "state": "RJ",
61
+ "taxpayer_icms": False,
62
+ "consumer_final": True,
63
+ "suframa": False,
64
+ "taxpayer_ibs": False
65
+ },
66
+ "product": {
67
+ "ncm": "22030000",
68
+ "cest": "0300100",
69
+ "origin": "0",
70
+ "fiscal_category": "industrialized",
71
+ "import_content": 0.0,
72
+ "benefit_code": None,
73
+ "is_imported": False,
74
+ "has_st": True,
75
+ "has_monophase": False,
76
+ "is_fuel": False,
77
+ "is_medicine": False
78
+ },
79
+ "values": {
80
+ "quantity": "5",
81
+ "unit_price": "200.00",
82
+ "gross_value": "1000.00",
83
+ "discount_value": "100.00",
84
+ "freight_value": "50.00",
85
+ "insurance_value": "10.00",
86
+ "other_expenses": "20.00"
87
+ }
88
+ }
89
+
90
+ result = engine.calculate_from_dict(payload)
91
+ print(result.to_dict())
92
+ ```
93
+
94
+ ### 2) Engine com taxas manuais (`taxes`)
95
+
96
+ ```python
97
+ payload["taxes"] = {
98
+ "enabled": ["ipi", "icms", "fcp", "pis", "cofins", "ibs", "cbs"],
99
+ "rates": {
100
+ "icms": "17.00",
101
+ "pis": "1.20",
102
+ "cofins": "5.40",
103
+ "ibs": "16.00",
104
+ "cbs": "8.50"
105
+ },
106
+ "icms": {
107
+ "cst": "00",
108
+ "aliquota_icms_proprio": "17.00"
109
+ },
110
+ "ipi": {
111
+ "aliquota_ipi": "10.00"
112
+ },
113
+ "pis": {
114
+ "aliquota_pis": "1.20"
115
+ },
116
+ "cofins": {
117
+ "aliquota_cofins": "5.40"
118
+ }
119
+ }
120
+
121
+ result = engine.calculate_from_dict(payload)
122
+ print(result.to_dict())
123
+ ```
124
+
125
+ ### 3) Estrutura de `taxes` suportada
126
+
127
+ Campos principais aceitos no payload JSON:
128
+
129
+ - `enabled`: lista dos tributos a calcular na sequencia centralizada.
130
+ - `rates`: aliquotas simples por tributo quando nao houver configuracao mais especifica.
131
+ - `ipi`: `aliquota_ipi` ou `mode: specific` + `aliquota_por_unidade`.
132
+ - `icms`: `cst`, `aliquota_icms_proprio`, `aliquota_icms_st`, `mva`, `percentual_reducao`, `percentual_reducao_st`, `percentual_diferimento`, `percentual_credito_sn`, `include_ipi_in_base`.
133
+ - `fcp`: `aliquota_fcp`, `aliquota_fcp_st`, `aliquota_diferimento_fcp`.
134
+ - `pis`: `aliquota_pis` ou `mode: specific` + `aliquota_por_unidade`.
135
+ - `cofins`: `aliquota_cofins` ou `mode: specific` + `aliquota_por_unidade`.
136
+ - `ibs`: `aliquota_efetiva_percentual`, `percentual_diferimento`.
137
+ - `cbs`: `aliquota_efetiva_percentual`, `percentual_diferimento`.
138
+
139
+ O retorno consolidado expõe `taxes.{nome}.base`, `taxes.{nome}.rate`, `taxes.{nome}.amount` e `total`.
140
+
141
+ ### 4) Consulta de impostos/taxas por NCM/CEST para todas as UFs
142
+
143
+ ```python
144
+ taxes_by_state = engine.list_taxes_for_sale_all_states_from_dict({
145
+ "product": {"ncm": "22030000", "cest": "0300100"}
146
+ })
147
+
148
+ print(taxes_by_state["SP"])
149
+ print(taxes_by_state["RJ"])
150
+ ```
151
+
152
+ ## Modo de resolucao de taxas
153
+
154
+ Prioridade da engine:
155
+
156
+ 1. `taxes` enviado no payload
157
+ 2. catalogo interno por NCM/CEST/UF
158
+ 3. fallback automatico do provider
159
+
160
+ Na versao atual do metodo centralizado, o fluxo principal esperado e receber as incidencias e aliquotas no proprio JSON. Catalogo/provider continuam como extensoes futuras da superficie publica.
161
+
162
+ ## Desenvolvimento
163
+
164
+ ```bash
165
+ python -m pip install -e .
166
+ python -m pytest tests
167
+ ```
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tributus-engine"
7
+ version = "0.2.0"
8
+ description = "Tributus Engine - Brazilian Tax Engine and Calculator Library"
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "Mackilem Van der Laan", email = "mack.vdl@gmail.com" },
12
+ ]
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Operating System :: OS Independent",
17
+ ]
18
+ requires-python = ">=3.10"
19
+ dependencies = [
20
+ "pydantic>=2.13.4",
21
+ "pytest>=9.0.3",
22
+ "PyYAML>=6.0.0",
23
+ ]
24
+
25
+ [project.optional-dependencies]
26
+ dev = [
27
+ "pytest",
28
+ "pytest-cov",
29
+ "build",
30
+ "twine",
31
+ ]
32
+
33
+ [tool.setuptools.packages.find]
34
+ where = ["src"]
35
+
36
+ [tool.setuptools.package-data]
37
+ tributus_engine = [
38
+ "data/docs/*.json",
39
+ ]
40
+
41
+ [tool.pytest.ini_options]
42
+ minversion = "6.0"
43
+ addopts = "-ra -q"
44
+ testpaths = [
45
+ "tests",
46
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,9 @@
1
+ from .engine import (
2
+ BRAZIL_STATES,
3
+ BaseCalculator,
4
+ TaxEngine,
5
+ TaxContext,
6
+ TaxDependencyGraph,
7
+ TaxResult,
8
+ ValueContext,
9
+ )