xrechnung-check 0.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bobook Limited
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.
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: xrechnung-check
3
+ Version: 0.1.0
4
+ Summary: CLI for the free XRechnung / ZUGFeRD (EN 16931) validator API at checkxrechnung.com
5
+ Author-email: Bobook Limited <info@bobook.club>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://checkxrechnung.com
8
+ Project-URL: Documentation, https://checkxrechnung.com/en/docs
9
+ Project-URL: Repository, https://github.com/wenboteng/xrechnung-validator
10
+ Project-URL: API waitlist, https://checkxrechnung.com/api-waitlist
11
+ Project-URL: Changelog, https://checkxrechnung.com/changelog
12
+ Keywords: xrechnung,zugferd,e-invoicing,en16931,validator,einvoice,germany
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Office/Business :: Financial
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: requests>=2.31
27
+ Dynamic: license-file
28
+
29
+ # xrechnung-check
30
+
31
+ Command-line client for the free, keyless XRechnung / ZUGFeRD validator API.
32
+
33
+ ```bash
34
+ pip install xrechnung-check
35
+ xrechnung-check invoice.xml
36
+ xrechnung-check invoice.xml --json
37
+ ```
38
+
39
+ Until the package is on PyPI, install it from a checkout:
40
+
41
+ ```bash
42
+ pip install ./cli
43
+ ```
44
+
45
+ `FILE` is an XRechnung XML document (UBL or CII) or a ZUGFeRD PDF. The command posts it as multipart field `file` to `https://checkxrechnung.com/v1/validate`. Python 3.9+. The only dependency is `requests`.
46
+
47
+ No API key. Free limit: 50 validations per IP per UTC day, 10 per minute, 5 MB maximum. HTTP 429 carries `Retry-After`. Higher volume: https://checkxrechnung.com/api-waitlist
48
+
49
+ Human output lists each issue with its rule id and `rule_url`. If the API omits `rule_url`, the CLI uses `https://checkxrechnung.com/fehler/<code>` (lowercase). `--json` prints a normalized report: `valid`, `errors[]` with `rule_id` and `rule_url`, plus summary fields from the API.
50
+
51
+ | Exit | Meaning |
52
+ | --- | --- |
53
+ | 0 | `ok` was true |
54
+ | 1 | the file is invalid, or it is not an e-invoice |
55
+ | 2 | usage error, unreadable file, or the API could not be reached |
56
+
57
+ Docs: https://checkxrechnung.com/en/docs · Rules: https://checkxrechnung.com/fehler/ · OpenAPI: https://checkxrechnung.com/openapi.json
58
+
59
+ MIT. Copyright (c) 2026 Bobook Limited.
@@ -0,0 +1,31 @@
1
+ # xrechnung-check
2
+
3
+ Command-line client for the free, keyless XRechnung / ZUGFeRD validator API.
4
+
5
+ ```bash
6
+ pip install xrechnung-check
7
+ xrechnung-check invoice.xml
8
+ xrechnung-check invoice.xml --json
9
+ ```
10
+
11
+ Until the package is on PyPI, install it from a checkout:
12
+
13
+ ```bash
14
+ pip install ./cli
15
+ ```
16
+
17
+ `FILE` is an XRechnung XML document (UBL or CII) or a ZUGFeRD PDF. The command posts it as multipart field `file` to `https://checkxrechnung.com/v1/validate`. Python 3.9+. The only dependency is `requests`.
18
+
19
+ No API key. Free limit: 50 validations per IP per UTC day, 10 per minute, 5 MB maximum. HTTP 429 carries `Retry-After`. Higher volume: https://checkxrechnung.com/api-waitlist
20
+
21
+ Human output lists each issue with its rule id and `rule_url`. If the API omits `rule_url`, the CLI uses `https://checkxrechnung.com/fehler/<code>` (lowercase). `--json` prints a normalized report: `valid`, `errors[]` with `rule_id` and `rule_url`, plus summary fields from the API.
22
+
23
+ | Exit | Meaning |
24
+ | --- | --- |
25
+ | 0 | `ok` was true |
26
+ | 1 | the file is invalid, or it is not an e-invoice |
27
+ | 2 | usage error, unreadable file, or the API could not be reached |
28
+
29
+ Docs: https://checkxrechnung.com/en/docs · Rules: https://checkxrechnung.com/fehler/ · OpenAPI: https://checkxrechnung.com/openapi.json
30
+
31
+ MIT. Copyright (c) 2026 Bobook Limited.
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "xrechnung-check"
7
+ version = "0.1.0"
8
+ description = "CLI for the free XRechnung / ZUGFeRD (EN 16931) validator API at checkxrechnung.com"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Bobook Limited", email = "info@bobook.club" }]
14
+ keywords = ["xrechnung", "zugferd", "e-invoicing", "en16931", "validator", "einvoice", "germany"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Environment :: Console",
18
+ "Intended Audience :: Developers",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Topic :: Office/Business :: Financial",
26
+ ]
27
+ dependencies = ["requests>=2.31"]
28
+
29
+ [project.urls]
30
+ Homepage = "https://checkxrechnung.com"
31
+ Documentation = "https://checkxrechnung.com/en/docs"
32
+ Repository = "https://github.com/wenboteng/xrechnung-validator"
33
+ "API waitlist" = "https://checkxrechnung.com/api-waitlist"
34
+ Changelog = "https://checkxrechnung.com/changelog"
35
+
36
+ [project.scripts]
37
+ xrechnung-check = "xrechnung_check.cli:main"
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """CLI for the free XRechnung / ZUGFeRD validator API."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,4 @@
1
+ from xrechnung_check.cli import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())
@@ -0,0 +1,56 @@
1
+ """Argument parsing and process exit codes for xrechnung-check."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ from xrechnung_check.client import ClientError, dumps, format_report, validate_path
9
+
10
+ USAGE = """\
11
+ usage: xrechnung-check FILE [--json]
12
+
13
+ Validate one XRechnung XML file (UBL or CII) or ZUGFeRD PDF with the free
14
+ API at https://checkxrechnung.com/v1/validate
15
+
16
+ No API key. Limits: 50 requests per IP per UTC day, 10 per minute, 5 MB.
17
+ The file is uploaded for that request. The service reports persisted: false.
18
+
19
+ --json print the normalized report as JSON on stdout
20
+
21
+ Exit codes:
22
+ 0 the file is valid
23
+ 1 the file is invalid, or it is not an e-invoice
24
+ 2 usage error, unreadable file, or the API could not be reached
25
+ """
26
+
27
+
28
+ def main(argv: list[str] | None = None) -> int:
29
+ if argv is None:
30
+ argv = sys.argv[1:]
31
+ as_json = False
32
+ files: list[str] = []
33
+ for arg in argv:
34
+ if arg in ("-h", "--help"):
35
+ sys.stdout.write(USAGE)
36
+ return 0
37
+ if arg == "--json":
38
+ as_json = True
39
+ continue
40
+ if arg.startswith("-"):
41
+ sys.stderr.write(f"unknown option: {arg}\n{USAGE}")
42
+ return 2
43
+ files.append(arg)
44
+ if len(files) != 1:
45
+ sys.stderr.write(USAGE)
46
+ return 2
47
+ try:
48
+ result = validate_path(Path(files[0]))
49
+ except ClientError as exc:
50
+ if as_json:
51
+ sys.stdout.write(dumps({"valid": False, "error": str(exc)}))
52
+ else:
53
+ sys.stderr.write(f"{exc}\n")
54
+ return 2
55
+ sys.stdout.write(dumps(result) if as_json else format_report(result))
56
+ return 0 if result["valid"] else 1
@@ -0,0 +1,200 @@
1
+ """Call the public checkxrechnung.com validator API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ API_URL = "https://checkxrechnung.com/v1/validate"
10
+ RULE_BASE = "https://checkxrechnung.com/fehler/"
11
+ WAITLIST_URL = "https://checkxrechnung.com/api-waitlist"
12
+ MAX_BYTES = 5 * 1024 * 1024
13
+ USER_AGENT = "xrechnung-check/0.1.0 (+https://checkxrechnung.com)"
14
+ TIMEOUT = (10, 120)
15
+
16
+
17
+ class ClientError(Exception):
18
+ """Usage, network, or HTTP failure. The CLI exits 2."""
19
+
20
+
21
+ def content_type_for(name: str) -> str:
22
+ lower = name.lower()
23
+ if lower.endswith(".pdf"):
24
+ return "application/pdf"
25
+ if lower.endswith(".xml") or lower.endswith(".cii"):
26
+ return "application/xml"
27
+ return "application/octet-stream"
28
+
29
+
30
+ def rule_url(issue: dict[str, Any]) -> str | None:
31
+ for key in ("rule_url", "ruleUrl"):
32
+ value = issue.get(key)
33
+ if isinstance(value, str) and value.strip():
34
+ return value
35
+ code = issue.get("code") or issue.get("rule_id") or issue.get("ruleId")
36
+ if not isinstance(code, str) or not code.strip():
37
+ return None
38
+ return RULE_BASE + code.strip().lower()
39
+
40
+
41
+ def _clean(data: dict[str, Any]) -> dict[str, Any]:
42
+ return {key: value for key, value in data.items() if value is not None and value != ""}
43
+
44
+
45
+ def normalize(report: dict[str, Any]) -> dict[str, Any]:
46
+ """Turn an API report into the CLI JSON shape.
47
+
48
+ ``rule_url`` is taken from the issue when the API sends it. Otherwise it
49
+ is the public rule page ``https://checkxrechnung.com/fehler/<code>``.
50
+ """
51
+ issues = report.get("issues")
52
+ errors: list[dict[str, Any]] = []
53
+ if isinstance(issues, list):
54
+ for issue in issues:
55
+ if not isinstance(issue, dict):
56
+ continue
57
+ code = issue.get("code") or issue.get("rule_id") or issue.get("ruleId")
58
+ errors.append(
59
+ _clean(
60
+ {
61
+ "rule_id": code if isinstance(code, str) else None,
62
+ "severity": issue.get("severity") if isinstance(issue.get("severity"), str) else None,
63
+ "location": issue.get("location") if isinstance(issue.get("location"), str) else None,
64
+ "message": issue.get("message") if isinstance(issue.get("message"), str) else None,
65
+ "hint": issue.get("hint") if isinstance(issue.get("hint"), str) else None,
66
+ "rule_url": rule_url(issue),
67
+ }
68
+ )
69
+ )
70
+ summary = None
71
+ summary_in = report.get("summary")
72
+ if isinstance(summary_in, dict):
73
+ summary = {}
74
+ if isinstance(summary_in.get("errors"), int):
75
+ summary["errors"] = summary_in["errors"]
76
+ if isinstance(summary_in.get("warnings"), int):
77
+ summary["warnings"] = summary_in["warnings"]
78
+ result: dict[str, Any] = {"valid": report.get("ok") is True, "errors": errors}
79
+ if isinstance(report.get("fileName"), str):
80
+ result["fileName"] = report["fileName"]
81
+ if isinstance(report.get("bytes"), int):
82
+ result["bytes"] = report["bytes"]
83
+ if isinstance(report.get("hasXml"), bool):
84
+ result["hasXml"] = report["hasXml"]
85
+ if isinstance(report.get("syntax"), str):
86
+ result["syntax"] = report["syntax"]
87
+ if isinstance(report.get("invoiceType"), str):
88
+ result["invoiceType"] = report["invoiceType"]
89
+ if isinstance(report.get("persisted"), bool):
90
+ result["persisted"] = report["persisted"]
91
+ if summary is not None:
92
+ result["summary"] = summary
93
+ versions = report.get("versions")
94
+ if isinstance(versions, dict):
95
+ clean_versions = {str(key): value for key, value in versions.items() if isinstance(value, str)}
96
+ if clean_versions:
97
+ result["versions"] = clean_versions
98
+ order = (
99
+ "valid",
100
+ "fileName",
101
+ "bytes",
102
+ "hasXml",
103
+ "syntax",
104
+ "invoiceType",
105
+ "persisted",
106
+ "summary",
107
+ "versions",
108
+ "errors",
109
+ )
110
+ return {key: result[key] for key in order if key in result}
111
+
112
+
113
+ def format_report(result: dict[str, Any]) -> str:
114
+ lines: list[str] = []
115
+ status = "valid" if result.get("valid") else "invalid"
116
+ lines.append(f"{status}: {result.get('fileName') or ''}".rstrip())
117
+ if result.get("syntax"):
118
+ lines.append(f"syntax: {result['syntax']}")
119
+ if result.get("invoiceType"):
120
+ lines.append(f"type: {result['invoiceType']}")
121
+ if isinstance(result.get("hasXml"), bool):
122
+ lines.append("xml: yes" if result["hasXml"] else "xml: no")
123
+ summary = result.get("summary") or {}
124
+ if isinstance(summary, dict):
125
+ if "errors" in summary:
126
+ lines.append(f"errors: {summary['errors']}")
127
+ if "warnings" in summary:
128
+ lines.append(f"warnings: {summary['warnings']}")
129
+ for issue in result.get("errors") or []:
130
+ lines.append("")
131
+ bits = [str(issue.get("rule_id") or "(no rule id)"), str(issue.get("severity") or "issue")]
132
+ if issue.get("location"):
133
+ bits.append(str(issue["location"]))
134
+ lines.append(" ".join(bits))
135
+ if issue.get("message"):
136
+ lines.append(f" message: {issue['message']}")
137
+ if issue.get("hint"):
138
+ lines.append(f" hint: {issue['hint']}")
139
+ if issue.get("rule_url"):
140
+ lines.append(f" rule_url: {issue['rule_url']}")
141
+ return "\n".join(lines) + "\n"
142
+
143
+
144
+ def dumps(result: dict[str, Any]) -> str:
145
+ return json.dumps(result, ensure_ascii=False, indent=2) + "\n"
146
+
147
+
148
+ def validate_path(path: Path) -> dict[str, Any]:
149
+ if not path.is_file():
150
+ raise ClientError(f"file not found: {path}")
151
+ size = path.stat().st_size
152
+ if size == 0:
153
+ raise ClientError(f"empty file: {path}")
154
+ if size > MAX_BYTES:
155
+ raise ClientError(f"file is larger than 5 MB, the API limit: {path}")
156
+ return validate_bytes(path.name, path.read_bytes(), content_type_for(path.name))
157
+
158
+
159
+ def validate_bytes(filename: str, data: bytes, content_type: str) -> dict[str, Any]:
160
+ if not data:
161
+ raise ClientError("empty file")
162
+ if len(data) > MAX_BYTES:
163
+ raise ClientError("file is larger than 5 MB, the API limit")
164
+ import requests
165
+
166
+ try:
167
+ response = requests.post(
168
+ API_URL,
169
+ files={"file": (filename, data, content_type)},
170
+ headers={"User-Agent": USER_AGENT, "Accept": "application/json"},
171
+ timeout=TIMEOUT,
172
+ )
173
+ except requests.RequestException as exc:
174
+ raise ClientError(f"network error: {exc}") from exc
175
+ if response.status_code != 200:
176
+ raise ClientError(_http_error(response))
177
+ try:
178
+ payload = response.json()
179
+ except ValueError as exc:
180
+ raise ClientError("API returned a non-JSON response") from exc
181
+ if not isinstance(payload, dict):
182
+ raise ClientError("API returned an unexpected JSON response")
183
+ return normalize(payload)
184
+
185
+
186
+ def _http_error(response: Any) -> str:
187
+ retry = response.headers.get("Retry-After")
188
+ body = (response.text or "").strip().replace("\n", " ")
189
+ if len(body) > 500:
190
+ body = body[:500] + "…"
191
+ if response.status_code == 429:
192
+ wait = f" Retry-After: {retry}s." if retry else ""
193
+ return (
194
+ f"rate limit reached (HTTP 429).{wait} "
195
+ f"Free limit: 50 per IP per UTC day, 10 per minute. Waitlist: {WAITLIST_URL}. {body}"
196
+ ).strip()
197
+ if response.status_code == 413:
198
+ return f"file too large (HTTP 413). The API accepts at most 5 MB. {body}".strip()
199
+ extra = f" Retry-After: {retry}s." if retry else ""
200
+ return f"HTTP {response.status_code}.{extra} {body}".strip()
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: xrechnung-check
3
+ Version: 0.1.0
4
+ Summary: CLI for the free XRechnung / ZUGFeRD (EN 16931) validator API at checkxrechnung.com
5
+ Author-email: Bobook Limited <info@bobook.club>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://checkxrechnung.com
8
+ Project-URL: Documentation, https://checkxrechnung.com/en/docs
9
+ Project-URL: Repository, https://github.com/wenboteng/xrechnung-validator
10
+ Project-URL: API waitlist, https://checkxrechnung.com/api-waitlist
11
+ Project-URL: Changelog, https://checkxrechnung.com/changelog
12
+ Keywords: xrechnung,zugferd,e-invoicing,en16931,validator,einvoice,germany
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Office/Business :: Financial
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: requests>=2.31
27
+ Dynamic: license-file
28
+
29
+ # xrechnung-check
30
+
31
+ Command-line client for the free, keyless XRechnung / ZUGFeRD validator API.
32
+
33
+ ```bash
34
+ pip install xrechnung-check
35
+ xrechnung-check invoice.xml
36
+ xrechnung-check invoice.xml --json
37
+ ```
38
+
39
+ Until the package is on PyPI, install it from a checkout:
40
+
41
+ ```bash
42
+ pip install ./cli
43
+ ```
44
+
45
+ `FILE` is an XRechnung XML document (UBL or CII) or a ZUGFeRD PDF. The command posts it as multipart field `file` to `https://checkxrechnung.com/v1/validate`. Python 3.9+. The only dependency is `requests`.
46
+
47
+ No API key. Free limit: 50 validations per IP per UTC day, 10 per minute, 5 MB maximum. HTTP 429 carries `Retry-After`. Higher volume: https://checkxrechnung.com/api-waitlist
48
+
49
+ Human output lists each issue with its rule id and `rule_url`. If the API omits `rule_url`, the CLI uses `https://checkxrechnung.com/fehler/<code>` (lowercase). `--json` prints a normalized report: `valid`, `errors[]` with `rule_id` and `rule_url`, plus summary fields from the API.
50
+
51
+ | Exit | Meaning |
52
+ | --- | --- |
53
+ | 0 | `ok` was true |
54
+ | 1 | the file is invalid, or it is not an e-invoice |
55
+ | 2 | usage error, unreadable file, or the API could not be reached |
56
+
57
+ Docs: https://checkxrechnung.com/en/docs · Rules: https://checkxrechnung.com/fehler/ · OpenAPI: https://checkxrechnung.com/openapi.json
58
+
59
+ MIT. Copyright (c) 2026 Bobook Limited.
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/xrechnung_check/__init__.py
5
+ src/xrechnung_check/__main__.py
6
+ src/xrechnung_check/cli.py
7
+ src/xrechnung_check/client.py
8
+ src/xrechnung_check.egg-info/PKG-INFO
9
+ src/xrechnung_check.egg-info/SOURCES.txt
10
+ src/xrechnung_check.egg-info/dependency_links.txt
11
+ src/xrechnung_check.egg-info/entry_points.txt
12
+ src/xrechnung_check.egg-info/requires.txt
13
+ src/xrechnung_check.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ xrechnung-check = xrechnung_check.cli:main
@@ -0,0 +1 @@
1
+ requests>=2.31
@@ -0,0 +1 @@
1
+ xrechnung_check