datev-extf-parser 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.
- datev_extf_parser/__init__.py +174 -0
- datev_extf_parser/__main__.py +32 -0
- datev_extf_parser-0.1.0.dist-info/METADATA +67 -0
- datev_extf_parser-0.1.0.dist-info/RECORD +8 -0
- datev_extf_parser-0.1.0.dist-info/WHEEL +5 -0
- datev_extf_parser-0.1.0.dist-info/entry_points.txt +2 -0
- datev_extf_parser-0.1.0.dist-info/licenses/LICENSE +13 -0
- datev_extf_parser-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"""Zero-dependency parser and validator for German & Austrian DATEV EXTF / Buchungsstapel CSV files."""
|
|
2
|
+
import csv
|
|
3
|
+
import datetime as dt
|
|
4
|
+
import re
|
|
5
|
+
from decimal import Decimal, InvalidOperation
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.0"
|
|
8
|
+
__all__ = ["parse_datev_extf"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _decode(data, encodings=("utf-8-sig", "cp1252", "latin-1")):
|
|
12
|
+
if isinstance(data, str):
|
|
13
|
+
return data
|
|
14
|
+
for enc in encodings:
|
|
15
|
+
try:
|
|
16
|
+
return data.decode(enc)
|
|
17
|
+
except UnicodeDecodeError:
|
|
18
|
+
continue
|
|
19
|
+
return data.decode("latin-1", errors="replace")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _parse_de_decimal(s):
|
|
23
|
+
s = (s or "").strip().strip('"').replace(" ", "")
|
|
24
|
+
if not s:
|
|
25
|
+
return None
|
|
26
|
+
if "," in s and "." in s:
|
|
27
|
+
s = s.replace(".", "").replace(",", ".") if s.rfind(",") > s.rfind(".") else s.replace(",", "")
|
|
28
|
+
elif "," in s:
|
|
29
|
+
s = s.replace(",", ".")
|
|
30
|
+
try:
|
|
31
|
+
return Decimal(s)
|
|
32
|
+
except InvalidOperation:
|
|
33
|
+
return None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _parse_belegdatum(val, ref_year):
|
|
37
|
+
s = (val or "").strip().strip('"')
|
|
38
|
+
if not s:
|
|
39
|
+
return None
|
|
40
|
+
m = re.fullmatch(r"(\d{4})-(\d{2})-(\d{2})", s)
|
|
41
|
+
if m:
|
|
42
|
+
try:
|
|
43
|
+
return dt.date(int(m.group(1)), int(m.group(2)), int(m.group(3)))
|
|
44
|
+
except ValueError:
|
|
45
|
+
return None
|
|
46
|
+
m = re.fullmatch(r"(\d{1,2})\.(\d{1,2})\.(\d{2,4})", s)
|
|
47
|
+
if m:
|
|
48
|
+
y = int(m.group(3))
|
|
49
|
+
if y < 100:
|
|
50
|
+
y += 2000
|
|
51
|
+
try:
|
|
52
|
+
return dt.date(y, int(m.group(2)), int(m.group(1)))
|
|
53
|
+
except ValueError:
|
|
54
|
+
return None
|
|
55
|
+
if re.fullmatch(r"\d{3,4}", s):
|
|
56
|
+
s4 = s.zfill(4)
|
|
57
|
+
try:
|
|
58
|
+
return dt.date(ref_year, int(s4[2:]), int(s4[:2]))
|
|
59
|
+
except ValueError:
|
|
60
|
+
return None
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _yyyymmdd(s):
|
|
65
|
+
s = (s or "").strip().strip('"')
|
|
66
|
+
if re.fullmatch(r"\d{8}", s):
|
|
67
|
+
try:
|
|
68
|
+
return dt.date(int(s[:4]), int(s[4:6]), int(s[6:8]))
|
|
69
|
+
except ValueError:
|
|
70
|
+
return None
|
|
71
|
+
return None
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def parse_datev_extf(data):
|
|
75
|
+
"""Parse DATEV EXTF / Buchungsstapel bytes or str -> (meta, rows, issues)."""
|
|
76
|
+
text = _decode(data)
|
|
77
|
+
lines = [ln for ln in text.splitlines() if ln.strip()]
|
|
78
|
+
if not lines:
|
|
79
|
+
raise ValueError("Empty DATEV file.")
|
|
80
|
+
|
|
81
|
+
delim = ";" if lines[0].count(";") >= lines[0].count(",") else ","
|
|
82
|
+
reader = list(csv.reader(lines, delimiter=delim, quotechar='"'))
|
|
83
|
+
meta = {
|
|
84
|
+
"format": "CSV", "version": "", "category": "", "berater": "", "mandant": "",
|
|
85
|
+
"wj_beginn": "", "sachkontenlaenge": None, "datum_von": "", "datum_bis": "",
|
|
86
|
+
"bezeichnung": "", "currency": "EUR",
|
|
87
|
+
}
|
|
88
|
+
issues = []
|
|
89
|
+
idx = 0
|
|
90
|
+
first_cell = (reader[0][0] if reader[0] else "").strip().upper()
|
|
91
|
+
if first_cell in ("EXTF", "DTVF"):
|
|
92
|
+
hdr = reader[0]
|
|
93
|
+
meta["format"] = first_cell
|
|
94
|
+
meta["version"] = hdr[1].strip() if len(hdr) > 1 else ""
|
|
95
|
+
meta["category"] = hdr[3].strip() if len(hdr) > 3 else ""
|
|
96
|
+
meta["berater"] = hdr[10].strip() if len(hdr) > 10 else ""
|
|
97
|
+
meta["mandant"] = hdr[11].strip() if len(hdr) > 11 else ""
|
|
98
|
+
meta["wj_beginn"] = hdr[12].strip() if len(hdr) > 12 else ""
|
|
99
|
+
if len(hdr) > 13 and hdr[13].strip().isdigit():
|
|
100
|
+
meta["sachkontenlaenge"] = int(hdr[13].strip())
|
|
101
|
+
meta["datum_von"] = hdr[14].strip() if len(hdr) > 14 else ""
|
|
102
|
+
meta["datum_bis"] = hdr[15].strip() if len(hdr) > 15 else ""
|
|
103
|
+
meta["bezeichnung"] = hdr[16].strip() if len(hdr) > 16 else ""
|
|
104
|
+
if len(hdr) > 22 and hdr[22].strip():
|
|
105
|
+
meta["currency"] = hdr[22].strip().upper()
|
|
106
|
+
idx = 1
|
|
107
|
+
|
|
108
|
+
if idx >= len(reader):
|
|
109
|
+
raise ValueError("DATEV file has no column header or booking rows.")
|
|
110
|
+
|
|
111
|
+
col_lower = [c.strip().lower() for c in reader[idx]]
|
|
112
|
+
|
|
113
|
+
def _find(*needles):
|
|
114
|
+
for n in needles:
|
|
115
|
+
for i, cl in enumerate(col_lower):
|
|
116
|
+
if n in cl:
|
|
117
|
+
return i
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
c_amt = _find("umsatz")
|
|
121
|
+
c_sh = _find("soll/haben-kennzeichen", "soll/haben-kz", "s/h-kennzeichen", "s/h")
|
|
122
|
+
if c_sh == c_amt:
|
|
123
|
+
c_sh = next((i for i, cl in enumerate(col_lower) if i != c_amt and ("soll/haben" in cl or "s/h" in cl)), None)
|
|
124
|
+
c_wkz = _find("wkz umsatz", "wkz")
|
|
125
|
+
c_konto = next((i for i, cl in enumerate(col_lower) if cl == "konto" or (cl.startswith("konto") and "gegen" not in cl)), None)
|
|
126
|
+
c_gkonto = _find("gegenkonto")
|
|
127
|
+
c_bu = _find("bu-schl", "bu-schlüssel")
|
|
128
|
+
c_date = _find("belegdatum")
|
|
129
|
+
c_bel1 = _find("belegfeld 1")
|
|
130
|
+
c_text = _find("buchungstext")
|
|
131
|
+
c_kost1 = _find("kost1")
|
|
132
|
+
|
|
133
|
+
if c_amt is None or (c_konto is None and c_gkonto is None):
|
|
134
|
+
raise ValueError("Not a recognized DATEV Buchungsstapel CSV.")
|
|
135
|
+
|
|
136
|
+
d_von = _yyyymmdd(meta["datum_von"]) or _yyyymmdd(meta["wj_beginn"])
|
|
137
|
+
ref_year = d_von.year if d_von else dt.date.today().year
|
|
138
|
+
skl = meta["sachkontenlaenge"]
|
|
139
|
+
rows = []
|
|
140
|
+
|
|
141
|
+
for line_no, raw_row in enumerate(reader[idx + 1:], start=idx + 2):
|
|
142
|
+
if not any(cell.strip() for cell in raw_row):
|
|
143
|
+
continue
|
|
144
|
+
get = lambda ci: "" if (ci is None or ci >= len(raw_row)) else raw_row[ci].strip()
|
|
145
|
+
amt_dec = _parse_de_decimal(get(c_amt))
|
|
146
|
+
if amt_dec is None:
|
|
147
|
+
issues.append(f"Row {line_no}: invalid amount '{get(c_amt)}'")
|
|
148
|
+
continue
|
|
149
|
+
sh = get(c_sh).upper() or "S"
|
|
150
|
+
if sh not in ("S", "H"):
|
|
151
|
+
issues.append(f"Row {line_no}: unexpected Soll/Haben '{sh}'")
|
|
152
|
+
signed = amt_dec if sh == "S" else -amt_dec
|
|
153
|
+
konto, gkonto = get(c_konto), get(c_gkonto)
|
|
154
|
+
if not konto or not gkonto:
|
|
155
|
+
issues.append(f"Row {line_no}: missing Konto or Gegenkonto")
|
|
156
|
+
elif skl and konto.isdigit() and len(konto) < skl:
|
|
157
|
+
issues.append(f"Row {line_no}: Konto '{konto}' shorter than Sachkontenlaenge {skl}")
|
|
158
|
+
bdate = _parse_belegdatum(get(c_date), ref_year)
|
|
159
|
+
if get(c_date) and bdate is None:
|
|
160
|
+
issues.append(f"Row {line_no}: invalid Belegdatum '{get(c_date)}'")
|
|
161
|
+
rows.append({
|
|
162
|
+
"date": bdate.isoformat() if bdate else get(c_date),
|
|
163
|
+
"beleg1": get(c_bel1),
|
|
164
|
+
"konto": konto,
|
|
165
|
+
"gegenkonto": gkonto,
|
|
166
|
+
"bu": get(c_bu),
|
|
167
|
+
"sh": sh,
|
|
168
|
+
"signed_amount": float(signed),
|
|
169
|
+
"currency": (get(c_wkz) or meta["currency"] or "EUR").upper(),
|
|
170
|
+
"text": get(c_text),
|
|
171
|
+
"kost1": get(c_kost1),
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
return meta, rows, issues
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import csv
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from . import parse_datev_extf
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main(argv=None):
|
|
10
|
+
ap = argparse.ArgumentParser(description="Parse and validate DATEV EXTF / Buchungsstapel CSV files.")
|
|
11
|
+
ap.add_argument("file", help="Path to DATEV EXTF CSV file")
|
|
12
|
+
ap.add_argument("--format", choices=["csv", "json"], default="json")
|
|
13
|
+
ap.add_argument("-o", "--output", help="Output file (default: stdout)")
|
|
14
|
+
args = ap.parse_args(argv)
|
|
15
|
+
meta, rows, issues = parse_datev_extf(Path(args.file).read_bytes())
|
|
16
|
+
out = open(args.output, "w", encoding="utf-8", newline="") if args.output else sys.stdout
|
|
17
|
+
try:
|
|
18
|
+
if args.format == "json":
|
|
19
|
+
json.dump({"meta": meta, "issues": issues, "bookings": rows}, out, indent=2, ensure_ascii=False)
|
|
20
|
+
out.write("\n")
|
|
21
|
+
else:
|
|
22
|
+
cols = ["date", "beleg1", "konto", "gegenkonto", "bu", "sh", "signed_amount", "currency", "text", "kost1"]
|
|
23
|
+
w = csv.DictWriter(out, fieldnames=cols)
|
|
24
|
+
w.writeheader()
|
|
25
|
+
w.writerows(rows)
|
|
26
|
+
finally:
|
|
27
|
+
if args.output:
|
|
28
|
+
out.close()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if __name__ == "__main__":
|
|
32
|
+
main()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datev-extf-parser
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Zero-dependency Python parser, validator and CLI for German & Austrian DATEV EXTF / Buchungsstapel CSV files (signed Soll/Haben amounts, ISO dates, CSV/Xero/JSON export).
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://radarbg.com/instant/datev-to-excel?ref=pypi-datev
|
|
7
|
+
Project-URL: DATEV to Excel Online, https://radarbg.com/instant/datev-to-excel?ref=pypi-datev
|
|
8
|
+
Project-URL: CAMT.053 & MT940 Converter, https://radarbg.com/instant/camt053-to-excel?ref=pypi-datev
|
|
9
|
+
Project-URL: XRechnung & ZUGFeRD Reader, https://radarbg.com/instant/einvoice-to-excel?ref=pypi-datev
|
|
10
|
+
Keywords: datev,extf,buchungsstapel,accounting,steuerberater,germany,austria,csv,excel,parser
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Office/Business :: Financial :: Accounting
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Requires-Python: >=3.8
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# datev-extf-parser
|
|
22
|
+
|
|
23
|
+
Zero-dependency Python library and CLI to parse and validate German & Austrian **DATEV EXTF / Buchungsstapel** CSV exports offline.
|
|
24
|
+
|
|
25
|
+
Need an instant browser converter to **formatted Excel (.xlsx) with account totals, validation tab, Xero or QuickBooks CSV** without installing Python?
|
|
26
|
+
👉 Use the online tool at **[radarbg.com/instant/datev-to-excel](https://radarbg.com/instant/datev-to-excel?ref=pypi-datev)**
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
- Parses 2-line **EXTF / DTVF** metadata headers (Beraternummer, Mandantennummer, WJ-Beginn, Sachkontenlänge, Buchungsperiode, WKZ)
|
|
31
|
+
- Converts German decimal commas (`1.234,56`) and `S`/`H` (Soll/Haben) indicators into signed `Decimal` amounts
|
|
32
|
+
- Resolves 4-digit `DDMM` `Belegdatum` against the fiscal year into ISO `YYYY-MM-DD` dates
|
|
33
|
+
- Validates missing accounts, invalid dates, unexpected S/H flags, and `Sachkontenlänge`
|
|
34
|
+
- Zero external dependencies (Python standard library only)
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install datev-extf-parser
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Python Usage
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from datev_extf_parser import parse_datev_extf
|
|
46
|
+
|
|
47
|
+
with open("EXTF_Buchungsstapel.csv", "rb") as f:
|
|
48
|
+
meta, bookings, issues = parse_datev_extf(f.read())
|
|
49
|
+
|
|
50
|
+
print(meta["bezeichnung"], len(bookings), "issues:", len(issues))
|
|
51
|
+
for row in bookings[:5]:
|
|
52
|
+
print(row["date"], row["konto"], "->", row["gegenkonto"], row["signed_amount"], row["text"])
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## CLI Usage
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
datev-extf-parser EXTF_Buchungsstapel.csv --format csv -o bookings.csv
|
|
59
|
+
datev-extf-parser EXTF_Buchungsstapel.csv --format json -o bookings.json
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Related Online Accounting Tools (RadarBG)
|
|
63
|
+
|
|
64
|
+
- [DATEV EXTF to Excel & Validator](https://radarbg.com/instant/datev-to-excel?ref=pypi-datev)
|
|
65
|
+
- [CAMT.053 & MT940 to Excel / CSV](https://radarbg.com/instant/camt053-to-excel?ref=pypi-datev)
|
|
66
|
+
- [XRechnung, ZUGFeRD & Peppol E-Invoice Reader](https://radarbg.com/instant/einvoice-to-excel?ref=pypi-datev)
|
|
67
|
+
- [PDF Bank Statement to Excel](https://radarbg.com/instant/bank-statement-pdf-to-excel?ref=pypi-datev)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
datev_extf_parser/__init__.py,sha256=2vZOPKtKlRgC5hy6xDp65mfqIEfJYbLAs4wzkZ9u3-0,6429
|
|
2
|
+
datev_extf_parser/__main__.py,sha256=9HffZs9rQOgh_mWHWSYEoFCFHrFMb3caqifzuALJ7FM,1170
|
|
3
|
+
datev_extf_parser-0.1.0.dist-info/licenses/LICENSE,sha256=9ERzIE2W8I4Dl6NXsK42aks5foFxSXUeayLz795TQWo,624
|
|
4
|
+
datev_extf_parser-0.1.0.dist-info/METADATA,sha256=gqDZZ5YHWPZn0cO2mAqEPgGHcuAj7C0K7iVpq_3lgss,3102
|
|
5
|
+
datev_extf_parser-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
6
|
+
datev_extf_parser-0.1.0.dist-info/entry_points.txt,sha256=75D7ae1y0pCMJ-GaftJH1v5feQhNPsFgfyDH6LLjpsc,70
|
|
7
|
+
datev_extf_parser-0.1.0.dist-info/top_level.txt,sha256=XGWyY641h3sFVMY3bAyoDUYMhUvhUzXPdsECCPSzpls,18
|
|
8
|
+
datev_extf_parser-0.1.0.dist-info/RECORD,,
|
|
@@ -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
|
+
datev_extf_parser
|