cfdi-kit 1.1.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.
- cfdi_kit-1.1.0/.gitignore +231 -0
- cfdi_kit-1.1.0/CHANGELOG.md +41 -0
- cfdi_kit-1.1.0/LICENSE +21 -0
- cfdi_kit-1.1.0/PKG-INFO +204 -0
- cfdi_kit-1.1.0/README.es.md +175 -0
- cfdi_kit-1.1.0/README.md +175 -0
- cfdi_kit-1.1.0/pyproject.toml +73 -0
- cfdi_kit-1.1.0/src/cfdi_kit/__init__.py +42 -0
- cfdi_kit-1.1.0/src/cfdi_kit/catalogs.py +134 -0
- cfdi_kit-1.1.0/src/cfdi_kit/cli.py +232 -0
- cfdi_kit-1.1.0/src/cfdi_kit/export.py +259 -0
- cfdi_kit-1.1.0/src/cfdi_kit/loader.py +125 -0
- cfdi_kit-1.1.0/src/cfdi_kit/models.py +200 -0
- cfdi_kit-1.1.0/src/cfdi_kit/parser.py +331 -0
- cfdi_kit-1.1.0/src/cfdi_kit/py.typed +0 -0
- cfdi_kit-1.1.0/src/cfdi_kit/report.css +53 -0
- cfdi_kit-1.1.0/src/cfdi_kit/report.py +387 -0
- cfdi_kit-1.1.0/src/cfdi_kit/risk.py +207 -0
- cfdi_kit-1.1.0/src/cfdi_kit/summary.py +245 -0
- cfdi_kit-1.1.0/src/cfdi_kit/validate.py +203 -0
- cfdi_kit-1.1.0/tests/__init__.py +0 -0
- cfdi_kit-1.1.0/tests/conftest.py +23 -0
- cfdi_kit-1.1.0/tests/fixtures/credit_note_40.xml +25 -0
- cfdi_kit-1.1.0/tests/fixtures/expense_ppd_usd_33.xml +22 -0
- cfdi_kit-1.1.0/tests/fixtures/expense_pue_40.xml +22 -0
- cfdi_kit-1.1.0/tests/fixtures/income_ppd_40.xml +22 -0
- cfdi_kit-1.1.0/tests/fixtures/income_pue_40.xml +30 -0
- cfdi_kit-1.1.0/tests/fixtures/invalid/cfdi_32.xml +2 -0
- cfdi_kit-1.1.0/tests/fixtures/invalid/not_a_cfdi.xml +2 -0
- cfdi_kit-1.1.0/tests/fixtures/invalid/truncated.xml +2 -0
- cfdi_kit-1.1.0/tests/fixtures/payment_10.xml +16 -0
- cfdi_kit-1.1.0/tests/fixtures/payment_20.xml +28 -0
- cfdi_kit-1.1.0/tests/fixtures/payroll_40.xml +20 -0
- cfdi_kit-1.1.0/tests/fixtures/risk/listado_69b.csv +8 -0
- cfdi_kit-1.1.0/tests/test_catalogs.py +18 -0
- cfdi_kit-1.1.0/tests/test_cli.py +205 -0
- cfdi_kit-1.1.0/tests/test_export.py +162 -0
- cfdi_kit-1.1.0/tests/test_loader.py +141 -0
- cfdi_kit-1.1.0/tests/test_package.py +5 -0
- cfdi_kit-1.1.0/tests/test_parser.py +206 -0
- cfdi_kit-1.1.0/tests/test_report.py +141 -0
- cfdi_kit-1.1.0/tests/test_risk.py +177 -0
- cfdi_kit-1.1.0/tests/test_summary.py +98 -0
- cfdi_kit-1.1.0/tests/test_validate.py +92 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Spyder project settings
|
|
163
|
+
.spyderproject
|
|
164
|
+
.spyproject
|
|
165
|
+
|
|
166
|
+
# Rope project settings
|
|
167
|
+
.ropeproject
|
|
168
|
+
|
|
169
|
+
# mkdocs documentation
|
|
170
|
+
/site
|
|
171
|
+
|
|
172
|
+
# mypy
|
|
173
|
+
.mypy_cache/
|
|
174
|
+
.dmypy.json
|
|
175
|
+
dmypy.json
|
|
176
|
+
|
|
177
|
+
# Pyre type checker
|
|
178
|
+
.pyre/
|
|
179
|
+
|
|
180
|
+
# pytype static type analyzer
|
|
181
|
+
.pytype/
|
|
182
|
+
|
|
183
|
+
# Cython debug symbols
|
|
184
|
+
cython_debug/
|
|
185
|
+
|
|
186
|
+
# PyCharm
|
|
187
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
188
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
189
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
190
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
191
|
+
# .idea/
|
|
192
|
+
|
|
193
|
+
# Abstra
|
|
194
|
+
# Abstra is an AI-powered process automation framework.
|
|
195
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
196
|
+
# Learn more at https://abstra.io/docs
|
|
197
|
+
.abstra/
|
|
198
|
+
|
|
199
|
+
# Visual Studio Code
|
|
200
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
201
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
202
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
203
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
204
|
+
# .vscode/
|
|
205
|
+
# Temporary file for partial code execution
|
|
206
|
+
tempCodeRunnerFile.py
|
|
207
|
+
|
|
208
|
+
# Ruff stuff:
|
|
209
|
+
.ruff_cache/
|
|
210
|
+
|
|
211
|
+
# PyPI configuration file
|
|
212
|
+
.pypirc
|
|
213
|
+
|
|
214
|
+
# Marimo
|
|
215
|
+
marimo/_static/
|
|
216
|
+
marimo/_lsp/
|
|
217
|
+
__marimo__/
|
|
218
|
+
|
|
219
|
+
# Streamlit
|
|
220
|
+
.streamlit/secrets.toml
|
|
221
|
+
|
|
222
|
+
# --- Workspace additions ---
|
|
223
|
+
# macOS
|
|
224
|
+
.DS_Store
|
|
225
|
+
# Editors
|
|
226
|
+
.vscode/
|
|
227
|
+
.idea/
|
|
228
|
+
# Secrets (commit .env.example only)
|
|
229
|
+
.env
|
|
230
|
+
.env.*
|
|
231
|
+
!.env.example
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## [1.1.0] - 2026-11-27
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `cfdi-kit risk PATHS --list FILE [--rfc RFC]` flags invoices whose issuer is on a local copy of the SAT article 69-B list, by status (`Definitivo`, `Presunto`, `Desvirtuado`, `Sentencia Favorable`). It exits with status 1 on presumed or definitive matches.
|
|
10
|
+
- `cfdi-kit report --risk-list FILE` adds a supplier risk section to the HTML report.
|
|
11
|
+
- Library API: `load_snapshot`, `find_matches` and their types.
|
|
12
|
+
- `examples/demo-69b.csv`, a synthetic list for the demo invoices.
|
|
13
|
+
|
|
14
|
+
### Security
|
|
15
|
+
|
|
16
|
+
- Excel exports store invoice text as plain text, so a description such as `=HYPERLINK(...)` in a third-party XML no longer becomes a live formula.
|
|
17
|
+
- CSV exports prefix an apostrophe to text that starts with a character a spreadsheet would run (`=`, `+`, `-`, `@`, their full-width forms, tab or line break). Amounts are not changed.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- `load` reports an error and keeps going on encrypted or damaged ZIP members, unreadable files and unknown or unsupported XML encodings, instead of raising.
|
|
22
|
+
- The 20 MiB limit also applies to XML files outside ZIP archives.
|
|
23
|
+
- Invoices with `NaN`, infinite or oversized amounts, dates with a time zone or outside 2000–2099, or a non-numeric installment are rejected as parse errors.
|
|
24
|
+
|
|
25
|
+
## [1.0.0] - 2026-10-26
|
|
26
|
+
|
|
27
|
+
First public release.
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- Parser for CFDI 4.0 and 3.3 with the Timbre Fiscal Digital 1.1, Pagos 1.0 / 2.0 and Nómina 1.2 complements, into frozen dataclasses with `Decimal` money.
|
|
32
|
+
- Loader for files, folders and ZIP archives, with per-file error reporting and UUID de-duplication.
|
|
33
|
+
- Export to pandas DataFrames, CSV and a three-sheet Excel workbook.
|
|
34
|
+
- Monthly income / expense / VAT summary on accrual or cash basis.
|
|
35
|
+
- Consistency checks: totals, tax breakdowns, RFCs, stamps, PPD payment form, exchange rate, duplicates.
|
|
36
|
+
- Self-contained HTML report.
|
|
37
|
+
- `cfdi-kit` CLI with `parse`, `summary`, `validate` and `report`.
|
|
38
|
+
- Synthetic demo generator and a year of demo invoices.
|
|
39
|
+
|
|
40
|
+
[1.1.0]: https://github.com/DiegoTepichin/cfdi-kit/compare/v1.0.0...v1.1.0
|
|
41
|
+
[1.0.0]: https://github.com/DiegoTepichin/cfdi-kit/releases/tag/v1.0.0
|
cfdi_kit-1.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Diego Tepichin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
cfdi_kit-1.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: cfdi-kit
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Parse SAT CFDI invoices (XML) into dataframes, Excel and a local income / expense / VAT report. Nothing leaves your machine.
|
|
5
|
+
Project-URL: Homepage, https://github.com/DiegoTepichin/cfdi-kit
|
|
6
|
+
Project-URL: Repository, https://github.com/DiegoTepichin/cfdi-kit
|
|
7
|
+
Project-URL: Issues, https://github.com/DiegoTepichin/cfdi-kit/issues
|
|
8
|
+
Author: Diego Tepichin
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: accounting,cfdi,factura,invoice,iva,mexico,pandas,sat,xml
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Classifier: Natural Language :: English
|
|
17
|
+
Classifier: Natural Language :: Spanish
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Office/Business :: Financial :: Accounting
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Requires-Dist: openpyxl>=3.1
|
|
27
|
+
Requires-Dist: pandas>=2.2
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# cfdi-kit
|
|
31
|
+
|
|
32
|
+
Turn a folder of SAT CFDI invoices (XML) into Excel, pandas DataFrames, a monthly income / expense / VAT summary and a one-file HTML report. Everything runs on your machine; no invoice data is sent anywhere.
|
|
33
|
+
|
|
34
|
+
[](https://github.com/DiegoTepichin/cfdi-kit/actions/workflows/ci.yml)
|
|
35
|
+
[](https://github.com/DiegoTepichin/cfdi-kit/blob/main/LICENSE)
|
|
36
|
+
|
|
37
|
+
[Leer en español](https://github.com/DiegoTepichin/cfdi-kit/blob/main/README.es.md)
|
|
38
|
+
|
|
39
|
+

|
|
40
|
+
|
|
41
|
+
*`cfdi-kit report` on the synthetic invoices in [`examples/demo`](https://github.com/DiegoTepichin/cfdi-kit/tree/main/examples/demo).*
|
|
42
|
+
|
|
43
|
+
## Why
|
|
44
|
+
|
|
45
|
+
Every Mexican invoice is an XML file. Reading a month of them means opening files one by one, retyping amounts into a spreadsheet or uploading your tax data to a cloud service. `cfdi-kit` reads hundreds of CFDIs in a second, straight from the folder or the ZIP the SAT portal gives you, and keeps them on your computer.
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install cfdi-kit
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
or run it without installing, with [uv](https://docs.astral.sh/uv/):
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
uvx cfdi-kit --help
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Requires Python 3.11+.
|
|
60
|
+
|
|
61
|
+
## Quickstart
|
|
62
|
+
|
|
63
|
+
Try it on the bundled demo (a fictional freelancer, RFC `CACX7605101P8`, one year of invoices):
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
git clone https://github.com/DiegoTepichin/cfdi-kit && cd cfdi-kit
|
|
67
|
+
uv run cfdi-kit summary examples/demo --rfc CACX7605101P8 --basis cash
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```text
|
|
71
|
+
CACX7605101P8 · cash basis · MXN
|
|
72
|
+
|
|
73
|
+
Month Income VAT charged VAT withheld Expenses VAT creditable Net VAT
|
|
74
|
+
------- --------- ----------- ------------ --------- -------------- --------
|
|
75
|
+
2026-01 61,000.00 9,760.00 4,160.01 2,500.00 400.00 5,199.99
|
|
76
|
+
2026-02 26,500.00 4,240.00 0.00 2,400.00 384.00 3,856.00
|
|
77
|
+
2026-03 74,000.00 11,840.00 7,893.36 28,700.00 4,592.00 -645.36
|
|
78
|
+
...
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
With your own invoices:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
cfdi-kit parse ~/Downloads/facturas -o facturas.xlsx --rfc YOUR_RFC # Excel with 3 sheets
|
|
85
|
+
cfdi-kit summary ~/Downloads/facturas --rfc YOUR_RFC # monthly table
|
|
86
|
+
cfdi-kit report ~/Downloads/facturas --rfc YOUR_RFC -o reporte.html # HTML report
|
|
87
|
+
cfdi-kit validate ~/Downloads/facturas # consistency checks
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Every command accepts any mix of `.xml` files, folders (searched recursively) and `.zip` archives. Unreadable files are listed and skipped; repeated UUIDs are counted once.
|
|
91
|
+
|
|
92
|
+
## What it reads
|
|
93
|
+
|
|
94
|
+
| | Supported |
|
|
95
|
+
|---|---|
|
|
96
|
+
| CFDI | 4.0 and 3.3 (types I, E, T, N and P) |
|
|
97
|
+
| Complements | Timbre Fiscal Digital 1.1, Pagos 2.0 and 1.0, Nómina 1.2 |
|
|
98
|
+
| Money | `Decimal` end to end; foreign currency converted with the invoice or payment exchange rate |
|
|
99
|
+
|
|
100
|
+
CFDI 3.2 and earlier are reported as unsupported.
|
|
101
|
+
|
|
102
|
+
## Commands
|
|
103
|
+
|
|
104
|
+
### `parse`: Excel or CSV
|
|
105
|
+
|
|
106
|
+
`cfdi-kit parse PATHS -o out.xlsx [--rfc RFC]` writes three sheets: `invoices` (one row per CFDI, with taxes, totals in MXN and SAT catalog labels), `line_items` and `payments` (each invoice settled by a payment complement). With `-o out.csv` it writes the invoices table only. `--rfc` adds a `direction` column (`issued` / `received`). Invoice text comes from third parties, so Excel stores it as plain text, never as a formula; in CSV, text starting with `=`, `+`, `-`, `@`, a tab or a line break gets a leading apostrophe.
|
|
107
|
+
|
|
108
|
+
### `summary`: income, expenses and VAT per month
|
|
109
|
+
|
|
110
|
+
`cfdi-kit summary PATHS --rfc RFC [--basis accrual|cash] [-o file]`
|
|
111
|
+
|
|
112
|
+
- **accrual** (default): every invoice counts on its issue date.
|
|
113
|
+
- **cash**: `PUE` invoices count on their issue date; `PPD` invoices count when a payment complement settles them, on the payment date. Pagos 2.0 tax breakdowns are used as written; Pagos 1.0 payments are prorated against the original invoice when it is in the folder.
|
|
114
|
+
|
|
115
|
+
Credit notes (`E`) subtract. Payroll (`N`) is reported in separate columns. *Net VAT* is VAT charged, minus VAT withheld by your clients, minus creditable VAT.
|
|
116
|
+
|
|
117
|
+
### `report`: one HTML file
|
|
118
|
+
|
|
119
|
+
`cfdi-kit report PATHS --rfc RFC [--basis] [-o report.html]` writes a single file with no scripts or external assets: totals, an income vs expense chart, the monthly table, top clients and suppliers, PPD invoices with an open balance and every validation issue. It follows the system's light or dark theme.
|
|
120
|
+
|
|
121
|
+
### `validate`: catch errors before they reach your books
|
|
122
|
+
|
|
123
|
+
```text
|
|
124
|
+
$ cfdi-kit validate broken.xml
|
|
125
|
+
error total-mismatch broken.xml Total is 99999.99 but SubTotal - Descuento + taxes is 34796.65
|
|
126
|
+
1 error(s), 0 warning(s)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Checks: missing stamp, total / subtotal / discount that don't add up (one cent of rounding per line allowed), invoice vs line-item tax totals, malformed RFCs, PPD invoices with a payment form other than 99, foreign currency without an exchange rate and duplicate UUIDs. The command exits with status 1 when it finds errors, so you can use it in scripts.
|
|
130
|
+
|
|
131
|
+
### `risk`: check suppliers against the SAT 69-B list
|
|
132
|
+
|
|
133
|
+
The SAT publishes the taxpayers it presumes issue invoices for non-existent operations (article 69-B of the Código Fiscal de la Federación). Download the file once and check your suppliers against it, offline:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
curl -o Listado_completo_69-B.csv http://omawww.sat.gob.mx/cifras_sat/Documents/Listado_completo_69-B.csv
|
|
137
|
+
cfdi-kit risk PATHS --list Listado_completo_69-B.csv [--rfc RFC]
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
```text
|
|
141
|
+
$ cfdi-kit risk examples/demo --list examples/demo-69b.csv --rfc CACX7605101P8
|
|
142
|
+
Definitivo KIJ0906199R1 2026-01-04 AF67D461-E416-3207-D094-499602F0EE99 1,044.00 MXN KERNEL INDUSTIA JUGUETERA
|
|
143
|
+
Presunto MAG041126GT8 2026-02-17 D1711CBD-2106-119E-C40D-31B5397A7623 522.00 MXN MINERA AGUILAR
|
|
144
|
+
...
|
|
145
|
+
29 match(es) against the 69-B list dated 2025-12-31, 18 presumed or definitive
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`examples/demo-69b.csv` is a synthetic list for the demo invoices, not the SAT's. With the real file (14,234 rows, dated 31 December 2025), the same 63 demo invoices are checked in about 0.3 seconds.
|
|
149
|
+
|
|
150
|
+
- The command reads one local file and your invoices; it never goes online. Download the list yourself and note its date: it is printed with every result.
|
|
151
|
+
- Each invoice whose **issuer** is on the list is shown with the SAT's status: `Definitivo`, `Presunto`, `Desvirtuado` or `Sentencia Favorable`. With `--rfc`, only invoices you received are checked.
|
|
152
|
+
- The SAT file can list one RFC in several rows (separate proceedings, for example `Definitivo` and `Sentencia Favorable`). The rows are not in chronological order, so a result shows the most serious one and a later row never clears an earlier one.
|
|
153
|
+
- The command exits with status 1 if any match is `Presunto` or `Definitivo`.
|
|
154
|
+
- `report --risk-list FILE` adds the same table to the HTML report.
|
|
155
|
+
|
|
156
|
+
A match is a coincidence with a public list, not an accusation. The list changes, taxpayers can be cleared, and the tool does not replace an accountant.
|
|
157
|
+
|
|
158
|
+
## Python API
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from pathlib import Path
|
|
162
|
+
|
|
163
|
+
import cfdi_kit
|
|
164
|
+
|
|
165
|
+
result = cfdi_kit.load(["examples/demo"]) # files, folders or ZIPs
|
|
166
|
+
print(len(result.cfdis), "invoices,", len(result.errors), "errors")
|
|
167
|
+
|
|
168
|
+
cfdi = result.cfdis[0]
|
|
169
|
+
cfdi.uuid, cfdi.issuer.rfc, cfdi.total, cfdi.iva_transferred # typed, Decimal
|
|
170
|
+
|
|
171
|
+
invoices = cfdi_kit.invoices_frame(result.cfdis, rfc="CACX7605101P8") # pandas
|
|
172
|
+
invoices.groupby("direction")["total_mxn"].sum()
|
|
173
|
+
|
|
174
|
+
summary = cfdi_kit.summarize(result.cfdis, "CACX7605101P8", cfdi_kit.Basis.CASH)
|
|
175
|
+
cfdi_kit.summary_frame(summary)
|
|
176
|
+
|
|
177
|
+
issues = cfdi_kit.validate(result.cfdis)
|
|
178
|
+
|
|
179
|
+
snapshot = cfdi_kit.load_snapshot(Path("Listado_completo_69-B.csv")) # your own download
|
|
180
|
+
matches = cfdi_kit.find_matches(result.cfdis, snapshot, rfc="CACX7605101P8")
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Also available: `parse_file`, `parse_bytes`, `concepts_frame`, `payments_frame`, `to_csv` and `to_excel`. The package ships type hints (`py.typed`).
|
|
184
|
+
|
|
185
|
+
## Limits
|
|
186
|
+
|
|
187
|
+
- It reads the XML only. It does not verify the digital seals or ask the SAT whether an invoice was cancelled; remove cancelled invoices before summarizing.
|
|
188
|
+
- The summary is an aid to review a period. It is not a tax return and does not replace an accountant.
|
|
189
|
+
- It does not issue, stamp, cancel or download invoices, and it does not download the 69-B list for you.
|
|
190
|
+
|
|
191
|
+
## Development
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
uv sync
|
|
195
|
+
uv run pytest
|
|
196
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy .
|
|
197
|
+
uv run python examples/generate_demo.py examples/demo # regenerate the demo invoices
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
The test fixtures and demo invoices are synthetic and use the SAT's public test RFCs. See [CONTRIBUTING.md](https://github.com/DiegoTepichin/cfdi-kit/blob/main/CONTRIBUTING.md). A CFDI that fails to parse is the most useful bug report you can send: anonymize it and open an issue.
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
[MIT](https://github.com/DiegoTepichin/cfdi-kit/blob/main/LICENSE) © Diego Tepichin
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# cfdi-kit
|
|
2
|
+
|
|
3
|
+
Convierte una carpeta de facturas CFDI del SAT (XML) en Excel, DataFrames de pandas, un resumen mensual de ingresos, gastos e IVA y un reporte HTML de un solo archivo. Todo corre en tu computadora; ningún dato de tus facturas sale de ella.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/DiegoTepichin/cfdi-kit/actions/workflows/ci.yml)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
[Read in English](README.md)
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
*`cfdi-kit report` sobre las facturas sintéticas de [`examples/demo`](examples/demo).*
|
|
13
|
+
|
|
14
|
+
## Por qué
|
|
15
|
+
|
|
16
|
+
Cada factura en México es un XML. Revisar un mes implica abrir archivos uno por uno, capturar montos a mano en Excel o subir tu información fiscal a un servicio en la nube. `cfdi-kit` lee cientos de CFDIs en un segundo, directo de la carpeta o del ZIP que descargas del portal del SAT, sin que salgan de tu equipo.
|
|
17
|
+
|
|
18
|
+
## Instalación
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install cfdi-kit
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
o sin instalar, con [uv](https://docs.astral.sh/uv/):
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
uvx cfdi-kit --help
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Requiere Python 3.11 o superior.
|
|
31
|
+
|
|
32
|
+
## Inicio rápido
|
|
33
|
+
|
|
34
|
+
Pruébalo con las facturas de ejemplo (una persona freelance ficticia, RFC `CACX7605101P8`, un año de facturas):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/DiegoTepichin/cfdi-kit && cd cfdi-kit
|
|
38
|
+
uv run cfdi-kit summary examples/demo --rfc CACX7605101P8 --basis cash
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
CACX7605101P8 · cash basis · MXN
|
|
43
|
+
|
|
44
|
+
Month Income VAT charged VAT withheld Expenses VAT creditable Net VAT
|
|
45
|
+
------- --------- ----------- ------------ --------- -------------- --------
|
|
46
|
+
2026-01 61,000.00 9,760.00 4,160.01 2,500.00 400.00 5,199.99
|
|
47
|
+
2026-02 26,500.00 4,240.00 0.00 2,400.00 384.00 3,856.00
|
|
48
|
+
2026-03 74,000.00 11,840.00 7,893.36 28,700.00 4,592.00 -645.36
|
|
49
|
+
...
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Con tus propias facturas:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
cfdi-kit parse ~/Downloads/facturas -o facturas.xlsx --rfc TU_RFC # Excel con 3 hojas
|
|
56
|
+
cfdi-kit summary ~/Downloads/facturas --rfc TU_RFC # tabla mensual
|
|
57
|
+
cfdi-kit report ~/Downloads/facturas --rfc TU_RFC -o reporte.html # reporte HTML
|
|
58
|
+
cfdi-kit validate ~/Downloads/facturas # validaciones
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Todos los comandos aceptan cualquier combinación de archivos `.xml`, carpetas (se buscan de forma recursiva) y archivos `.zip`. Los archivos ilegibles se listan y se omiten; los UUID repetidos se cuentan una sola vez.
|
|
62
|
+
|
|
63
|
+
## Qué lee
|
|
64
|
+
|
|
65
|
+
| | Soportado |
|
|
66
|
+
|---|---|
|
|
67
|
+
| CFDI | 4.0 y 3.3 (tipos I, E, T, N y P) |
|
|
68
|
+
| Complementos | Timbre Fiscal Digital 1.1, Pagos 2.0 y 1.0, Nómina 1.2 |
|
|
69
|
+
| Dinero | `Decimal` de principio a fin; moneda extranjera convertida con el tipo de cambio de la factura o del pago |
|
|
70
|
+
|
|
71
|
+
CFDI 3.2 y anteriores se reportan como no soportados.
|
|
72
|
+
|
|
73
|
+
## Comandos
|
|
74
|
+
|
|
75
|
+
### `parse`: Excel o CSV
|
|
76
|
+
|
|
77
|
+
`cfdi-kit parse RUTAS -o salida.xlsx [--rfc RFC]` escribe tres hojas: `invoices` (una fila por CFDI, con impuestos, totales en MXN y descripciones de los catálogos del SAT), `line_items` (conceptos) y `payments` (cada factura liquidada en un complemento de pago). Con `-o salida.csv` escribe solo la tabla de facturas. `--rfc` agrega la columna `direction` (`issued` emitida / `received` recibida). El texto de las facturas viene de terceros: en Excel se guarda como texto, nunca como fórmula; en CSV, el texto que empieza con `=`, `+`, `-`, `@`, tabulador o salto de línea lleva un apóstrofo al inicio.
|
|
78
|
+
|
|
79
|
+
### `summary`: ingresos, gastos e IVA por mes
|
|
80
|
+
|
|
81
|
+
`cfdi-kit summary RUTAS --rfc RFC [--basis accrual|cash] [-o archivo]`
|
|
82
|
+
|
|
83
|
+
- **accrual** (por defecto): cada factura cuenta en su fecha de emisión.
|
|
84
|
+
- **cash** (flujo de efectivo): las facturas `PUE` cuentan en su fecha de emisión; las `PPD`, cuando un complemento de pago las liquida, en la fecha del pago. El desglose de impuestos de Pagos 2.0 se usa tal cual; los pagos de Pagos 1.0 se prorratean contra la factura original si está en la carpeta.
|
|
85
|
+
|
|
86
|
+
Las notas de crédito (`E`) restan. La nómina (`N`) se reporta en columnas aparte. *Net VAT* es el IVA trasladado, menos el IVA que te retuvieron tus clientes, menos el IVA acreditable.
|
|
87
|
+
|
|
88
|
+
### `report`: un archivo HTML
|
|
89
|
+
|
|
90
|
+
`cfdi-kit report RUTAS --rfc RFC [--basis] [-o reporte.html]` escribe un solo archivo sin scripts ni recursos externos: totales, gráfica de ingresos contra gastos, tabla mensual, principales clientes y proveedores, facturas PPD con saldo pendiente y todas las observaciones de la validación. Respeta el tema claro u oscuro del sistema.
|
|
91
|
+
|
|
92
|
+
### `validate`: encuentra errores antes de que lleguen a tu contabilidad
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
$ cfdi-kit validate broken.xml
|
|
96
|
+
error total-mismatch broken.xml Total is 99999.99 but SubTotal - Descuento + taxes is 34796.65
|
|
97
|
+
1 error(s), 0 warning(s)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Revisa: timbre faltante; total, subtotal o descuento que no cuadran (se permite un centavo de redondeo por concepto); impuestos de la factura contra los de los conceptos; RFC mal formados; facturas PPD con forma de pago distinta de 99; moneda extranjera sin tipo de cambio y UUID duplicados. Termina con código 1 si encuentra errores, para usarlo en scripts.
|
|
101
|
+
|
|
102
|
+
### `risk`: revisa a tus proveedores contra la lista 69-B del SAT
|
|
103
|
+
|
|
104
|
+
El SAT publica a los contribuyentes que presume emiten facturas por operaciones inexistentes (artículo 69-B del Código Fiscal de la Federación). Descarga el archivo una vez y revisa a tus proveedores sin conexión:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
curl -o Listado_completo_69-B.csv http://omawww.sat.gob.mx/cifras_sat/Documents/Listado_completo_69-B.csv
|
|
108
|
+
cfdi-kit risk RUTAS --list Listado_completo_69-B.csv [--rfc RFC]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```text
|
|
112
|
+
$ cfdi-kit risk examples/demo --list examples/demo-69b.csv --rfc CACX7605101P8
|
|
113
|
+
Definitivo KIJ0906199R1 2026-01-04 AF67D461-E416-3207-D094-499602F0EE99 1,044.00 MXN KERNEL INDUSTIA JUGUETERA
|
|
114
|
+
Presunto MAG041126GT8 2026-02-17 D1711CBD-2106-119E-C40D-31B5397A7623 522.00 MXN MINERA AGUILAR
|
|
115
|
+
...
|
|
116
|
+
29 match(es) against the 69-B list dated 2025-12-31, 18 presumed or definitive
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`examples/demo-69b.csv` es una lista sintética para las facturas de demostración, no la del SAT. Con el archivo real (14,234 filas, con fecha del 31 de diciembre de 2025), las mismas 63 facturas de la demo se revisan en unos 0.3 segundos.
|
|
120
|
+
|
|
121
|
+
- El comando lee un archivo local y tus facturas; nunca se conecta a internet. Descarga tú la lista y anota su fecha: se imprime con cada resultado.
|
|
122
|
+
- Cada factura cuyo **emisor** está en la lista se muestra con el estatus del SAT: `Definitivo`, `Presunto`, `Desvirtuado` o `Sentencia Favorable`. Con `--rfc`, solo se revisan las facturas que recibiste.
|
|
123
|
+
- El archivo del SAT puede listar un RFC en varias filas (trámites distintos, por ejemplo `Definitivo` y `Sentencia Favorable`). Las filas no están en orden cronológico, así que el resultado muestra la más grave y una fila posterior nunca absuelve a una anterior.
|
|
124
|
+
- El comando termina con estado 1 si alguna coincidencia es `Presunto` o `Definitivo`.
|
|
125
|
+
- `report --risk-list ARCHIVO` agrega la misma tabla al reporte HTML.
|
|
126
|
+
|
|
127
|
+
Una coincidencia es una coincidencia con una lista pública, no una acusación. La lista cambia, los contribuyentes pueden desvirtuar y la herramienta no sustituye a un contador.
|
|
128
|
+
|
|
129
|
+
## API de Python
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from pathlib import Path
|
|
133
|
+
|
|
134
|
+
import cfdi_kit
|
|
135
|
+
|
|
136
|
+
result = cfdi_kit.load(["examples/demo"]) # archivos, carpetas o ZIPs
|
|
137
|
+
print(len(result.cfdis), "invoices,", len(result.errors), "errors")
|
|
138
|
+
|
|
139
|
+
cfdi = result.cfdis[0]
|
|
140
|
+
cfdi.uuid, cfdi.issuer.rfc, cfdi.total, cfdi.iva_transferred # tipado, Decimal
|
|
141
|
+
|
|
142
|
+
invoices = cfdi_kit.invoices_frame(result.cfdis, rfc="CACX7605101P8") # pandas
|
|
143
|
+
invoices.groupby("direction")["total_mxn"].sum()
|
|
144
|
+
|
|
145
|
+
summary = cfdi_kit.summarize(result.cfdis, "CACX7605101P8", cfdi_kit.Basis.CASH)
|
|
146
|
+
cfdi_kit.summary_frame(summary)
|
|
147
|
+
|
|
148
|
+
issues = cfdi_kit.validate(result.cfdis)
|
|
149
|
+
|
|
150
|
+
snapshot = cfdi_kit.load_snapshot(Path("Listado_completo_69-B.csv")) # tu propia descarga
|
|
151
|
+
matches = cfdi_kit.find_matches(result.cfdis, snapshot, rfc="CACX7605101P8")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
También: `parse_file`, `parse_bytes`, `concepts_frame`, `payments_frame`, `to_csv` y `to_excel`. El paquete incluye anotaciones de tipos (`py.typed`).
|
|
155
|
+
|
|
156
|
+
## Límites
|
|
157
|
+
|
|
158
|
+
- Solo lee el XML. No verifica los sellos digitales ni consulta al SAT si una factura fue cancelada; quita las canceladas antes de resumir.
|
|
159
|
+
- El resumen es una ayuda para revisar un periodo. No es una declaración y no sustituye a tu contador.
|
|
160
|
+
- No emite, timbra, cancela ni descarga facturas, ni descarga por ti la lista 69-B.
|
|
161
|
+
|
|
162
|
+
## Desarrollo
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
uv sync
|
|
166
|
+
uv run pytest
|
|
167
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy .
|
|
168
|
+
uv run python examples/generate_demo.py examples/demo # regenera las facturas de ejemplo
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Los fixtures de prueba y las facturas de ejemplo son sintéticos y usan los RFC de prueba públicos del SAT. Ver [CONTRIBUTING.md](CONTRIBUTING.md). Un CFDI que no se puede leer es el reporte de bug más útil: anonimízalo y abre un issue.
|
|
172
|
+
|
|
173
|
+
## Licencia
|
|
174
|
+
|
|
175
|
+
[MIT](LICENSE) © Diego Tepichin
|