fec-validator-excel 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,52 @@
1
+ """Zero-dependency French FEC (Fichier des Ecritures Comptables) parser and DGFiP validator."""
2
+ import csv, datetime as dt, re
3
+ from collections import defaultdict
4
+ from decimal import Decimal, InvalidOperation
5
+
6
+ __version__ = "0.1.0"
7
+ __all__ = ["parse_fec", "FEC_REQUIRED"]
8
+
9
+ FEC_REQUIRED = [
10
+ "JournalCode", "JournalLib", "EcritureNum", "EcritureDate", "CompteNum",
11
+ "CompteLib", "CompAuxNum", "CompAuxLib", "PieceRef", "PieceDate",
12
+ "EcritureLib", "Debit", "Credit", "EcritureLet", "DateLet",
13
+ "ValidDate", "Montantdevise", "Idevise",
14
+ ]
15
+
16
+ def _dec(s):
17
+ s = (s or "").strip().strip('"').replace(" ", "")
18
+ if not s: return Decimal("0.00")
19
+ if "," in s and "." in s:
20
+ s = s.replace(".", "").replace(",", ".") if s.rfind(",") > s.rfind(".") else s.replace(",", "")
21
+ elif "," in s:
22
+ s = s.replace(",", ".")
23
+ try: return Decimal(s)
24
+ except InvalidOperation: return None
25
+
26
+ def parse_fec(data):
27
+ text = data.decode("utf-8-sig", errors="replace") if isinstance(data, (bytes, bytearray)) else str(data)
28
+ lines = [ln for ln in text.splitlines() if ln.strip()]
29
+ if len(lines) < 2: raise ValueError("FEC file must have a header and at least one entry.")
30
+ delim = max(("\t", "|", ";", ","), key=lambda d: lines[0].count(d))
31
+ reader = list(csv.reader(lines, delimiter=delim, quotechar='"'))
32
+ hdr = {c.strip().lower(): i for i, c in enumerate(reader[0])}
33
+ issues = []
34
+ miss = [c for c in FEC_REQUIRED if c.lower() not in hdr]
35
+ if miss: issues.append(f"Missing DGFiP columns ({len(miss)}): {', '.join(miss[:5])}")
36
+ rows, bal = [], defaultdict(lambda: [Decimal("0.00"), Decimal("0.00")])
37
+ for ln_no, raw in enumerate(reader[1:], start=2):
38
+ if not any(c.strip() for c in raw): continue
39
+ g = lambda col: raw[hdr[col.lower()]].strip() if col.lower() in hdr and hdr[col.lower()] < len(raw) else ""
40
+ deb, cred = _dec(g("Debit")), _dec(g("Credit"))
41
+ if deb is None or cred is None:
42
+ issues.append(f"Row {ln_no}: invalid Debit/Credit"); continue
43
+ ed = g("EcritureDate")
44
+ iso = f"{ed[:4]}-{ed[4:6]}-{ed[6:8]}" if re.fullmatch(r"\d{8}", ed) else ed
45
+ enum = g("EcritureNum")
46
+ bal[enum][0] += deb; bal[enum][1] += cred
47
+ rows.append({"journal": g("JournalCode"), "ecriture_num": enum, "date": iso, "compte": g("CompteNum"),
48
+ "compte_lib": g("CompteLib"), "piece_ref": g("PieceRef"), "libelle": g("EcritureLib"),
49
+ "debit": float(deb), "credit": float(cred), "net": float(deb - cred)})
50
+ unbal = [e for e, (d, c) in bal.items() if d != c]
51
+ if unbal: issues.append(f"{len(unbal)} unbalanced EcritureNum: {', '.join(unbal[:5])}")
52
+ return rows, issues, len(bal)
@@ -0,0 +1,16 @@
1
+ import argparse, csv, json, sys
2
+ from pathlib import Path
3
+ from . import parse_fec
4
+
5
+ def main(argv=None):
6
+ ap = argparse.ArgumentParser(description="Validate & convert French FEC accounting files.")
7
+ ap.add_argument("file"); ap.add_argument("--format", choices=["json", "csv"], default="json")
8
+ args = ap.parse_args(argv)
9
+ rows, issues, n = parse_fec(Path(args.file).read_bytes())
10
+ if args.format == "json":
11
+ print(json.dumps({"entries": n, "issues": issues, "rows": rows}, indent=2, ensure_ascii=False))
12
+ else:
13
+ w = csv.DictWriter(sys.stdout, fieldnames=["journal","ecriture_num","date","compte","compte_lib","piece_ref","libelle","debit","credit","net"])
14
+ w.writeheader(); w.writerows(rows)
15
+
16
+ if __name__ == "__main__": main()
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: fec-validator-excel
3
+ Version: 0.1.0
4
+ Summary: Zero-dependency Python parser, DGFiP validator and CLI for French FEC (Fichier des Ecritures Comptables) accounting files.
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://radarbg.com/instant/fec-to-excel?ref=pypi-fec
7
+ Project-URL: French FEC to Excel Online, https://radarbg.com/instant/fec-to-excel?ref=pypi-fec
8
+ Project-URL: RadarBG Accounting Tools, https://radarbg.com/instant?ref=pypi
9
+ Keywords: fec,dgfip,france,accounting,comptabilite,excel,csv,validator,parser
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Topic :: Office/Business :: Financial :: Accounting
13
+ Classifier: Intended Audience :: Developers
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Dynamic: license-file
18
+
19
+ # fec-validator-excel
20
+
21
+ Zero-dependency Python parser, DGFiP validator, and CLI for French **FEC (Fichier des Écritures Comptables)** accounting files.
22
+
23
+ Need an instant browser tool to validate DGFiP rules and export formatted **Excel (.xlsx with Balance_Comptes & Controle_DGFiP tabs), Xero, or QuickBooks CSV**?
24
+ 👉 Use **[radarbg.com/instant/fec-to-excel](https://radarbg.com/instant/fec-to-excel?ref=pypi-fec)**
25
+
26
+ ## Install
27
+ ```bash
28
+ pip install fec-validator-excel
29
+ ```
30
+
31
+ ## Usage
32
+ ```python
33
+ from fec_validator_excel import parse_fec
34
+ rows, issues, n_entries = parse_fec(open("123456789FEC20261115.txt", "rb").read())
35
+ print(len(rows), "lines,", n_entries, "entries, issues:", issues)
36
+ ```
37
+ ```bash
38
+ fec-validator-excel 123456789FEC20261115.txt --format json
39
+ ```
@@ -0,0 +1,8 @@
1
+ fec_validator_excel/__init__.py,sha256=5HRYly1rcHTqCTXp2410w6QwB8qLa_cmkTdFXK-_jiY,2723
2
+ fec_validator_excel/__main__.py,sha256=leAYUKrMFfFmHvRDAViLkfL-ZIzTlrEeEii6FjNHJ7I,764
3
+ fec_validator_excel-0.1.0.dist-info/licenses/LICENSE,sha256=9ERzIE2W8I4Dl6NXsK42aks5foFxSXUeayLz795TQWo,624
4
+ fec_validator_excel-0.1.0.dist-info/METADATA,sha256=irgDnYGIe93oQz2lW3XkLZrXQOCQjGiRAN6Px1KD-zI,1615
5
+ fec_validator_excel-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ fec_validator_excel-0.1.0.dist-info/entry_points.txt,sha256=NtPcasdv-wqxe4fJaD4AqMMLg9RsVZrEfowpq7mdd7w,74
7
+ fec_validator_excel-0.1.0.dist-info/top_level.txt,sha256=bTuhTaH0CiAxWfZF9F8LvJZHOkXJYbhMgMNm3gXLq0k,20
8
+ fec_validator_excel-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ fec-validator-excel = fec_validator_excel.__main__:main
@@ -0,0 +1,13 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RadarBG (https://radarbg.com)
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.
@@ -0,0 +1 @@
1
+ fec_validator_excel