sdb-reader 0.9.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.
- sdb_reader/__init__.py +157 -0
- sdb_reader/ask.py +437 -0
- sdb_reader/ask_record.schema.json +388 -0
- sdb_reader/cli.py +1079 -0
- sdb_reader/clp_statements_de.json +997 -0
- sdb_reader/compliance.py +546 -0
- sdb_reader/current.py +134 -0
- sdb_reader/diff.py +520 -0
- sdb_reader/embedded.py +250 -0
- sdb_reader/extraction.py +506 -0
- sdb_reader/layout.py +894 -0
- sdb_reader/line_breaks.py +40 -0
- sdb_reader/messages.py +394 -0
- sdb_reader/messages_data/de.toml +146 -0
- sdb_reader/messages_data/en.toml +141 -0
- sdb_reader/model.py +321 -0
- sdb_reader/parser.py +4601 -0
- sdb_reader/pictograms.py +374 -0
- sdb_reader/presets.py +110 -0
- sdb_reader/presets.toml +23 -0
- sdb_reader/py.typed +0 -0
- sdb_reader/read_record.schema.json +792 -0
- sdb_reader/reading.py +94 -0
- sdb_reader/scan.py +265 -0
- sdb_reader/schema.py +96 -0
- sdb_reader/serialise.py +463 -0
- sdb_reader/show.py +370 -0
- sdb_reader/statements.py +1011 -0
- sdb_reader/verification.py +322 -0
- sdb_reader/versions.py +31 -0
- sdb_reader-0.9.0.dist-info/METADATA +117 -0
- sdb_reader-0.9.0.dist-info/RECORD +37 -0
- sdb_reader-0.9.0.dist-info/WHEEL +5 -0
- sdb_reader-0.9.0.dist-info/entry_points.txt +2 -0
- sdb_reader-0.9.0.dist-info/licenses/LICENSE +661 -0
- sdb_reader-0.9.0.dist-info/licenses/NOTICE +40 -0
- sdb_reader-0.9.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"""Verification helpers for Sicherheitsdatenblatt (SDS) PDFs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from collections.abc import Iterable, Iterator, Sequence
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from enum import StrEnum
|
|
9
|
+
|
|
10
|
+
from .extraction import ExtractionResult
|
|
11
|
+
from .messages import Message
|
|
12
|
+
from .parser import split_sections
|
|
13
|
+
from .schema import Section
|
|
14
|
+
|
|
15
|
+
HEADER_KEYWORDS: tuple[str, ...] = (
|
|
16
|
+
"sicherheitsdatenblatt",
|
|
17
|
+
"safety data sheet",
|
|
18
|
+
"material safety data sheet",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
SECTION_MARKER_PATTERNS: tuple[re.Pattern[str], ...] = (
|
|
22
|
+
re.compile(r"abschnitt\s+1", re.IGNORECASE),
|
|
23
|
+
re.compile(r"section\s+1", re.IGNORECASE),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# The words standing as a title: at the start of a line, alone or as the end
|
|
27
|
+
# of a compound ("EG-Sicherheitsdatenblatt", "Produkt-Sicherheitsdatenblatt").
|
|
28
|
+
# A real sheet carries one, usually on every page. The keywords above match
|
|
29
|
+
# them anywhere, and the word alone was enough to pass: One supplier's "Sicherheits-
|
|
30
|
+
# informationen" for its batteries passed on "Verantwortlich fuer das
|
|
31
|
+
# Sicherheitsdatenblatt" and on the sentence stating that no Sicherheits-
|
|
32
|
+
# datenblatt is required for them. Measured over 3191 documents
|
|
33
|
+
# that passed with their text kept, that document is the only one without a
|
|
34
|
+
# title line; the nine that cite no REACH article and the three written
|
|
35
|
+
# voluntarily for unclassified mixtures all carry one.
|
|
36
|
+
#
|
|
37
|
+
# It reads lines, so it depends on where the extractor breaks them: running
|
|
38
|
+
# text that happens to wrap just before the word passes, and a title the
|
|
39
|
+
# extractor joins onto the line before it ("Seite 1/8 Sicherheitsdatenblatt")
|
|
40
|
+
# does not. Neither occurs in the corpus today. The prefixes are the ones it
|
|
41
|
+
# holds, with every hyphen a PDF may carry.
|
|
42
|
+
#
|
|
43
|
+
# A sentence that happens to begin its line with the word is no title either.
|
|
44
|
+
# EUH210 reads "Sicherheitsdatenblatt auf Anfrage erhältlich." and stands on
|
|
45
|
+
# its own line in technical data sheets (26 of one supplier passed), and
|
|
46
|
+
# running text wraps before the word: "… entnehmen Sie bitte dem" /
|
|
47
|
+
# "Sicherheitsdatenblatt.".
|
|
48
|
+
#
|
|
49
|
+
# Only the German word (SDB-66): a sheet in another language is no German
|
|
50
|
+
# safety data sheet, whatever it is titled.
|
|
51
|
+
GERMAN_TITLE_PATTERN = re.compile(
|
|
52
|
+
r"(?im)^[^\S\n]*[\W\d]{0,4}"
|
|
53
|
+
r"(?:(?:eg|eu|ec|produkt)[^\S\n]*[-‐‑–][^\S\n]*|(?:eg|eu|ec)[^\S\n]+)?"
|
|
54
|
+
r"sicherheitsdatenblatt"
|
|
55
|
+
r"(?![^\S\n]*(?:\.|auf\s+Anfrage))"
|
|
56
|
+
)
|
|
57
|
+
# A misspelled title is a title (SDB-66): "Sichheitsdatenblatt". The word where
|
|
58
|
+
# a title stands, at most two letters off and no longer than the word itself,
|
|
59
|
+
# so that an inflected form at the start of a wrapped sentence
|
|
60
|
+
# ("Sicherheitsdatenblattes") is none.
|
|
61
|
+
_TITLE_WORD = "sicherheitsdatenblatt"
|
|
62
|
+
_TITLE_CANDIDATE = re.compile(
|
|
63
|
+
r"(?im)^[^\S\n]*[\W\d]{0,4}([^\W\d_]{17,21})\b"
|
|
64
|
+
r"(?![^\S\n]*(?:\.|auf\s+Anfrage))"
|
|
65
|
+
)
|
|
66
|
+
# A sentence that wraps before the word is no title (SDB-140): the word goes on
|
|
67
|
+
# in lower case and the line before ends in a lower-case word ("… die in
|
|
68
|
+
# diesem" / "Sicherheitsdatenblatt enthaltenen Daten"). What a title goes on
|
|
69
|
+
# with says by what or for what the sheet is made; such a line stays a title
|
|
70
|
+
# also under a product name in lower case.
|
|
71
|
+
_LOWER_CASE_AHEAD = re.compile(r"[^\S\n]+[a-zäöüß]")
|
|
72
|
+
_TITLE_GOES_ON = re.compile(
|
|
73
|
+
r"[^\S\n]+(?:gemäß|gemäss|nach|in[^\S\n]+Anlehnung[^\S\n]+an|für|zum|vom)\b",
|
|
74
|
+
re.IGNORECASE,
|
|
75
|
+
)
|
|
76
|
+
_ENDS_IN_LOWER_CASE = re.compile(r"(?:^|\s)[a-zäöüß]+$")
|
|
77
|
+
# A leaflet on handling an article that calls itself a safety data sheet
|
|
78
|
+
# (SDB-141): "Sicherheitsdatenblatt" / "zum sicheren Umgang mit Bleibatterien".
|
|
79
|
+
_LEAFLET_GOES_ON = re.compile(
|
|
80
|
+
r"zum[^\S\n]+sicheren[^\S\n]+Umgang[^\S\n]+mit\b", re.IGNORECASE
|
|
81
|
+
)
|
|
82
|
+
_REACH_NUMBER = re.compile(r"1907\s*/\s*2006")
|
|
83
|
+
# How many of the sixteen sections make the layout of a safety data sheet
|
|
84
|
+
# (SDB-66). Among the files the check refuses, 1,451 hold four at most and 589
|
|
85
|
+
# twelve or more, none between.
|
|
86
|
+
SECTIONS_OF_A_SHEET = 12
|
|
87
|
+
# Headings a sheet in English carries, which the parser reads too: sections
|
|
88
|
+
# found under them are no German layout.
|
|
89
|
+
_ENGLISH_HEADING = re.compile(
|
|
90
|
+
r"(?im)^\W{0,6}(?:\d{1,2}\W{1,3})?section[^\S\n]+0?(\d{1,2})\b"
|
|
91
|
+
)
|
|
92
|
+
# The numbering Annex II prescribes in every language (SDB-68): a subsection
|
|
93
|
+
# "n.1" at a line's start for sections 1 to 15.
|
|
94
|
+
_FIRST_SUBSECTION = re.compile(
|
|
95
|
+
r"(?m)^[^\S\n]*[-·•*]?[^\S\n]*(\d{1,2})\s?\.\s?1\b(?!\s?\.\s?\d)"
|
|
96
|
+
)
|
|
97
|
+
NUMBERED_SECTIONS_OF_A_SHEET = 10
|
|
98
|
+
# A document that prints statement codes says something about the product,
|
|
99
|
+
# whatever it is (SDB-68). Three different ones, because one or two are mostly
|
|
100
|
+
# chance: "BM P150 L".
|
|
101
|
+
_STATEMENT_CODE = re.compile(r"\b(?:H[2-4]\d{2}|P[1-5]\d{2}|EUH\s?\d{3})\b")
|
|
102
|
+
STATEMENT_CODES_OF_A_LABEL = 3
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class DocumentKind(StrEnum):
|
|
106
|
+
"""What a file filed as a safety data sheet is (SDB-66, SDB-68)."""
|
|
107
|
+
|
|
108
|
+
# Carries the German title: the only kind the parser reads.
|
|
109
|
+
SAFETY_DATA_SHEET = "safety-data-sheet"
|
|
110
|
+
# Laid out like one, without calling itself one: a voluntary document for
|
|
111
|
+
# a product that needs none.
|
|
112
|
+
SAFETY_INFORMATION = "safety-information"
|
|
113
|
+
# A safety data sheet in another language, told by its layout.
|
|
114
|
+
FOREIGN_SAFETY_DATA_SHEET = "safety-data-sheet-other-language"
|
|
115
|
+
DOCUMENT = "document"
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
REGULATION_PATTERNS: tuple[re.Pattern[str], ...] = (
|
|
119
|
+
re.compile(r"verordnung\s*\(eg\)\s*nr\.?\s*1907/2006", re.IGNORECASE),
|
|
120
|
+
re.compile(r"regulation\s*\(ec\)\s*no\s*1907/2006", re.IGNORECASE),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
HAZARD_CODE_PATTERN = re.compile(r"\bH\d{3}\b")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@dataclass(slots=True)
|
|
127
|
+
class Verification:
|
|
128
|
+
"""What kind of document a text is, and why.
|
|
129
|
+
|
|
130
|
+
``kind`` is the verdict; only a ``SAFETY_DATA_SHEET`` is parsed. ``errors``
|
|
131
|
+
say why a file is none, ``warnings`` what else stood out.
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
errors: list[Message]
|
|
135
|
+
warnings: list[Message]
|
|
136
|
+
kind: DocumentKind = DocumentKind.DOCUMENT
|
|
137
|
+
# Whether the text prints three or more different statement codes. Judged
|
|
138
|
+
# for every file that is neither a German sheet nor a safety information;
|
|
139
|
+
# None for those two (SDB-68).
|
|
140
|
+
prints_statement_codes: bool | None = None
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class SDSVerifier:
|
|
144
|
+
"""Detect whether a PDF is a genuine Sicherheitsdatenblatt."""
|
|
145
|
+
|
|
146
|
+
def verify(self, extraction: ExtractionResult) -> Verification:
|
|
147
|
+
"""Judge an already-extracted document.
|
|
148
|
+
|
|
149
|
+
Takes the text rather than the file. It never needed the file -- all
|
|
150
|
+
it looks at is ``extraction.text`` -- but it used to
|
|
151
|
+
open the PDF itself and read the first four pages, so every document was
|
|
152
|
+
read twice: once cheaply to decide whether it was a safety data sheet,
|
|
153
|
+
then again in full to parse it.
|
|
154
|
+
|
|
155
|
+
The idea was that a document which turns out not to be one should never
|
|
156
|
+
cost a full extraction. Measured over the corpus that saves nothing:
|
|
157
|
+
of 2804 current sheets and 884 retired ones, not one was refused. The
|
|
158
|
+
gate cost 37% more reading time on every document to guard against a
|
|
159
|
+
case that does not arise.
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
errors: list[Message] = []
|
|
163
|
+
warnings: list[Message] = list(extraction.warnings)
|
|
164
|
+
|
|
165
|
+
lower_text = extraction.text.lower()
|
|
166
|
+
|
|
167
|
+
header_hits = _find_keywords(lower_text, HEADER_KEYWORDS)
|
|
168
|
+
if not header_hits:
|
|
169
|
+
warnings.append(Message("no-title-keywords"))
|
|
170
|
+
title_line = has_german_title(extraction.text)
|
|
171
|
+
leaflet = not title_line and _has_leaflet_title(extraction.text)
|
|
172
|
+
|
|
173
|
+
section_hits = sum(
|
|
174
|
+
1 for pattern in SECTION_MARKER_PATTERNS if pattern.search(lower_text)
|
|
175
|
+
)
|
|
176
|
+
if section_hits == 0:
|
|
177
|
+
warnings.append(Message("no-section-marker"))
|
|
178
|
+
|
|
179
|
+
regulation_hits = sum(
|
|
180
|
+
1 for pattern in REGULATION_PATTERNS if pattern.search(lower_text)
|
|
181
|
+
)
|
|
182
|
+
if regulation_hits == 0:
|
|
183
|
+
warnings.append(Message("no-regulation-reference"))
|
|
184
|
+
|
|
185
|
+
hazard_code_count = len(HAZARD_CODE_PATTERN.findall(extraction.text))
|
|
186
|
+
if hazard_code_count == 0:
|
|
187
|
+
warnings.append(Message("no-hazard-codes-in-text"))
|
|
188
|
+
|
|
189
|
+
document_length = len(extraction.text)
|
|
190
|
+
if document_length < 800:
|
|
191
|
+
warnings.append(Message("short-sample"))
|
|
192
|
+
|
|
193
|
+
sections_found = _sections_found(extraction.text)
|
|
194
|
+
kind = _kind(extraction.text, title_line=title_line, sections=sections_found)
|
|
195
|
+
prints_statement_codes: bool | None = None
|
|
196
|
+
if kind is DocumentKind.SAFETY_INFORMATION:
|
|
197
|
+
errors.append(
|
|
198
|
+
Message("leaflet-title")
|
|
199
|
+
if leaflet
|
|
200
|
+
else Message("safety-information", {"sections": sections_found})
|
|
201
|
+
)
|
|
202
|
+
elif kind is not DocumentKind.SAFETY_DATA_SHEET:
|
|
203
|
+
prints_statement_codes = (
|
|
204
|
+
len(
|
|
205
|
+
{
|
|
206
|
+
"".join(c.split())
|
|
207
|
+
for c in _STATEMENT_CODE.findall(extraction.text)
|
|
208
|
+
}
|
|
209
|
+
)
|
|
210
|
+
>= STATEMENT_CODES_OF_A_LABEL
|
|
211
|
+
)
|
|
212
|
+
if kind is DocumentKind.FOREIGN_SAFETY_DATA_SHEET:
|
|
213
|
+
errors.append(Message("other-language"))
|
|
214
|
+
elif leaflet:
|
|
215
|
+
errors.append(Message("leaflet-title"))
|
|
216
|
+
elif title_line:
|
|
217
|
+
errors.append(Message("cover-only"))
|
|
218
|
+
elif header_hits:
|
|
219
|
+
errors.append(Message("title-in-running-text"))
|
|
220
|
+
else:
|
|
221
|
+
errors.append(Message("no-safety-data-sheet"))
|
|
222
|
+
|
|
223
|
+
return Verification(
|
|
224
|
+
errors=errors,
|
|
225
|
+
warnings=warnings,
|
|
226
|
+
kind=kind,
|
|
227
|
+
prints_statement_codes=prints_statement_codes,
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
def refuse_unreadable(self, errors: Sequence[Message]) -> Verification:
|
|
231
|
+
"""The verdict for a document that could not be read at all."""
|
|
232
|
+
return Verification(errors=list(errors), warnings=[])
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def has_german_title(text: str) -> bool:
|
|
236
|
+
"""Whether a line carries "Sicherheitsdatenblatt" as a title, misspelled or not.
|
|
237
|
+
|
|
238
|
+
A sentence that wraps before the word is none (SDB-140), nor is the title
|
|
239
|
+
of a leaflet on handling an article (SDB-141).
|
|
240
|
+
"""
|
|
241
|
+
names_reach = bool(_REACH_NUMBER.search(text))
|
|
242
|
+
return any(
|
|
243
|
+
not _wraps_before(text, end)
|
|
244
|
+
and (names_reach or not _goes_on_as_leaflet(text, end))
|
|
245
|
+
for end in _title_ends(text)
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _has_leaflet_title(text: str) -> bool:
|
|
250
|
+
"""Whether a title line is a leaflet's, in a text that does not name REACH."""
|
|
251
|
+
return not _REACH_NUMBER.search(text) and any(
|
|
252
|
+
_goes_on_as_leaflet(text, end) for end in _title_ends(text)
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def _title_ends(text: str) -> Iterator[int]:
|
|
257
|
+
"""Where the word ends in each line that carries it the way a title does."""
|
|
258
|
+
for match in GERMAN_TITLE_PATTERN.finditer(text):
|
|
259
|
+
yield match.end()
|
|
260
|
+
for match in _TITLE_CANDIDATE.finditer(text):
|
|
261
|
+
if _edits(match.group(1).lower(), _TITLE_WORD) <= 2:
|
|
262
|
+
yield match.end(1)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def _wraps_before(text: str, end: int) -> bool:
|
|
266
|
+
"""Whether the line is the rest of a sentence that broke before the word."""
|
|
267
|
+
if not _LOWER_CASE_AHEAD.match(text, end) or _TITLE_GOES_ON.match(text, end):
|
|
268
|
+
return False
|
|
269
|
+
start = text.rfind("\n", 0, end)
|
|
270
|
+
before = text[: max(start, 0)].rstrip()
|
|
271
|
+
return bool(_ENDS_IN_LOWER_CASE.search(before[before.rfind("\n") + 1 :]))
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _goes_on_as_leaflet(text: str, end: int) -> bool:
|
|
275
|
+
"""Whether the word is followed, on its line or the next with text, by the leaflet's words."""
|
|
276
|
+
stop = text.find("\n", end)
|
|
277
|
+
rest = text[end:] if stop < 0 else text[end:stop]
|
|
278
|
+
if not rest.strip():
|
|
279
|
+
rest = text[stop:].lstrip().split("\n", 1)[0] if stop >= 0 else ""
|
|
280
|
+
return bool(_LEAFLET_GOES_ON.match(rest.lstrip()))
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _edits(word: str, target: str) -> int:
|
|
284
|
+
"""How many single-letter changes turn *word* into *target*."""
|
|
285
|
+
previous = list(range(len(target) + 1))
|
|
286
|
+
for i, a in enumerate(word, start=1):
|
|
287
|
+
current = [i]
|
|
288
|
+
for j, b in enumerate(target, start=1):
|
|
289
|
+
current.append(
|
|
290
|
+
min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + (a != b))
|
|
291
|
+
)
|
|
292
|
+
previous = current
|
|
293
|
+
return previous[-1]
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def _sections_found(text: str) -> int:
|
|
297
|
+
"""How many of the sixteen sections the parser finds in *text*."""
|
|
298
|
+
return sum(
|
|
299
|
+
1
|
|
300
|
+
for section, body in split_sections(text).items()
|
|
301
|
+
if isinstance(section, Section) and body.strip()
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _kind(text: str, *, title_line: bool, sections: int) -> DocumentKind:
|
|
306
|
+
# The title over none of the sixteen sections is a cover (SDB-105).
|
|
307
|
+
if title_line and sections:
|
|
308
|
+
return DocumentKind.SAFETY_DATA_SHEET
|
|
309
|
+
laid_out = sections >= SECTIONS_OF_A_SHEET
|
|
310
|
+
english = (
|
|
311
|
+
len({int(n) for n in _ENGLISH_HEADING.findall(text)}) >= SECTIONS_OF_A_SHEET
|
|
312
|
+
)
|
|
313
|
+
if laid_out and not english:
|
|
314
|
+
return DocumentKind.SAFETY_INFORMATION
|
|
315
|
+
numbered = {int(n) for n in _FIRST_SUBSECTION.findall(text) if 1 <= int(n) <= 15}
|
|
316
|
+
if laid_out or len(numbered) >= NUMBERED_SECTIONS_OF_A_SHEET:
|
|
317
|
+
return DocumentKind.FOREIGN_SAFETY_DATA_SHEET
|
|
318
|
+
return DocumentKind.DOCUMENT
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def _find_keywords(text: str, keywords: Iterable[str]) -> list[str]:
|
|
322
|
+
return [keyword for keyword in keywords if keyword in text]
|
sdb_reader/versions.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""The versions of the library's two stages (BIB-4).
|
|
2
|
+
|
|
3
|
+
A caller that keeps texts or readings compares these with what it stored:
|
|
4
|
+
a text read at another ``extraction_stage()`` is read from the PDF again, a
|
|
5
|
+
reading made at another ``PARSER_VERSION`` is made again from the text.
|
|
6
|
+
|
|
7
|
+
Whoever changes a stage's code decides here; tests/test_stage_versions.py
|
|
8
|
+
asks (BIB-5).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import pymupdf
|
|
14
|
+
|
|
15
|
+
# Raise when the same PDF can give another text: extraction.py, layout.py,
|
|
16
|
+
# line_breaks.py.
|
|
17
|
+
EXTRACTION_VERSION = 2
|
|
18
|
+
|
|
19
|
+
# Raise when the same text can give another reading: the verdict, the parser,
|
|
20
|
+
# the statements and their tables, the findings, the message codes, the JSON
|
|
21
|
+
# form. The sentences of the catalogs are no part of a reading.
|
|
22
|
+
PARSER_VERSION = 16
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def extraction_stage() -> str:
|
|
26
|
+
"""The reading stage a text comes from: its version and the PDF library's.
|
|
27
|
+
|
|
28
|
+
The text of a PDF depends on both, so a stored text holds for one value of
|
|
29
|
+
this and no other.
|
|
30
|
+
"""
|
|
31
|
+
return f"{EXTRACTION_VERSION}+pymupdf-{pymupdf.__version__}"
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sdb-reader
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: Reads German safety data sheets (Sicherheitsdatenblätter) under REACH and CLP, without a language model
|
|
5
|
+
Author-email: "Förde-Baumarkt Holger Claussen GmbH & Co. KG" <service@foerde-baumarkt.de>
|
|
6
|
+
License-Expression: AGPL-3.0-or-later
|
|
7
|
+
Project-URL: Documentation, https://foerdebaumarkt.github.io/sdb-reader/
|
|
8
|
+
Project-URL: Changelog, https://github.com/foerdebaumarkt/sdb-reader/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Source, https://github.com/foerdebaumarkt/sdb-reader
|
|
10
|
+
Project-URL: Issues, https://github.com/foerdebaumarkt/sdb-reader/issues
|
|
11
|
+
Keywords: safety data sheet,Sicherheitsdatenblatt,SDS,SDB,REACH,CLP,GHS,hazard statements,PDF
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Information Technology
|
|
16
|
+
Classifier: Natural Language :: German
|
|
17
|
+
Classifier: Natural Language :: English
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
20
|
+
Classifier: Topic :: Text Processing
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
27
|
+
Requires-Python: >=3.12
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
License-File: NOTICE
|
|
31
|
+
Requires-Dist: pymupdf-lite<3.0.0,>=2.1
|
|
32
|
+
Requires-Dist: structlog>=26.1.0
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# sdb-reader
|
|
36
|
+
|
|
37
|
+
Reads German safety data sheets (Sicherheitsdatenblätter) under REACH and CLP
|
|
38
|
+
from PDF files, without a language model: the same file always gives the same
|
|
39
|
+
result, and every rule the reader follows is written down.
|
|
40
|
+
|
|
41
|
+
Deutsch: [README.de.md](https://github.com/foerdebaumarkt/sdb-reader/blob/main/README.de.md)
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
sdb-reader read sheet.pdf
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
For each PDF it says:
|
|
48
|
+
|
|
49
|
+
- **what the file is:** a German safety data sheet, a safety information, a
|
|
50
|
+
safety data sheet in another language, or another document;
|
|
51
|
+
- **the classification** that section 2 states;
|
|
52
|
+
- **the label:** signal word, pictograms, and the H, P and EUH statements,
|
|
53
|
+
with the sheet's wording beside the regulation's;
|
|
54
|
+
- **dates and version**, the countries the sheet is issued for, and the
|
|
55
|
+
supplier;
|
|
56
|
+
- **what is wrong with the sheet as a document:** revised before 2021, no
|
|
57
|
+
readable date, a classification and a label that contradict each other, a
|
|
58
|
+
statement worded differently from the regulation.
|
|
59
|
+
|
|
60
|
+
The result is JSON. Warnings and findings come as a fixed code with a
|
|
61
|
+
sentence, in German or English. To read a sheet yourself, `show` prints the
|
|
62
|
+
same as a report:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
sdb-reader show sheet.pdf
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Documentation
|
|
69
|
+
|
|
70
|
+
The documentation is at <https://foerdebaumarkt.github.io/sdb-reader/>, one
|
|
71
|
+
edition per released version. The same pages are in the repository under
|
|
72
|
+
[docs/](https://github.com/foerdebaumarkt/sdb-reader/tree/main/docs).
|
|
73
|
+
|
|
74
|
+
| You want to | Read |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| run the command and understand what it prints | [Using the command line](https://foerdebaumarkt.github.io/sdb-reader/latest/usage/README.html), in German: [Bedienung](https://foerdebaumarkt.github.io/sdb-reader/latest/bedienung/README.html) |
|
|
77
|
+
| read sheets from a Python program | [Using the library](https://foerdebaumarkt.github.io/sdb-reader/latest/api/README.html) |
|
|
78
|
+
| understand how a file becomes a reading | [How it works](https://foerdebaumarkt.github.io/sdb-reader/latest/how-it-works.html) |
|
|
79
|
+
| change the reader | [Contributing](https://foerdebaumarkt.github.io/sdb-reader/latest/contributing/README.html) |
|
|
80
|
+
| know what a version changed | [CHANGELOG.md](https://foerdebaumarkt.github.io/sdb-reader/latest/changelog.html) |
|
|
81
|
+
| read the binding rules | [specs/](https://github.com/foerdebaumarkt/sdb-reader/blob/main/specs/README.md), in German |
|
|
82
|
+
|
|
83
|
+
## Install
|
|
84
|
+
|
|
85
|
+
Needs Python 3.12 or newer. Install it from the Python Package Index:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
uv tool install sdb-reader
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Scanned sheets are read by text recognition, which needs `tesseract` with
|
|
92
|
+
German language data. [Installing](https://foerdebaumarkt.github.io/sdb-reader/latest/usage/installing.html) has the details.
|
|
93
|
+
|
|
94
|
+
## Limits
|
|
95
|
+
|
|
96
|
+
- German sheets only. A sheet in another language is recognised as one and
|
|
97
|
+
not read.
|
|
98
|
+
- It reads one file at a time. Which sheets belong to one product is for the
|
|
99
|
+
program that uses it; the library then chooses the current one among them.
|
|
100
|
+
- Whether a product needs a safety data sheet is read from the classification
|
|
101
|
+
and the label. Section 2.3 (PBT, vPvB, candidate list) is not read.
|
|
102
|
+
- An older sheet in another language, without numbered subsections, counts as
|
|
103
|
+
a document.
|
|
104
|
+
- A form in two columns without colons is read as label and value in
|
|
105
|
+
section 1 only. In the other sections of such a sheet a value may not be
|
|
106
|
+
found.
|
|
107
|
+
|
|
108
|
+
## Licence
|
|
109
|
+
|
|
110
|
+
GNU Affero General Public License, version 3 or later ([LICENSE](https://github.com/foerdebaumarkt/sdb-reader/blob/main/LICENSE)).
|
|
111
|
+
The PDF library the reader is built on, PyMuPDF (installed as `pymupdf-lite`), is under the AGPL, so a
|
|
112
|
+
program that uses this package takes on its obligations.
|
|
113
|
+
|
|
114
|
+
Copyright © 2026 Förde-Baumarkt Holger Claussen GmbH & Co. KG
|
|
115
|
+
(<service@foerde-baumarkt.de>).
|
|
116
|
+
[NOTICE](https://github.com/foerdebaumarkt/sdb-reader/blob/main/NOTICE) names the copyright holder and the source of the regulation's
|
|
117
|
+
wording that the package carries.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
sdb_reader/__init__.py,sha256=dTkWLZ-dnZzr1ij1q5Yx2WOzYBVZm2v89EQSNNc2O3k,4792
|
|
2
|
+
sdb_reader/ask.py,sha256=UjrXWQIVdV08x8NosJj6xLHulKjKcc844OwHu7eI1tI,17483
|
|
3
|
+
sdb_reader/ask_record.schema.json,sha256=KaQ5vggzL5LhqDfmA68A6X8X3zF0Guq5ZjDXUtvY2R4,11223
|
|
4
|
+
sdb_reader/cli.py,sha256=0V3JyD9krrWPYRcSHVZI8b4JLG-n5G8RQJnN0RUDTMI,36838
|
|
5
|
+
sdb_reader/clp_statements_de.json,sha256=kKh5MQpR2pJtWL4Ul2mnS8SBwHd5TYf601eNa81-edQ,34707
|
|
6
|
+
sdb_reader/compliance.py,sha256=udmiJPsi8oqQxnV_WRNnwTPMtfp7nS_OUFYugxKoDkY,20870
|
|
7
|
+
sdb_reader/current.py,sha256=kar8Ai14HfMAl2iQ05ddlZOdI4HaDdhTHM8SRb2JeEQ,4790
|
|
8
|
+
sdb_reader/diff.py,sha256=uKnSqsRGRotIbtHa5BH4ae0Fbo58snoay9CC5p6_2sQ,17577
|
|
9
|
+
sdb_reader/embedded.py,sha256=4p5pezSWBGtPuG6iEz6EPS6SIjbjvNWT3WFLwiwGPYU,9687
|
|
10
|
+
sdb_reader/extraction.py,sha256=7jzzJBN5ErJq1xSAaoDZ7Wy2BZr3va0Tj0AEreLN4Qw,20635
|
|
11
|
+
sdb_reader/layout.py,sha256=1p-2I1a9dJB3mm0X9fFUCD4OLUNh3O8aP80c2O56sCM,34772
|
|
12
|
+
sdb_reader/line_breaks.py,sha256=tCFYdEZl6pzXC3CeQrkKPBjoSqZ-dXeVAcL1CtE-tJM,1762
|
|
13
|
+
sdb_reader/messages.py,sha256=hcvrjji514Ih6IB_Y4U9HjjLtjFxD0pVn8HrTp7fPQA,14686
|
|
14
|
+
sdb_reader/model.py,sha256=sW37H1ait0MoDEnWWDbMRUyikWvYIBCqARimuuMPN5o,15151
|
|
15
|
+
sdb_reader/parser.py,sha256=ujPr5bUVulP1mFSugoKVU4LAZDo5eLCnEJIysqMYBh8,199029
|
|
16
|
+
sdb_reader/pictograms.py,sha256=l7IIby8JKeB9o-TTd32nE7ntfea5HyFGCdCyt70gNOw,12360
|
|
17
|
+
sdb_reader/presets.py,sha256=JmgITRzC5xjP0XMM7-_Zvjxka1TK2vfJCv8txRiD9fk,4269
|
|
18
|
+
sdb_reader/presets.toml,sha256=LGSwLFwJ6P80NUr_JoYUgKWw6BAqN9zaJr4VnH-ojtM,1076
|
|
19
|
+
sdb_reader/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
sdb_reader/read_record.schema.json,sha256=31u8LNQ2EjaJTZnG2HXrZfCj4TexpE1ODqHYL77OCZQ,23183
|
|
21
|
+
sdb_reader/reading.py,sha256=A6m2JDhflZWFVAYd32n6ZGRZNkg96un0c9cRe6qRy_Y,3691
|
|
22
|
+
sdb_reader/scan.py,sha256=h5FeWX0HxtdKIefekWPhRuFei3ZBbTnsLPE9aH_Zwoo,8869
|
|
23
|
+
sdb_reader/schema.py,sha256=XhXEuiIRBrU9N90cZPr4zTpMHhymUU6GtAD0cMzlFC4,3622
|
|
24
|
+
sdb_reader/serialise.py,sha256=2Q4wEydwPPPtaTYWdv3mt2gvSJIdaUg63M0YCJu74qA,19704
|
|
25
|
+
sdb_reader/show.py,sha256=gvE4MfPDoON3Y-GVmpBBvuTb5vnwP5x4PoPueWlV9fc,13996
|
|
26
|
+
sdb_reader/statements.py,sha256=xC-EUdnhpJkxSBSkUSnxetWrB3Sk74YVmUfqv0pDPbw,42729
|
|
27
|
+
sdb_reader/verification.py,sha256=KwQIkzRqiEQdrqWS5pk5tsBLNuihTRh3a98LucjyDU8,13193
|
|
28
|
+
sdb_reader/versions.py,sha256=PqADQEncS4dQAsyzbDicu2E-nBgwQ0UItvFsGZ3LHBk,1066
|
|
29
|
+
sdb_reader/messages_data/de.toml,sha256=zNWhN863gLNptVBiMR-25XH72UNVG8I5Msrzdo1D0yM,12658
|
|
30
|
+
sdb_reader/messages_data/en.toml,sha256=MEsyWM1IjfcmGqHmSCBlGYVST7uAM-HcGznbRC87ZlQ,11222
|
|
31
|
+
sdb_reader-0.9.0.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
|
|
32
|
+
sdb_reader-0.9.0.dist-info/licenses/NOTICE,sha256=50yGZvb_bO893s0mqL7BSTPd9X6KHMRX9B9jzNNMwTM,2082
|
|
33
|
+
sdb_reader-0.9.0.dist-info/METADATA,sha256=jo67iUNo8yXSKXGqAKcgoYsHa4oBkjrYhF98CfecIds,5438
|
|
34
|
+
sdb_reader-0.9.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
35
|
+
sdb_reader-0.9.0.dist-info/entry_points.txt,sha256=BXnlRR964JQwhCr9iuW0kQ7x0FB4x6K2EsuXlQidXjs,51
|
|
36
|
+
sdb_reader-0.9.0.dist-info/top_level.txt,sha256=JKwMztkHTXyXVkFTmfgHqL9wNyZ0OFmSBWW75aJL3OE,11
|
|
37
|
+
sdb_reader-0.9.0.dist-info/RECORD,,
|