omrkit 2.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.
omrkit/api/settings.py ADDED
@@ -0,0 +1,55 @@
1
+ """Environment-driven API configuration and public demo abuse-protection limits."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from dataclasses import dataclass
7
+
8
+
9
+ def _parse_bool(raw: str | None, default: bool = False) -> bool:
10
+ if raw is None:
11
+ return default
12
+ return raw.strip().lower() in {"1", "true", "yes", "on"}
13
+
14
+
15
+ def _parse_positive_int(raw: str | None, default: int) -> int:
16
+ if raw is None:
17
+ return default
18
+ try:
19
+ val = int(raw.strip())
20
+ return val if val > 0 else default
21
+ except ValueError:
22
+ return default
23
+
24
+
25
+ @dataclass(frozen=True, slots=True)
26
+ class APISettings:
27
+ """Runtime guardrails for the FastAPI REST API and hosted Web Studio demos."""
28
+
29
+ demo_mode: bool = False
30
+ max_upload_mb: int = 15
31
+ max_files_per_scan: int = 20
32
+ max_pdf_pages: int = 25
33
+
34
+ @property
35
+ def max_upload_bytes(self) -> int:
36
+ return self.max_upload_mb * 1024 * 1024
37
+
38
+ def limits_dict(self) -> dict[str, int]:
39
+ return {
40
+ "max_upload_mb": self.max_upload_mb,
41
+ "max_files_per_scan": self.max_files_per_scan,
42
+ "max_pdf_pages": self.max_pdf_pages,
43
+ }
44
+
45
+
46
+ def get_api_settings() -> APISettings:
47
+ """Read current API settings from environment variables."""
48
+ return APISettings(
49
+ demo_mode=_parse_bool(os.environ.get("OMRKIT_DEMO_MODE"), default=False),
50
+ max_upload_mb=_parse_positive_int(os.environ.get("OMRKIT_MAX_UPLOAD_MB"), default=15),
51
+ max_files_per_scan=_parse_positive_int(
52
+ os.environ.get("OMRKIT_MAX_FILES_PER_SCAN"), default=20
53
+ ),
54
+ max_pdf_pages=_parse_positive_int(os.environ.get("OMRKIT_MAX_PDF_PAGES"), default=25),
55
+ )