lexgrid 1.0.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.
- lexgrid/__init__.py +38 -0
- lexgrid/client.py +872 -0
- lexgrid/exceptions.py +56 -0
- lexgrid/models.py +121 -0
- lexgrid-1.0.0.dist-info/METADATA +171 -0
- lexgrid-1.0.0.dist-info/RECORD +8 -0
- lexgrid-1.0.0.dist-info/WHEEL +5 -0
- lexgrid-1.0.0.dist-info/top_level.txt +1 -0
lexgrid/__init__.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LexGrid Official Python SDK.
|
|
3
|
+
Deterministic Sovereign Hub for EU Compliance, Regulatory Auditing & Italian Public Procurement.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from .client import LexGridClient
|
|
7
|
+
from .models import (
|
|
8
|
+
AuditMeta,
|
|
9
|
+
ResponseMeta,
|
|
10
|
+
LexGridResponse,
|
|
11
|
+
CertificateVerification,
|
|
12
|
+
)
|
|
13
|
+
from .exceptions import (
|
|
14
|
+
LexGridError,
|
|
15
|
+
LexGridAuthError,
|
|
16
|
+
LexGridRateLimitError,
|
|
17
|
+
AccountingImbalanceError,
|
|
18
|
+
DataIntegrityAlert,
|
|
19
|
+
LexGridNotFoundError,
|
|
20
|
+
LexGridServerError,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__version__ = "1.0.0"
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"LexGridClient",
|
|
27
|
+
"AuditMeta",
|
|
28
|
+
"ResponseMeta",
|
|
29
|
+
"LexGridResponse",
|
|
30
|
+
"CertificateVerification",
|
|
31
|
+
"LexGridError",
|
|
32
|
+
"LexGridAuthError",
|
|
33
|
+
"LexGridRateLimitError",
|
|
34
|
+
"AccountingImbalanceError",
|
|
35
|
+
"DataIntegrityAlert",
|
|
36
|
+
"LexGridNotFoundError",
|
|
37
|
+
"LexGridServerError",
|
|
38
|
+
]
|
lexgrid/client.py
ADDED
|
@@ -0,0 +1,872 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LexGrid Official Python Client.
|
|
3
|
+
Stateless, thread-safe, and zero-dependency HTTP client for the NovaPixel LexGrid API.
|
|
4
|
+
Full coverage of all 20 European Sovereign Compliance Suites & 90 Deterministic Tools.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import urllib.request
|
|
9
|
+
import urllib.error
|
|
10
|
+
from typing import Any, Dict, List, Optional, Union
|
|
11
|
+
|
|
12
|
+
from .exceptions import (
|
|
13
|
+
LexGridError,
|
|
14
|
+
LexGridAuthError,
|
|
15
|
+
LexGridRateLimitError,
|
|
16
|
+
AccountingImbalanceError,
|
|
17
|
+
DataIntegrityAlert,
|
|
18
|
+
LexGridNotFoundError,
|
|
19
|
+
LexGridServerError,
|
|
20
|
+
)
|
|
21
|
+
from .models import LexGridResponse, CertificateVerification
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Mapping of canonical suite identifiers and shorthand aliases
|
|
25
|
+
SUITE_ALIASES: Dict[str, str] = {
|
|
26
|
+
# Shorthand to canonical
|
|
27
|
+
"tax": "eu-tax",
|
|
28
|
+
"fin": "fin-esg",
|
|
29
|
+
"sec": "net-sec",
|
|
30
|
+
"gdpr": "web-gdpr",
|
|
31
|
+
"appalti": "gov-appalti",
|
|
32
|
+
"dora": "dora-nis2",
|
|
33
|
+
"dogane": "customs-cbam",
|
|
34
|
+
"lavoro": "hr-labour",
|
|
35
|
+
"materials": "materials-dpp",
|
|
36
|
+
"energy": "energy-epbd",
|
|
37
|
+
"pii": "sovereign-pii",
|
|
38
|
+
"xbrl": "xbrl-fin",
|
|
39
|
+
"peppol": "einvoice-vida",
|
|
40
|
+
"grants": "grants-funding",
|
|
41
|
+
"carbon": "carbon-factors",
|
|
42
|
+
"ted": "ted-procurement",
|
|
43
|
+
"reach": "chemicals-reach",
|
|
44
|
+
"aml": "aml-compliance",
|
|
45
|
+
"eudr": "agri-food-eudr",
|
|
46
|
+
"mdr": "pharma-medical-mdr",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class _BaseSuite:
|
|
51
|
+
def __init__(self, client: "LexGridClient", suite_id: str):
|
|
52
|
+
self._client = client
|
|
53
|
+
self._suite_id = suite_id
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def suite_id(self) -> str:
|
|
57
|
+
return self._suite_id
|
|
58
|
+
|
|
59
|
+
def call(self, tool: str, payload: Optional[Dict[str, Any]] = None) -> LexGridResponse:
|
|
60
|
+
"""Execute any deterministic tool within this suite."""
|
|
61
|
+
return self._client.call_tool(self._suite_id, tool, payload or {})
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# ==========================================
|
|
65
|
+
# 1. EU Tax, KYB & e-Invoicing (eu-tax / tax)
|
|
66
|
+
# ==========================================
|
|
67
|
+
class EUTaxSuite(_BaseSuite):
|
|
68
|
+
"""Suite 1: EU Tax, KYB, VIES & e-Invoicing."""
|
|
69
|
+
|
|
70
|
+
def verify_vies(self, vat_number: str, country_code: str = "IT", company_name: Optional[str] = None) -> LexGridResponse:
|
|
71
|
+
"""Verify European VAT number on VIES with local Shadow Mirror resilience and sanctions screening."""
|
|
72
|
+
payload: Dict[str, Any] = {"countryCode": country_code, "vatNumber": vat_number}
|
|
73
|
+
if company_name:
|
|
74
|
+
payload["companyName"] = company_name
|
|
75
|
+
return self.call("vies_gleif_kyb_verify", payload)
|
|
76
|
+
|
|
77
|
+
def validate_iban(self, iban: str) -> LexGridResponse:
|
|
78
|
+
"""Validate SEPA IBAN using ISO 7064 Modulo 97 and directory resolution."""
|
|
79
|
+
return self.call("iban_sepa_antifraud", {"iban": iban})
|
|
80
|
+
|
|
81
|
+
def audit_einvoice(self, xml_content: str, mode: str = "audit") -> LexGridResponse:
|
|
82
|
+
"""Audit Italian FatturaPA 1.2.2 / Peppol BIS 3.0 XML against official SDI XSD schemas."""
|
|
83
|
+
return self.call("einvoice_xml_auditor", {"xmlContent": xml_content, "mode": mode})
|
|
84
|
+
|
|
85
|
+
def audit_codice_fiscale(self, codice_fiscale: str) -> LexGridResponse:
|
|
86
|
+
"""Audit Italian Codice Fiscale checksum, omocodia, and demographic cross-match."""
|
|
87
|
+
return self.call("codice_fiscale_audit", {"codiceFiscale": codice_fiscale})
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# ==========================================
|
|
91
|
+
# 2. Financial & ESG Forensics (fin-esg / fin)
|
|
92
|
+
# ==========================================
|
|
93
|
+
class FinEsgSuite(_BaseSuite):
|
|
94
|
+
"""Suite 2: Financial Forensics, Crisis Insolvency & CSRD VSME."""
|
|
95
|
+
|
|
96
|
+
def predict_default(
|
|
97
|
+
self,
|
|
98
|
+
total_assets: float,
|
|
99
|
+
total_liabilities: float,
|
|
100
|
+
equity: float,
|
|
101
|
+
retained_earnings: float,
|
|
102
|
+
ebit: float,
|
|
103
|
+
revenue: float,
|
|
104
|
+
working_capital: Optional[float] = None,
|
|
105
|
+
market_value_equity: Optional[float] = None,
|
|
106
|
+
) -> LexGridResponse:
|
|
107
|
+
"""
|
|
108
|
+
Calculate Altman Z-Score for corporate default risk under CCII (Codice della Crisi d'Impresa).
|
|
109
|
+
Enforces deterministic pre-flight balance sheet sanity check (Assets == Liabilities + Equity).
|
|
110
|
+
"""
|
|
111
|
+
payload: Dict[str, Any] = {
|
|
112
|
+
"total_assets": total_assets,
|
|
113
|
+
"total_liabilities": total_liabilities,
|
|
114
|
+
"equity": equity,
|
|
115
|
+
"retained_earnings": retained_earnings,
|
|
116
|
+
"ebit": ebit,
|
|
117
|
+
"revenue": revenue,
|
|
118
|
+
}
|
|
119
|
+
if working_capital is not None:
|
|
120
|
+
payload["working_capital"] = working_capital
|
|
121
|
+
if market_value_equity is not None:
|
|
122
|
+
payload["market_value_equity"] = market_value_equity
|
|
123
|
+
return self.call("corporate_default_predictor", payload)
|
|
124
|
+
|
|
125
|
+
def detect_anomalies(self, financials: Dict[str, Any]) -> LexGridResponse:
|
|
126
|
+
"""Audit balance sheet manipulation using Beneish M-Score and Benford's Law."""
|
|
127
|
+
return self.call("financial_trend_anomaly", financials)
|
|
128
|
+
|
|
129
|
+
def calculate_csrd_vsme(
|
|
130
|
+
self,
|
|
131
|
+
fuel_liters: float = 0.0,
|
|
132
|
+
natural_gas_kwh: float = 0.0,
|
|
133
|
+
electricity_grid_kwh: float = 0.0,
|
|
134
|
+
employees_count: int = 1,
|
|
135
|
+
) -> LexGridResponse:
|
|
136
|
+
"""Calculate Scope 1 and Scope 2 GHG emissions under EFRAG VSME ESRS E1 standard."""
|
|
137
|
+
return self.call("csrd_esg_calculator", {
|
|
138
|
+
"fuel_liters": fuel_liters,
|
|
139
|
+
"natural_gas_kwh": natural_gas_kwh,
|
|
140
|
+
"electricity_grid_kwh": electricity_grid_kwh,
|
|
141
|
+
"employees_count": employees_count,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
def dcf_wacc_valuation(self, fcf_projections: List[float], terminal_growth_rate: float, cost_of_equity: float, cost_of_debt: float, tax_rate: float, debt_ratio: float) -> LexGridResponse:
|
|
145
|
+
"""Compute DCF enterprise valuation and weighted average cost of capital (WACC)."""
|
|
146
|
+
return self.call("dcf_wacc_valuation", {
|
|
147
|
+
"fcfProjections": fcf_projections,
|
|
148
|
+
"terminalGrowthRate": terminal_growth_rate,
|
|
149
|
+
"costOfEquity": cost_of_equity,
|
|
150
|
+
"costOfDebt": cost_of_debt,
|
|
151
|
+
"taxRate": tax_rate,
|
|
152
|
+
"debtRatio": debt_ratio,
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
# ==========================================
|
|
157
|
+
# 3. NetSec, Deliverability & RDAP (net-sec / sec)
|
|
158
|
+
# ==========================================
|
|
159
|
+
class NetSecSuite(_BaseSuite):
|
|
160
|
+
"""Suite 3: Network Security, Deliverability & RDAP Intel."""
|
|
161
|
+
|
|
162
|
+
def audit_email_deliverability(self, domain: str) -> LexGridResponse:
|
|
163
|
+
"""Audit SPF, DKIM, DMARC, BIMI and MTA-STS records for email deliverability."""
|
|
164
|
+
return self.call("email_deliverability_audit", {"domain": domain})
|
|
165
|
+
|
|
166
|
+
def inspect_tls_http(self, domain: str) -> LexGridResponse:
|
|
167
|
+
"""Inspect TLS 1.3 / X.509 certificate expiry, HSTS, and cipher suites."""
|
|
168
|
+
return self.call("tls_http_inspector", {"domain": domain})
|
|
169
|
+
|
|
170
|
+
def rdap_domain_intel(self, domain: str) -> LexGridResponse:
|
|
171
|
+
"""Retrieve authoritative RDAP domain registration, registrar, and abuse contacts."""
|
|
172
|
+
return self.call("domain_rdap_intel", {"domain": domain})
|
|
173
|
+
|
|
174
|
+
def detect_port_leaks(self, host: str, port_profile: str = "web") -> LexGridResponse:
|
|
175
|
+
"""Safe non-intrusive TCP port reachability screening against SSRF and open services."""
|
|
176
|
+
return self.call("port_leak_detector", {"host": host, "profile": port_profile})
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
# ==========================================
|
|
180
|
+
# 4. Web GDPR & Consent (web-gdpr / gdpr)
|
|
181
|
+
# ==========================================
|
|
182
|
+
class WebGdprSuite(_BaseSuite):
|
|
183
|
+
"""Suite 4: Web GDPR, Cookie CMP & EU AI Act Checker."""
|
|
184
|
+
|
|
185
|
+
def audit_cmp_trackers(self, url: str) -> LexGridResponse:
|
|
186
|
+
"""Audit Cookie CMP banner compliance, Cookiebot/Iubenda integration, and Google Consent Mode v2."""
|
|
187
|
+
return self.call("gdpr_cmp_tracker_audit", {"url": url})
|
|
188
|
+
|
|
189
|
+
def check_eu_ai_act(self, system_description: str, intended_use: str) -> LexGridResponse:
|
|
190
|
+
"""Classify AI system under EU AI Act Regulation (EU) 2024/1689 risk tiers (Prohibited, High-Risk, GPAI)."""
|
|
191
|
+
return self.call("eu_ai_act_check", {"systemDescription": system_description, "intendedUse": intended_use})
|
|
192
|
+
|
|
193
|
+
def profile_b2b_tech(self, domain: str) -> LexGridResponse:
|
|
194
|
+
"""Enrich B2B enterprise tech stack, VAT discovery from legal notices, and CMS profiler."""
|
|
195
|
+
return self.call("b2b_tech_profiler", {"domain": domain})
|
|
196
|
+
|
|
197
|
+
def audit_cookie_dark_patterns(self, url: str) -> LexGridResponse:
|
|
198
|
+
"""Audit cookie banner dark patterns, pre-ticked checkboxes, and asymmetry under EDPB Guidelines."""
|
|
199
|
+
return self.call("cookie_dark_patterns", {"url": url})
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# ==========================================
|
|
203
|
+
# 5. Public Procurement & ANAC (gov-appalti / appalti)
|
|
204
|
+
# ==========================================
|
|
205
|
+
class GovAppaltiSuite(_BaseSuite):
|
|
206
|
+
"""Suite 5: Public Procurement & ANAC Tenders (D.Lgs. 36/2023)."""
|
|
207
|
+
|
|
208
|
+
def calculate_anomaly(
|
|
209
|
+
self,
|
|
210
|
+
bids: List[float],
|
|
211
|
+
method: str = "METODO_A",
|
|
212
|
+
tender_base_price: Optional[float] = None,
|
|
213
|
+
) -> LexGridResponse:
|
|
214
|
+
"""Calculate deterministic anomaly exclusion threshold pursuant to D.Lgs. 36/2023 Art. 110."""
|
|
215
|
+
payload: Dict[str, Any] = {"bids": bids, "method": method}
|
|
216
|
+
if tender_base_price is not None:
|
|
217
|
+
payload["tender_base_price"] = tender_base_price
|
|
218
|
+
return self.call("anomalia_offerte_calculator", payload)
|
|
219
|
+
|
|
220
|
+
def audit_subcontract(
|
|
221
|
+
self,
|
|
222
|
+
category: str,
|
|
223
|
+
contract_amount: float,
|
|
224
|
+
subcontract_amount: float,
|
|
225
|
+
is_siad: bool = False,
|
|
226
|
+
) -> LexGridResponse:
|
|
227
|
+
"""Verify cascade subcontracting limits and mandatory declarations."""
|
|
228
|
+
return self.call(
|
|
229
|
+
"subappalto_cascade_limiter",
|
|
230
|
+
{
|
|
231
|
+
"category": category,
|
|
232
|
+
"contractAmount": contract_amount,
|
|
233
|
+
"subcontractAmount": subcontract_amount,
|
|
234
|
+
"isSiad": is_siad,
|
|
235
|
+
},
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
def validate_cig_cup(self, cig: Optional[str] = None, cup: Optional[str] = None) -> LexGridResponse:
|
|
239
|
+
"""Validate ANAC SmartCIG and public investment CUP alphanumeric format and checksums."""
|
|
240
|
+
return self.call("cig_cup_anac_validator", {"cig": cig, "cup": cup})
|
|
241
|
+
|
|
242
|
+
def calculate_bando_thresholds(self, amount_euro: float, contract_type: str = "lavori") -> LexGridResponse:
|
|
243
|
+
"""Calculate statutory procurement threshold ceilings under EU Directive 2014/24/EU and D.Lgs 36/2023."""
|
|
244
|
+
return self.call("bando_thresholds_calculator", {"amountEuro": amount_euro, "contractType": contract_type})
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
# ==========================================
|
|
248
|
+
# 6. DORA & NIS2 (dora-nis2 / dora)
|
|
249
|
+
# ==========================================
|
|
250
|
+
class DoraNis2Suite(_BaseSuite):
|
|
251
|
+
"""Suite 6: DORA Banking/ICT Resilience & NIS2 Criticality."""
|
|
252
|
+
|
|
253
|
+
def audit_third_party_risk(self, clauses: List[Dict[str, Any]]) -> LexGridResponse:
|
|
254
|
+
"""Audit ICT third-party contracts against mandatory DORA Articles 28-30 requirements."""
|
|
255
|
+
return self.call("dora_third_party_risk", {"clauses": clauses})
|
|
256
|
+
|
|
257
|
+
def classify_nis2_criticality(self, sector: str, employees: int, turnover_eur: float) -> LexGridResponse:
|
|
258
|
+
"""Classify entity as Essential or Important under Directive (EU) 2022/2555 (NIS2)."""
|
|
259
|
+
return self.call("nis2_criticality_classifier", {"sector": sector, "employees": employees, "turnoverEur": turnover_eur})
|
|
260
|
+
|
|
261
|
+
def triage_incident_severity(self, incident_type: str, affected_users: int, duration_hours: float) -> LexGridResponse:
|
|
262
|
+
"""Triage major ICT-related incidents and mandatory CSIRT reporting deadlines."""
|
|
263
|
+
return self.call("incident_severity_triage", {"incidentType": incident_type, "affectedUsers": affected_users, "durationHours": duration_hours})
|
|
264
|
+
|
|
265
|
+
def assess_tlpt_scope(self, critical_functions: List[str]) -> LexGridResponse:
|
|
266
|
+
"""Assess Threat-Led Penetration Testing (TLPT) scope pursuant to TIBER-EU and DORA Art. 26."""
|
|
267
|
+
return self.call("tlpt_threat_led_pentest_scope", {"criticalFunctions": critical_functions})
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
# ==========================================
|
|
271
|
+
# 7. Customs & CBAM (customs-cbam / dogane)
|
|
272
|
+
# ==========================================
|
|
273
|
+
class CustomsCbamSuite(_BaseSuite):
|
|
274
|
+
"""Suite 7: Customs CBAM, TARIC & Dual-Use Export Control."""
|
|
275
|
+
|
|
276
|
+
def calculate_cbam_emissions(self, cn_code: str, imported_quantity_tonnes: float, country_of_origin: str) -> LexGridResponse:
|
|
277
|
+
"""Calculate embedded greenhouse gas emissions and CBAM financial certificate liability under Reg. (EU) 2023/956."""
|
|
278
|
+
return self.call("cbam_embedded_emissions", {"cnCode": cn_code, "importedQuantityTonnes": imported_quantity_tonnes, "countryOfOrigin": country_of_origin})
|
|
279
|
+
|
|
280
|
+
def validate_taric_hs(self, hs_code: str, origin_country: str) -> LexGridResponse:
|
|
281
|
+
"""Validate 8/10-digit TARIC Harmonized System customs code and applicable EU duty rates."""
|
|
282
|
+
return self.call("taric_hs_validator", {"hsCode": hs_code, "originCountry": origin_country})
|
|
283
|
+
|
|
284
|
+
def allocate_incoterms_cost(self, incoterm: str, invoice_value_eur: float, freight_eur: float, insurance_eur: float) -> LexGridResponse:
|
|
285
|
+
"""Allocate freight, insurance, and risk obligations under ICC Incoterms 2020 rules."""
|
|
286
|
+
return self.call("incoterms_cost_allocator", {"incoterm": incoterm, "invoiceValueEur": invoice_value_eur, "freightEur": freight_eur, "insuranceEur": insurance_eur})
|
|
287
|
+
|
|
288
|
+
def screen_dual_use_export(self, item_description: str, destination_country: str) -> LexGridResponse:
|
|
289
|
+
"""Screen dual-use export control classification numbers (ECCN) under Regulation (EU) 2021/821."""
|
|
290
|
+
return self.call("dual_use_export_control", {"itemDescription": item_description, "destinationCountry": destination_country})
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
# ==========================================
|
|
294
|
+
# 8. HR & Labour Law (hr-labour / lavoro)
|
|
295
|
+
# ==========================================
|
|
296
|
+
class HrLabourSuite(_BaseSuite):
|
|
297
|
+
"""Suite 8: HR Labour Law, CCNL Inquadramento & IRPEF Simulator."""
|
|
298
|
+
|
|
299
|
+
def simulate_costo_aziendale(self, gross_annual_salary: float, ccnl: str, level: str) -> LexGridResponse:
|
|
300
|
+
"""Simulate total employer cost (INPS, INAIL, TFR accrual, regional IRAP) under statutory Italian CCNL."""
|
|
301
|
+
return self.call("costo_aziendale_dipendente", {"grossAnnualSalary": gross_annual_salary, "ccnl": ccnl, "level": level})
|
|
302
|
+
|
|
303
|
+
def simulate_lordo_netto(self, gross_annual_salary: float, region: str = "lombardia", months: int = 13) -> LexGridResponse:
|
|
304
|
+
"""Simulate gross-to-net take-home pay with 3-tier IRPEF 2025/2026 reform and regional/municipal surcharges."""
|
|
305
|
+
return self.call("lordo_netto_irpef_simulator", {"grossAnnualSalary": gross_annual_salary, "region": region, "months": months})
|
|
306
|
+
|
|
307
|
+
def audit_ccnl_inquadramento(self, ccnl: str, level: str, duties_description: str) -> LexGridResponse:
|
|
308
|
+
"""Audit statutory employee classification against official collective agreement level descriptors."""
|
|
309
|
+
return self.call("ccnl_inquadramento_audit", {"ccnl": ccnl, "level": level, "dutiesDescription": duties_description})
|
|
310
|
+
|
|
311
|
+
def optimize_fringe_benefits(self, annual_value_eur: float, has_dependent_children: bool = False) -> LexGridResponse:
|
|
312
|
+
"""Optimize corporate fringe benefit packages under TUIR Art. 51 statutory tax-exempt ceilings."""
|
|
313
|
+
return self.call("fringe_benefit_tax_optimizer", {"annualValueEur": annual_value_eur, "hasDependentChildren": has_dependent_children})
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
# ==========================================
|
|
317
|
+
# 9. Materials DPP & CPR (materials-dpp / materials)
|
|
318
|
+
# ==========================================
|
|
319
|
+
class MaterialsDppSuite(_BaseSuite):
|
|
320
|
+
"""Suite 9: Materials DPP, CPR & Critical Raw Materials."""
|
|
321
|
+
|
|
322
|
+
def validate_dpp_payload(self, dpp_json: Dict[str, Any]) -> LexGridResponse:
|
|
323
|
+
"""Validate Digital Product Passport (DPP) payload schemas under Ecodesign ESPR Regulation (EU) 2024/1781."""
|
|
324
|
+
return self.call("dpp_payload_validator", {"dppJson": dpp_json})
|
|
325
|
+
|
|
326
|
+
def audit_construction_materials_cpr(self, dop_number: str, harmonized_standard: str) -> LexGridResponse:
|
|
327
|
+
"""Audit Declaration of Performance (DoP) under Construction Products Regulation (CPR) 305/2011."""
|
|
328
|
+
return self.call("construction_materials_cpr_audit", {"dopNumber": dop_number, "harmonizedStandard": harmonized_standard})
|
|
329
|
+
|
|
330
|
+
def screen_critical_raw_materials(self, materials_list: List[str]) -> LexGridResponse:
|
|
331
|
+
"""Screen raw material inputs against the EU Critical Raw Materials Act (CRMA) list."""
|
|
332
|
+
return self.call("critical_raw_materials_screener", {"materialsList": materials_list})
|
|
333
|
+
|
|
334
|
+
def audit_green_claims(self, claim_statement: str, evidence_type: str) -> LexGridResponse:
|
|
335
|
+
"""Audit corporate environmental claims against the EU Green Claims Directive anti-greenwashing rules."""
|
|
336
|
+
return self.call("green_claims_substantiation_audit", {"claimStatement": claim_statement, "evidenceType": evidence_type})
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
# ==========================================
|
|
340
|
+
# 10. Energy Decarbonization (energy-epbd / energy)
|
|
341
|
+
# ==========================================
|
|
342
|
+
class EnergyEpbdSuite(_BaseSuite):
|
|
343
|
+
"""Suite 10: Energy Decarbonization, Case Green EPBD & ETS 2."""
|
|
344
|
+
|
|
345
|
+
def audit_case_green_epbd(self, building_type: str, current_energy_class: str, primary_energy_kwh_sqm: float) -> LexGridResponse:
|
|
346
|
+
"""Audit residential/non-residential building against EPBD IV 'Case Green' 2030/2033 renovation milestones."""
|
|
347
|
+
return self.call("case_green_epbd_target_audit", {"buildingType": building_type, "currentEnergyClass": current_energy_class, "primaryEnergyKwhSqm": primary_energy_kwh_sqm})
|
|
348
|
+
|
|
349
|
+
def project_ets2_carbon_tax(self, fuel_type: str, annual_consumption: float) -> LexGridResponse:
|
|
350
|
+
"""Project building heating and road transport fuel carbon price surcharges under EU ETS 2."""
|
|
351
|
+
return self.call("ets2_carbon_tax_projector", {"fuelType": fuel_type, "annualConsumption": annual_consumption})
|
|
352
|
+
|
|
353
|
+
def calculate_cer_incentivi_gse(self, solar_capacity_kw: float, shared_energy_kwh: float) -> LexGridResponse:
|
|
354
|
+
"""Calculate GSE feed-in tariffs and 20-year incentive yields for Renewable Energy Communities (CER)."""
|
|
355
|
+
return self.call("cer_incentivi_gse_calculator", {"solarCapacityKw": solar_capacity_kw, "sharedEnergyKwh": shared_energy_kwh})
|
|
356
|
+
|
|
357
|
+
def decompose_arera_bill(self, bill_details: Dict[str, Any]) -> LexGridResponse:
|
|
358
|
+
"""Decompose electricity and gas bills into official ARERA quota energia, trasporto e oneri di sistema."""
|
|
359
|
+
return self.call("arera_bill_decomposer", {"billDetails": bill_details})
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
# ==========================================
|
|
363
|
+
# 11. Sovereign PII & AI Act (sovereign-pii / pii)
|
|
364
|
+
# ==========================================
|
|
365
|
+
class SovereignPiiSuite(_BaseSuite):
|
|
366
|
+
"""Suite 11: Sovereign PII Scrubber & AI Act Governance."""
|
|
367
|
+
|
|
368
|
+
def scrub_eu_pii(self, text: str, redact_mode: str = "anonymize") -> LexGridResponse:
|
|
369
|
+
"""Scrub EU PII (names, tax codes, IBANs, phone numbers, addresses) in volatile RAM with zero retention."""
|
|
370
|
+
return self.call("eu_pii_scrubber", {"text": text, "redactMode": redact_mode})
|
|
371
|
+
|
|
372
|
+
def mask_synthetic_data(self, dataset: List[Dict[str, Any]]) -> LexGridResponse:
|
|
373
|
+
"""Generate statistically valid GDPR Recital 26 compliant synthetic data masks for testing."""
|
|
374
|
+
return self.call("eu_synthetic_data_masker", {"dataset": dataset})
|
|
375
|
+
|
|
376
|
+
def classify_ai_act_risk(self, use_case: str, sector: str, autonomy_level: str) -> LexGridResponse:
|
|
377
|
+
"""Classify AI systems into prohibited, high-risk, limited-risk, or minimal-risk categories under EU AI Act."""
|
|
378
|
+
return self.call("ai_act_risk_classifier", {"useCase": use_case, "sector": sector, "autonomyLevel": autonomy_level})
|
|
379
|
+
|
|
380
|
+
def build_ai_act_technical_dossier(self, system_name: str, model_architecture: str, risk_mitigations: List[str]) -> LexGridResponse:
|
|
381
|
+
"""Generate mandatory Annex IV technical documentation dossier template for high-risk AI systems."""
|
|
382
|
+
return self.call("ai_act_technical_dossier_builder", {"systemName": system_name, "modelArchitecture": model_architecture, "riskMitigations": risk_mitigations})
|
|
383
|
+
|
|
384
|
+
def audit_cross_border_transfer(self, destination_country: str, transfer_mechanism: str) -> LexGridResponse:
|
|
385
|
+
"""Assess international personal data transfers against GDPR Chapter V and Schrems II requirements."""
|
|
386
|
+
return self.call("cross_border_transfer_audit", {"destinationCountry": destination_country, "transferMechanism": transfer_mechanism})
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
# ==========================================
|
|
390
|
+
# 12. XBRL & EU Taxonomy (xbrl-fin / xbrl)
|
|
391
|
+
# ==========================================
|
|
392
|
+
class XbrlFinSuite(_BaseSuite):
|
|
393
|
+
"""Suite 12: Pan-European Registry, XBRL & EU Taxonomy."""
|
|
394
|
+
|
|
395
|
+
def normalize_xbrl_statement(self, xbrl_content: str) -> LexGridResponse:
|
|
396
|
+
"""Normalize ESEF iXBRL financial statement facts and reconcile balance sheet accounting identities."""
|
|
397
|
+
return self.call("xbrl_statement_normalizer", {"xbrlContent": xbrl_content})
|
|
398
|
+
|
|
399
|
+
def lookup_pan_eu_company(self, country_code: str, registration_number: str) -> LexGridResponse:
|
|
400
|
+
"""Query official European Business Registers Interconnection System (BRIS) corporate records."""
|
|
401
|
+
return self.call("pan_eu_company_lookup", {"countryCode": country_code, "registrationNumber": registration_number})
|
|
402
|
+
|
|
403
|
+
def check_eu_taxonomy(self, nace_code: str, activity_type: str) -> LexGridResponse:
|
|
404
|
+
"""Check EU Green Taxonomy eligibility, technical screening criteria, and DNSH conditions."""
|
|
405
|
+
return self.call("eu_taxonomy_checker", {"naceCode": nace_code, "activityType": activity_type})
|
|
406
|
+
|
|
407
|
+
def audit_ubo_beneficial_owners(self, ownership_tree: Dict[str, Any]) -> LexGridResponse:
|
|
408
|
+
"""Traverse multi-tier ownership chains to identify statutory 25%+ Ultimate Beneficial Owners (UBO)."""
|
|
409
|
+
return self.call("ubo_beneficial_owner_audit", {"ownershipTree": ownership_tree})
|
|
410
|
+
|
|
411
|
+
def resolve_esg_emission_factor(self, industry_sector: str, fuel_or_activity: str) -> LexGridResponse:
|
|
412
|
+
"""Resolve certified ESG emission factors from international reporting databases."""
|
|
413
|
+
return self.call("esg_emission_factor_resolver", {"industrySector": industry_sector, "fuelOrActivity": fuel_or_activity})
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
# ==========================================
|
|
417
|
+
# 13. Universal e-Invoicing & ViDA (einvoice-vida / peppol)
|
|
418
|
+
# ==========================================
|
|
419
|
+
class EinvoiceVidaSuite(_BaseSuite):
|
|
420
|
+
"""Suite 13: Universal EU e-Invoicing, ViDA & Peppol BIS 3.0."""
|
|
421
|
+
|
|
422
|
+
def validate_peppol_bis3(self, ubl_xml: str) -> LexGridResponse:
|
|
423
|
+
"""Validate Peppol BIS Billing 3.0 UBL XML against official OpenPEPPOL schematron rules."""
|
|
424
|
+
return self.call("universal_peppol_bis3_validator", {"ublXml": ubl_xml})
|
|
425
|
+
|
|
426
|
+
def compile_xrechnung_zugferd(self, invoice_data: Dict[str, Any], profile: str = "xrechnung") -> LexGridResponse:
|
|
427
|
+
"""Compile valid German XRechnung 3.0 or Franco-German ZUGFeRD / Factur-X electronic invoices."""
|
|
428
|
+
return self.call("xrechnung_zugferd_compiler", {"invoiceData": invoice_data, "profile": profile})
|
|
429
|
+
|
|
430
|
+
def verify_vida_digital_reporting(self, invoice_metadata: Dict[str, Any]) -> LexGridResponse:
|
|
431
|
+
"""Verify VAT in the Digital Age (ViDA) real-time cross-border 2-day digital reporting requirements."""
|
|
432
|
+
return self.call("vida_digital_reporting_checker", {"invoiceMetadata": invoice_metadata})
|
|
433
|
+
|
|
434
|
+
def sanitize_fatturapa_sdi(self, xml_content: str) -> LexGridResponse:
|
|
435
|
+
"""Sanitize Italian FatturaPA 1.2.2 XML and eliminate common rejection codes (00404, 00409, 00418)."""
|
|
436
|
+
return self.call("fatturapa_sdi_sanitizer", {"xmlContent": xml_content})
|
|
437
|
+
|
|
438
|
+
def audit_vat_triangulation(self, party_a_vat: str, party_b_vat: str, party_c_vat: str, delivery_member_state: str) -> LexGridResponse:
|
|
439
|
+
"""Audit intra-community triangular transaction VAT exemption rules under Article 141 Directive 2006/112/EC."""
|
|
440
|
+
return self.call("vat_triangulation_audit", {"partyAVat": party_a_vat, "partyBVat": party_b_vat, "partyCVat": party_c_vat, "deliveryMemberState": delivery_member_state})
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
# ==========================================
|
|
444
|
+
# 14. Grants & State Aid (grants-funding / grants)
|
|
445
|
+
# ==========================================
|
|
446
|
+
class GrantsFundingSuite(_BaseSuite):
|
|
447
|
+
"""Suite 14: EU Grants, State Aid & Transizione 5.0."""
|
|
448
|
+
|
|
449
|
+
def screen_de_minimis_aid(self, prior_aid_entries: List[Dict[str, Any]], requested_amount_eur: float) -> LexGridResponse:
|
|
450
|
+
"""Screen enterprise state aid against the €300,000 De Minimis ceiling under Regulation (EU) 2023/2831."""
|
|
451
|
+
return self.call("de_minimis_state_aid_screener", {"priorAidEntries": prior_aid_entries, "requestedAmountEur": requested_amount_eur})
|
|
452
|
+
|
|
453
|
+
def calculate_transizione_5(self, investment_eur: float, energy_reduction_percent: float, asset_type: str = "beni_materiali_4_0") -> LexGridResponse:
|
|
454
|
+
"""Calculate Italian Piano Transizione 5.0 tax credit rates (up to 45%) based on energy efficiency targets."""
|
|
455
|
+
return self.call("transizione_5_tax_credit_calculator", {"investmentEur": investment_eur, "energyReductionPercent": energy_reduction_percent, "assetType": asset_type})
|
|
456
|
+
|
|
457
|
+
def calculate_horizon_europe_budget(self, direct_personnel_eur: float, subcontracting_eur: float, other_direct_eur: float) -> LexGridResponse:
|
|
458
|
+
"""Calculate Horizon Europe project finances, 25% indirect cost flat rate, and maximum grant shares."""
|
|
459
|
+
return self.call("horizon_europe_budget_calculator", {"directPersonnelEur": direct_personnel_eur, "subcontractingEur": subcontracting_eur, "otherDirectEur": other_direct_eur})
|
|
460
|
+
|
|
461
|
+
def check_gber_aid_intensity(self, enterprise_size: str, region_assisted_status: str, investment_type: str) -> LexGridResponse:
|
|
462
|
+
"""Check maximum allowable regional aid intensity ceilings under General Block Exemption Regulation (GBER)."""
|
|
463
|
+
return self.call("gber_aid_intensity_checker", {"enterpriseSize": enterprise_size, "regionAssistedStatus": region_assisted_status, "investmentType": investment_type})
|
|
464
|
+
|
|
465
|
+
def audit_patent_box_superdeduction(self, eligible_rd_costs_eur: float) -> LexGridResponse:
|
|
466
|
+
"""Audit Italian Patent Box 110% super-deduction for qualifying software, patent, and R&D expenditures."""
|
|
467
|
+
return self.call("patent_box_superdeduction_audit", {"eligibleRdCostsEur": eligible_rd_costs_eur})
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
# ==========================================
|
|
471
|
+
# 15. Carbon Accounting (carbon-factors / carbon)
|
|
472
|
+
# ==========================================
|
|
473
|
+
class CarbonFactorsSuite(_BaseSuite):
|
|
474
|
+
"""Suite 15: Scope 1, 2, 3 GHG Emission Factors & CSRD Carbon Accounting."""
|
|
475
|
+
|
|
476
|
+
def resolve_ispra_grid_electricity(self, kwh_consumed: float, year: int = 2024, calculation_method: str = "location_based") -> LexGridResponse:
|
|
477
|
+
"""Calculate Scope 2 emissions using official Italian ISPRA electricity grid emission factors."""
|
|
478
|
+
return self.call("ispra_grid_electricity_factor", {"kwhConsumed": kwh_consumed, "year": year, "calculationMethod": calculation_method})
|
|
479
|
+
|
|
480
|
+
def calculate_scope1_stationary(self, fuel_type: str, quantity: float, unit: str) -> LexGridResponse:
|
|
481
|
+
"""Calculate Scope 1 GHG emissions from stationary combustion sources (boilers, furnaces, generators)."""
|
|
482
|
+
return self.call("scope1_stationary_combustion", {"fuelType": fuel_type, "quantity": quantity, "unit": unit})
|
|
483
|
+
|
|
484
|
+
def calculate_defra_freight(self, cargo_mass_tonnes: float, distance_km: float, transport_mode: str) -> LexGridResponse:
|
|
485
|
+
"""Calculate freight logistics emissions using UK DEFRA / GLEC Framework transport carbon factors."""
|
|
486
|
+
return self.call("defra_freight_logistics_calculator", {"cargoMassTonnes": cargo_mass_tonnes, "distanceKm": distance_km, "transportMode": transport_mode})
|
|
487
|
+
|
|
488
|
+
def calculate_business_travel_flight(self, origin_airport: str, destination_airport: str, cabin_class: str = "economy") -> LexGridResponse:
|
|
489
|
+
"""Calculate business air travel emissions with radiative forcing index according to ICAO / DEFRA."""
|
|
490
|
+
return self.call("business_travel_flight_calculator", {"originAirport": origin_airport, "destinationAirport": destination_airport, "cabinClass": cabin_class})
|
|
491
|
+
|
|
492
|
+
def calculate_scope3_spend_based(self, spend_amount_eur: float, industry_sector: str) -> LexGridResponse:
|
|
493
|
+
"""Estimate Scope 3 purchased goods and services carbon footprint using Environmentally-Extended Input-Output (EEIO)."""
|
|
494
|
+
return self.call("scope3_spend_based_eeio_calculator", {"spendAmountEur": spend_amount_eur, "industrySector": industry_sector})
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
# ==========================================
|
|
498
|
+
# 16. TED eForms Procurement (ted-procurement / ted)
|
|
499
|
+
# ==========================================
|
|
500
|
+
class TedProcurementSuite(_BaseSuite):
|
|
501
|
+
"""Suite 16: TED eForms, CPV Classifier & European Public Tenders."""
|
|
502
|
+
|
|
503
|
+
def classify_cpv_code(self, keyword_or_description: str) -> LexGridResponse:
|
|
504
|
+
"""Match, search, and validate Common Procurement Vocabulary (CPV) codes for European public tenders."""
|
|
505
|
+
return self.call("cpv_code_classifier_validator", {"keywordOrDescription": keyword_or_description})
|
|
506
|
+
|
|
507
|
+
def validate_ted_eforms(self, eforms_xml: str) -> LexGridResponse:
|
|
508
|
+
"""Validate European public tender notice XML against the official European Commission TED eForms schema."""
|
|
509
|
+
return self.call("ted_eforms_notice_validator", {"eformsXml": eforms_xml})
|
|
510
|
+
|
|
511
|
+
def screen_espd_dgue_eligibility(self, dgue_data: Dict[str, Any]) -> LexGridResponse:
|
|
512
|
+
"""Screen European Single Procurement Document (ESPD / DGUE) economic operator declarations."""
|
|
513
|
+
return self.call("espd_dgue_eligibility_screener", {"dgueData": dgue_data})
|
|
514
|
+
|
|
515
|
+
def calculate_tender_deadlines(self, dispatch_date: str, procedure_type: str, is_electronic: bool = True) -> LexGridResponse:
|
|
516
|
+
"""Calculate statutory minimum tender submission deadlines under EU Directive 2014/24/EU."""
|
|
517
|
+
return self.call("eu_tender_deadlines_calculator", {"dispatchDate": dispatch_date, "procedureType": procedure_type, "isElectronic": is_electronic})
|
|
518
|
+
|
|
519
|
+
def screen_abnormally_low_tender_eu(self, bids: List[float], base_price: Optional[float] = None) -> LexGridResponse:
|
|
520
|
+
"""Screen public tender bids for potential abnormally low offers pursuant to Directive 2014/24/EU Art. 69."""
|
|
521
|
+
return self.call("abnormally_low_tender_eu_screener", {"bids": bids, "basePrice": base_price})
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
# ==========================================
|
|
525
|
+
# 17. Chemicals, REACH & RoHS (chemicals-reach / reach)
|
|
526
|
+
# ==========================================
|
|
527
|
+
class ChemicalsReachSuite(_BaseSuite):
|
|
528
|
+
"""Suite 17: REACH, RoHS 3 & CLP Hazardous Substances."""
|
|
529
|
+
|
|
530
|
+
def screen_reach_svhc(self, substance_identifier: str, concentration_w_w: float) -> LexGridResponse:
|
|
531
|
+
"""Screen chemical substances against the official ECHA REACH SVHC (Substances of Very High Concern) candidate list."""
|
|
532
|
+
return self.call("reach_svhc_threshold_screener", {"substanceIdentifier": substance_identifier, "concentrationWW": concentration_w_w})
|
|
533
|
+
|
|
534
|
+
def check_rohs_substance(self, substance_name: str, concentration_ppm: float) -> LexGridResponse:
|
|
535
|
+
"""Check electrical and electronic equipment components against RoHS 3 Directive 2011/65/EU maximum limits."""
|
|
536
|
+
return self.call("rohs_substance_limit_checker", {"substanceName": substance_name, "concentrationPpm": concentration_ppm})
|
|
537
|
+
|
|
538
|
+
def validate_clp_ufi(self, ufi_code: str, vat_number: Optional[str] = None) -> LexGridResponse:
|
|
539
|
+
"""Validate CLP 16-character Unique Formula Identifier (UFI) checksum and company VAT pairing for poison centers."""
|
|
540
|
+
return self.call("clp_ufi_code_validator", {"ufiCode": ufi_code, "vatNumber": vat_number})
|
|
541
|
+
|
|
542
|
+
def screen_scip_dossier(self, dossier_data: Dict[str, Any]) -> LexGridResponse:
|
|
543
|
+
"""Screen SCIP notification dossier compliance for articles containing SVHC above 0.1% w/w under Waste Framework Directive."""
|
|
544
|
+
return self.call("scip_notification_dossier_screener", {"dossierData": dossier_data})
|
|
545
|
+
|
|
546
|
+
def classify_clp_mixture(self, substances: List[Dict[str, Any]]) -> LexGridResponse:
|
|
547
|
+
"""Classify chemical mixture hazards and GHS pictograms using calculation rules under Regulation (EC) 1272/2008."""
|
|
548
|
+
return self.call("clp_hazard_mixture_classifier", {"substances": substances})
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
# ==========================================
|
|
552
|
+
# 18. AML & Financial Crime (aml-compliance / aml)
|
|
553
|
+
# ==========================================
|
|
554
|
+
class AmlComplianceSuite(_BaseSuite):
|
|
555
|
+
"""Suite 18: EU AMLA, 6AMLD & Financial Crime Prevention."""
|
|
556
|
+
|
|
557
|
+
def score_aml_customer_risk(self, customer_profile: Dict[str, Any]) -> LexGridResponse:
|
|
558
|
+
"""Compute KYC customer money laundering risk score under the EU Single Rulebook (AMLA Regulation)."""
|
|
559
|
+
return self.call("aml_customer_risk_scorer", {"customerProfile": customer_profile})
|
|
560
|
+
|
|
561
|
+
def assess_pep_risk(self, individual_name: str, role_title: str, country: str) -> LexGridResponse:
|
|
562
|
+
"""Assess Politically Exposed Person (PEP) tiered exposure, close associates, and enhanced due diligence triggers."""
|
|
563
|
+
return self.call("pep_tiered_risk_assessor", {"individualName": individual_name, "roleTitle": role_title, "country": country})
|
|
564
|
+
|
|
565
|
+
def audit_cash_payment_limit(self, amount_eur: float, payment_country: str = "IT") -> LexGridResponse:
|
|
566
|
+
"""Audit commercial cash transactions against statutory EU €10,000 ceiling and stricter national thresholds."""
|
|
567
|
+
return self.call("eu_cash_payment_limit_audit", {"amountEur": amount_eur, "paymentCountry": payment_country})
|
|
568
|
+
|
|
569
|
+
def screen_high_risk_jurisdictions(self, country_code: str) -> LexGridResponse:
|
|
570
|
+
"""Screen jurisdictions against FATF Black/Grey lists and European Commission High-Risk Third Countries."""
|
|
571
|
+
return self.call("high_risk_jurisdiction_screener", {"countryCode": country_code})
|
|
572
|
+
|
|
573
|
+
def screen_suspicious_activity(self, transaction_details: Dict[str, Any]) -> LexGridResponse:
|
|
574
|
+
"""Screen transactions against statutory Financial Intelligence Unit (FIU) red flags for STR/SAR reporting."""
|
|
575
|
+
return self.call("aml_suspicious_activity_screener", {"transactionDetails": transaction_details})
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
# ==========================================
|
|
579
|
+
# 19. Agri-Food, EUDR & FIC (agri-food-eudr / eudr)
|
|
580
|
+
# ==========================================
|
|
581
|
+
class AgriFoodEudrSuite(_BaseSuite):
|
|
582
|
+
"""Suite 19: EUDR Deforestation, Food FIC & Contact Materials."""
|
|
583
|
+
|
|
584
|
+
def validate_eudr_statement(self, due_diligence_statement: Dict[str, Any]) -> LexGridResponse:
|
|
585
|
+
"""Validate EUDR Deforestation Due Diligence Statements (DDS) for TRACES NT platform submission under Reg. (EU) 2023/1115."""
|
|
586
|
+
return self.call("eudr_due_diligence_statement_validator", {"dueDiligenceStatement": due_diligence_statement})
|
|
587
|
+
|
|
588
|
+
def verify_eudr_polygon(self, coordinates: List[List[float]], production_date: str) -> LexGridResponse:
|
|
589
|
+
"""Verify geolocation polygon coordinates and satellite deforestation cut-off status (post Dec 31, 2020)."""
|
|
590
|
+
return self.call("eudr_polygon_geolocation_verifier", {"coordinates": coordinates, "productionDate": production_date})
|
|
591
|
+
|
|
592
|
+
def screen_food_allergen_nutrition(self, label_text: str, language: str = "it") -> LexGridResponse:
|
|
593
|
+
"""Screen mandatory allergen highlighting and Big 8 nutrition declarations under FIC Regulation (EU) 1169/2011."""
|
|
594
|
+
return self.call("food_allergen_nutrition_label_screener", {"labelText": label_text, "language": language})
|
|
595
|
+
|
|
596
|
+
def audit_geographical_indication(self, denomination: str, product_category: str) -> LexGridResponse:
|
|
597
|
+
"""Audit protected designations of origin (DOP, IGP, STG) against the European eAmbrosia geographical registry."""
|
|
598
|
+
return self.call("geographical_indication_pdo_pgi_audit", {"denomination": denomination, "productCategory": product_category})
|
|
599
|
+
|
|
600
|
+
def screen_food_contact_materials(self, material_type: str, test_migration_mg_dm2: float) -> LexGridResponse:
|
|
601
|
+
"""Screen food contact materials (MOCA) overall migration limits under Regulation (EC) No 1935/2004."""
|
|
602
|
+
return self.call("food_contact_materials_fcm_screener", {"materialType": material_type, "testMigrationMgDm2": test_migration_mg_dm2})
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
# ==========================================
|
|
606
|
+
# 20. Pharma & Medical Devices (pharma-medical-mdr / mdr)
|
|
607
|
+
# ==========================================
|
|
608
|
+
class PharmaMedicalMdrSuite(_BaseSuite):
|
|
609
|
+
"""Suite 20: EU MDR, IVDR & Pharma Serialization."""
|
|
610
|
+
|
|
611
|
+
def classify_mdr_device(self, intended_purpose: str, is_invasive: bool, is_active: bool, duration_days: int) -> LexGridResponse:
|
|
612
|
+
"""Classify medical devices into Class I, IIa, IIb, or III under Regulation (EU) 2017/745 (MDR) Annex VIII."""
|
|
613
|
+
return self.call("mdr_device_classification_engine", {"intendedPurpose": intended_purpose, "isInvasive": is_invasive, "isActive": is_active, "durationDays": duration_days})
|
|
614
|
+
|
|
615
|
+
def validate_eudamed_udi(self, basic_udi_di: str) -> LexGridResponse:
|
|
616
|
+
"""Validate European EUDAMED Basic UDI-DI string syntax and check digit algorithms (GS1 / HIBCC)."""
|
|
617
|
+
return self.call("eudamed_udi_di_validator", {"basicUdiDi": basic_udi_di})
|
|
618
|
+
|
|
619
|
+
def screen_mdr_clinical_evaluation(self, device_class: str, clinical_data_summary: Dict[str, Any]) -> LexGridResponse:
|
|
620
|
+
"""Screen clinical evaluation plan (CEP/CER) sufficiency and equivalence requirements under MDR Art. 61."""
|
|
621
|
+
return self.call("mdr_clinical_evaluation_screener", {"deviceClass": device_class, "clinicalDataSummary": clinical_data_summary})
|
|
622
|
+
|
|
623
|
+
def calculate_vigilance_timelines(self, incident_type: str, occurrence_date: str) -> LexGridResponse:
|
|
624
|
+
"""Calculate statutory serious incident reporting deadlines to Competent Authorities under MDR Art. 87."""
|
|
625
|
+
return self.call("mdr_vigilance_reporting_timeline_calculator", {"incidentType": incident_type, "occurrenceDate": occurrence_date})
|
|
626
|
+
|
|
627
|
+
def audit_fmd_serialization(self, gtin: str, serial_number: str, batch: str, expiry: str) -> LexGridResponse:
|
|
628
|
+
"""Audit pharmaceutical packaging 2D DataMatrix barcode identifiers under Falsified Medicines Directive (FMD)."""
|
|
629
|
+
return self.call("fmd_pharma_serialization_matrix_auditor", {"gtin": gtin, "serialNumber": serial_number, "batch": batch, "expiry": expiry})
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
# ==========================================
|
|
633
|
+
# Master LexGrid Client
|
|
634
|
+
# ==========================================
|
|
635
|
+
class LexGridClient:
|
|
636
|
+
"""
|
|
637
|
+
Main client for interacting with the NovaPixel LexGrid Sovereign Compliance Hub.
|
|
638
|
+
Covers all 20 specialized suites and 90 deterministic tools.
|
|
639
|
+
|
|
640
|
+
Example:
|
|
641
|
+
>>> from lexgrid import LexGridClient
|
|
642
|
+
>>> client = LexGridClient(api_key="your-api-key")
|
|
643
|
+
>>> vies = client.eu_tax.verify_vies("01234567890", country_code="IT")
|
|
644
|
+
>>> print(vies.data["is_valid"], vies.certificate_id)
|
|
645
|
+
"""
|
|
646
|
+
|
|
647
|
+
def __init__(
|
|
648
|
+
self,
|
|
649
|
+
api_key: Optional[str] = None,
|
|
650
|
+
base_url: str = "https://lexgrid.novapixel.it",
|
|
651
|
+
timeout: float = 30.0,
|
|
652
|
+
):
|
|
653
|
+
self.api_key = api_key
|
|
654
|
+
self.base_url = base_url.rstrip("/")
|
|
655
|
+
self.timeout = timeout
|
|
656
|
+
|
|
657
|
+
# 1. Official Canonical Suites
|
|
658
|
+
self.eu_tax = EUTaxSuite(self, "eu-tax")
|
|
659
|
+
self.fin_esg = FinEsgSuite(self, "fin-esg")
|
|
660
|
+
self.net_sec = NetSecSuite(self, "net-sec")
|
|
661
|
+
self.web_gdpr = WebGdprSuite(self, "web-gdpr")
|
|
662
|
+
self.gov_appalti = GovAppaltiSuite(self, "gov-appalti")
|
|
663
|
+
self.dora_nis2 = DoraNis2Suite(self, "dora-nis2")
|
|
664
|
+
self.customs_cbam = CustomsCbamSuite(self, "customs-cbam")
|
|
665
|
+
self.hr_labour = HrLabourSuite(self, "hr-labour")
|
|
666
|
+
self.materials_dpp = MaterialsDppSuite(self, "materials-dpp")
|
|
667
|
+
self.energy_epbd = EnergyEpbdSuite(self, "energy-epbd")
|
|
668
|
+
self.sovereign_pii = SovereignPiiSuite(self, "sovereign-pii")
|
|
669
|
+
self.xbrl_fin = XbrlFinSuite(self, "xbrl-fin")
|
|
670
|
+
self.einvoice_vida = EinvoiceVidaSuite(self, "einvoice-vida")
|
|
671
|
+
self.grants_funding = GrantsFundingSuite(self, "grants-funding")
|
|
672
|
+
self.carbon_factors = CarbonFactorsSuite(self, "carbon-factors")
|
|
673
|
+
self.ted_procurement = TedProcurementSuite(self, "ted-procurement")
|
|
674
|
+
self.chemicals_reach = ChemicalsReachSuite(self, "chemicals-reach")
|
|
675
|
+
self.aml_compliance = AmlComplianceSuite(self, "aml-compliance")
|
|
676
|
+
self.agri_food_eudr = AgriFoodEudrSuite(self, "agri-food-eudr")
|
|
677
|
+
self.pharma_medical_mdr = PharmaMedicalMdrSuite(self, "pharma-medical-mdr")
|
|
678
|
+
|
|
679
|
+
# 2. Ergonomic Shorthand Aliases
|
|
680
|
+
self.tax = self.eu_tax
|
|
681
|
+
self.fin = self.fin_esg
|
|
682
|
+
self.sec = self.net_sec
|
|
683
|
+
self.gdpr = self.web_gdpr
|
|
684
|
+
self.appalti = self.gov_appalti
|
|
685
|
+
self.dora = self.dora_nis2
|
|
686
|
+
self.dogane = self.customs_cbam
|
|
687
|
+
self.lavoro = self.hr_labour
|
|
688
|
+
self.materials = self.materials_dpp
|
|
689
|
+
self.energy = self.energy_epbd
|
|
690
|
+
self.pii = self.sovereign_pii
|
|
691
|
+
self.xbrl = self.xbrl_fin
|
|
692
|
+
self.peppol = self.einvoice_vida
|
|
693
|
+
self.grants = self.grants_funding
|
|
694
|
+
self.carbon = self.carbon_factors
|
|
695
|
+
self.ted = self.ted_procurement
|
|
696
|
+
self.reach = self.chemicals_reach
|
|
697
|
+
self.aml = self.aml_compliance
|
|
698
|
+
self.eudr = self.agri_food_eudr
|
|
699
|
+
self.mdr = self.pharma_medical_mdr
|
|
700
|
+
|
|
701
|
+
self._suite_registry: Dict[str, _BaseSuite] = {
|
|
702
|
+
"eu-tax": self.eu_tax,
|
|
703
|
+
"fin-esg": self.fin_esg,
|
|
704
|
+
"net-sec": self.net_sec,
|
|
705
|
+
"web-gdpr": self.web_gdpr,
|
|
706
|
+
"gov-appalti": self.gov_appalti,
|
|
707
|
+
"dora-nis2": self.dora_nis2,
|
|
708
|
+
"customs-cbam": self.customs_cbam,
|
|
709
|
+
"hr-labour": self.hr_labour,
|
|
710
|
+
"materials-dpp": self.materials_dpp,
|
|
711
|
+
"energy-epbd": self.energy_epbd,
|
|
712
|
+
"sovereign-pii": self.sovereign_pii,
|
|
713
|
+
"xbrl-fin": self.xbrl_fin,
|
|
714
|
+
"einvoice-vida": self.einvoice_vida,
|
|
715
|
+
"grants-funding": self.grants_funding,
|
|
716
|
+
"carbon-factors": self.carbon_factors,
|
|
717
|
+
"ted-procurement": self.ted_procurement,
|
|
718
|
+
"chemicals-reach": self.chemicals_reach,
|
|
719
|
+
"aml-compliance": self.aml_compliance,
|
|
720
|
+
"agri-food-eudr": self.agri_food_eudr,
|
|
721
|
+
"pharma-medical-mdr": self.pharma_medical_mdr,
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
def suite(self, suite_identifier: str) -> _BaseSuite:
|
|
725
|
+
"""Access any suite by name or shorthand alias (e.g. 'tax', 'eu-tax', 'dora')."""
|
|
726
|
+
clean_id = suite_identifier.lower().replace("_", "-")
|
|
727
|
+
canonical = SUITE_ALIASES.get(clean_id, clean_id)
|
|
728
|
+
if canonical in self._suite_registry:
|
|
729
|
+
return self._suite_registry[canonical]
|
|
730
|
+
# Return generic dynamic suite proxy if not found
|
|
731
|
+
return _BaseSuite(self, canonical)
|
|
732
|
+
|
|
733
|
+
def __enter__(self) -> "LexGridClient":
|
|
734
|
+
return self
|
|
735
|
+
|
|
736
|
+
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
|
|
737
|
+
pass
|
|
738
|
+
|
|
739
|
+
def call_tool(self, suite: str, tool: str, payload: Optional[Dict[str, Any]] = None) -> LexGridResponse:
|
|
740
|
+
"""
|
|
741
|
+
Low-level execution call for any of the 20 LexGrid suites and 90 tools.
|
|
742
|
+
Automatically verifies Zero-Data-Retention response headers and parses audit metadata.
|
|
743
|
+
"""
|
|
744
|
+
clean_suite = suite.lower().replace("_", "-")
|
|
745
|
+
canonical_suite = SUITE_ALIASES.get(clean_suite, clean_suite)
|
|
746
|
+
clean_tool = tool.strip()
|
|
747
|
+
|
|
748
|
+
endpoint = f"{self.base_url}/v1/{canonical_suite}/{clean_tool}"
|
|
749
|
+
body_bytes = json.dumps(payload or {}).encode("utf-8")
|
|
750
|
+
|
|
751
|
+
headers = {
|
|
752
|
+
"Content-Type": "application/json",
|
|
753
|
+
"Accept": "application/json",
|
|
754
|
+
"User-Agent": "LexGrid-Python-SDK/1.0.0",
|
|
755
|
+
}
|
|
756
|
+
if self.api_key:
|
|
757
|
+
headers["X-API-Key"] = self.api_key
|
|
758
|
+
|
|
759
|
+
req = urllib.request.Request(endpoint, data=body_bytes, headers=headers, method="POST")
|
|
760
|
+
|
|
761
|
+
try:
|
|
762
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as response:
|
|
763
|
+
response_data = json.loads(response.read().decode("utf-8"))
|
|
764
|
+
return LexGridResponse.from_dict(response_data)
|
|
765
|
+
except urllib.error.HTTPError as err:
|
|
766
|
+
err_body = err.read().decode("utf-8")
|
|
767
|
+
try:
|
|
768
|
+
err_json = json.loads(err_body)
|
|
769
|
+
err_msg = err_json.get("error", err_json.get("message", err_body))
|
|
770
|
+
except Exception:
|
|
771
|
+
err_msg = err_body
|
|
772
|
+
|
|
773
|
+
if err.code in (401, 403):
|
|
774
|
+
raise LexGridAuthError(f"Authentication failed: {err_msg}", status_code=err.code)
|
|
775
|
+
elif err.code == 429:
|
|
776
|
+
raise LexGridRateLimitError(f"Rate limit exceeded: {err_msg}", status_code=err.code)
|
|
777
|
+
elif "ACCOUNTING_IMBALANCE_DETECTED" in err_msg or "PLAUSIBILITY_SIGN_ERROR" in err_msg:
|
|
778
|
+
raise AccountingImbalanceError(
|
|
779
|
+
f"Pre-Flight Sanity Check failed: {err_msg}",
|
|
780
|
+
status_code=err.code,
|
|
781
|
+
details=err_body,
|
|
782
|
+
)
|
|
783
|
+
elif "DATA_INTEGRITY_ALERT" in err_msg:
|
|
784
|
+
raise DataIntegrityAlert(
|
|
785
|
+
f"Data integrity alert: {err_msg}",
|
|
786
|
+
status_code=err.code,
|
|
787
|
+
details=err_body,
|
|
788
|
+
)
|
|
789
|
+
elif err.code == 404:
|
|
790
|
+
raise LexGridNotFoundError(f"Endpoint or resource not found: {err_msg}", status_code=404)
|
|
791
|
+
elif err.code >= 500:
|
|
792
|
+
raise LexGridServerError(f"Server error: {err_msg}", status_code=err.code)
|
|
793
|
+
else:
|
|
794
|
+
raise LexGridError(f"LexGrid API Error ({err.code}): {err_msg}", status_code=err.code)
|
|
795
|
+
except urllib.error.URLError as err:
|
|
796
|
+
raise LexGridServerError(f"Network connection failed: {err.reason}")
|
|
797
|
+
|
|
798
|
+
def get_certificate(self, certificate_id: str) -> CertificateVerification:
|
|
799
|
+
"""
|
|
800
|
+
Retrieve official statutory verification proof for an issued certificate ID.
|
|
801
|
+
"""
|
|
802
|
+
clean_id = certificate_id.strip().upper()
|
|
803
|
+
url = f"{self.base_url}/verify/{clean_id}?format=json"
|
|
804
|
+
|
|
805
|
+
req = urllib.request.Request(
|
|
806
|
+
url,
|
|
807
|
+
headers={
|
|
808
|
+
"Accept": "application/json",
|
|
809
|
+
"User-Agent": "LexGrid-Python-SDK/1.0.0",
|
|
810
|
+
},
|
|
811
|
+
method="GET",
|
|
812
|
+
)
|
|
813
|
+
|
|
814
|
+
try:
|
|
815
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as resp:
|
|
816
|
+
data = json.loads(resp.read().decode("utf-8"))
|
|
817
|
+
return CertificateVerification.from_dict(data)
|
|
818
|
+
except urllib.error.HTTPError as err:
|
|
819
|
+
if err.code == 404:
|
|
820
|
+
raise LexGridNotFoundError(f"Certificate {clean_id} not found in registry", status_code=404)
|
|
821
|
+
raise LexGridError(f"Failed to fetch certificate: {err.read().decode('utf-8')}", status_code=err.code)
|
|
822
|
+
|
|
823
|
+
def recheck_certificate(self, certificate_id: str, candidate_data: Any) -> Dict[str, Any]:
|
|
824
|
+
"""
|
|
825
|
+
Verify if candidate data matches the certified SHA-256 fingerprint registered in the verification registry.
|
|
826
|
+
"""
|
|
827
|
+
url = f"{self.base_url}/api/verify/recheck"
|
|
828
|
+
body_bytes = json.dumps({
|
|
829
|
+
"certificate_id": certificate_id.strip().upper(),
|
|
830
|
+
"candidate_data": candidate_data,
|
|
831
|
+
}).encode("utf-8")
|
|
832
|
+
|
|
833
|
+
req = urllib.request.Request(
|
|
834
|
+
url,
|
|
835
|
+
data=body_bytes,
|
|
836
|
+
headers={
|
|
837
|
+
"Content-Type": "application/json",
|
|
838
|
+
"Accept": "application/json",
|
|
839
|
+
"User-Agent": "LexGrid-Python-SDK/1.0.0",
|
|
840
|
+
},
|
|
841
|
+
method="POST",
|
|
842
|
+
)
|
|
843
|
+
|
|
844
|
+
try:
|
|
845
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as resp:
|
|
846
|
+
return json.loads(resp.read().decode("utf-8"))
|
|
847
|
+
except urllib.error.HTTPError as err:
|
|
848
|
+
raise LexGridError(f"Recheck failed: {err.read().decode('utf-8')}", status_code=err.code)
|
|
849
|
+
|
|
850
|
+
def download_dossier_html(self, certificate_id: str) -> str:
|
|
851
|
+
"""
|
|
852
|
+
Download the official printable HTML Dossier for court or administrative record inclusion.
|
|
853
|
+
"""
|
|
854
|
+
clean_id = certificate_id.strip().upper()
|
|
855
|
+
url = f"{self.base_url}/verify/{clean_id}/dossier"
|
|
856
|
+
|
|
857
|
+
req = urllib.request.Request(
|
|
858
|
+
url,
|
|
859
|
+
headers={
|
|
860
|
+
"Accept": "text/html",
|
|
861
|
+
"User-Agent": "LexGrid-Python-SDK/1.0.0",
|
|
862
|
+
},
|
|
863
|
+
method="GET",
|
|
864
|
+
)
|
|
865
|
+
|
|
866
|
+
try:
|
|
867
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as resp:
|
|
868
|
+
return resp.read().decode("utf-8")
|
|
869
|
+
except urllib.error.HTTPError as err:
|
|
870
|
+
if err.code == 404:
|
|
871
|
+
raise LexGridNotFoundError(f"Dossier {clean_id} not found", status_code=404)
|
|
872
|
+
raise LexGridError(f"Failed to download dossier: {err}", status_code=err.code)
|
lexgrid/exceptions.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LexGrid SDK Custom Exceptions.
|
|
3
|
+
Provides structured, actionable error handling across all regulatory and statutory suites.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Optional, Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class LexGridError(Exception):
|
|
10
|
+
"""Base exception for all LexGrid SDK errors."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, message: str, status_code: Optional[int] = None, details: Optional[Any] = None):
|
|
13
|
+
super().__init__(message)
|
|
14
|
+
self.message = message
|
|
15
|
+
self.status_code = status_code
|
|
16
|
+
self.details = details
|
|
17
|
+
|
|
18
|
+
def __repr__(self) -> str:
|
|
19
|
+
return f"{self.__class__.__name__}(message={self.message!r}, status_code={self.status_code})"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class LexGridAuthError(LexGridError):
|
|
23
|
+
"""Raised when authentication fails (invalid API Key or insufficient credits)."""
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class LexGridRateLimitError(LexGridError):
|
|
28
|
+
"""Raised when free-trial or API key quota limit is exceeded."""
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class AccountingImbalanceError(LexGridError):
|
|
33
|
+
"""
|
|
34
|
+
Raised by LexGrid Pre-Flight Sanity Engine when balance sheet accounting identities fail:
|
|
35
|
+
Total Assets != Total Liabilities + Equity (tolerance > 1.00 €) or plausible sign errors occur.
|
|
36
|
+
Prevents GIGO (Garbage In, Garbage Out) and hallucinations before calculating insolvency indices.
|
|
37
|
+
"""
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class DataIntegrityAlert(LexGridError):
|
|
42
|
+
"""
|
|
43
|
+
Raised when forensic data anomalies are detected (e.g. Benford's Law Chi-Square deviations
|
|
44
|
+
or Receivables DSO outliers > 2.5x annual revenue).
|
|
45
|
+
"""
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class LexGridNotFoundError(LexGridError):
|
|
50
|
+
"""Raised when an audit certificate or requested entity is not found in the registry."""
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class LexGridServerError(LexGridError):
|
|
55
|
+
"""Raised on upstream or temporary internal server issues."""
|
|
56
|
+
pass
|
lexgrid/models.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LexGrid SDK Data Models.
|
|
3
|
+
Includes dataclass representations for verifiable audit metadata, responses, and certificates.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from typing import Any, Dict, Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class AuditMeta:
|
|
12
|
+
"""Verifiable cryptographic audit block returned on every LexGrid execution."""
|
|
13
|
+
certificate_id: str
|
|
14
|
+
verification_url: str
|
|
15
|
+
normative_ref: str
|
|
16
|
+
tables_version: str
|
|
17
|
+
last_verified_at: str
|
|
18
|
+
deterministic_hash: str
|
|
19
|
+
digital_seal: str
|
|
20
|
+
zero_data_retention_certified: bool = True
|
|
21
|
+
|
|
22
|
+
@classmethod
|
|
23
|
+
def from_dict(cls, data: Dict[str, Any]) -> "AuditMeta":
|
|
24
|
+
return cls(
|
|
25
|
+
certificate_id=data.get("certificate_id", ""),
|
|
26
|
+
verification_url=data.get("verification_url", ""),
|
|
27
|
+
normative_ref=data.get("normative_ref", ""),
|
|
28
|
+
tables_version=data.get("tables_version", ""),
|
|
29
|
+
last_verified_at=data.get("last_verified_at", ""),
|
|
30
|
+
deterministic_hash=data.get("deterministic_hash", ""),
|
|
31
|
+
digital_seal=data.get("digital_seal", ""),
|
|
32
|
+
zero_data_retention_certified=data.get("zero_data_retention_certified", True),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class ResponseMeta:
|
|
38
|
+
"""Server and execution metadata."""
|
|
39
|
+
provider: str
|
|
40
|
+
timestamp: str
|
|
41
|
+
auth_method: str
|
|
42
|
+
disclaimer: str
|
|
43
|
+
execution_ms: Optional[int] = None
|
|
44
|
+
|
|
45
|
+
@classmethod
|
|
46
|
+
def from_dict(cls, data: Dict[str, Any]) -> "ResponseMeta":
|
|
47
|
+
return cls(
|
|
48
|
+
provider=data.get("provider", "NovaPixel LexGrid"),
|
|
49
|
+
timestamp=data.get("timestamp", ""),
|
|
50
|
+
auth_method=data.get("auth_method", "free_trial"),
|
|
51
|
+
disclaimer=data.get("disclaimer", ""),
|
|
52
|
+
execution_ms=data.get("execution_ms"),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass
|
|
57
|
+
class LexGridResponse:
|
|
58
|
+
"""Standard typed response container for all LexGrid tool calls."""
|
|
59
|
+
status: str
|
|
60
|
+
suite: str
|
|
61
|
+
tool: str
|
|
62
|
+
deterministic_execution: bool
|
|
63
|
+
data: Any
|
|
64
|
+
audit_meta: AuditMeta
|
|
65
|
+
meta: ResponseMeta
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def certificate_id(self) -> str:
|
|
69
|
+
return self.audit_meta.certificate_id
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def verification_url(self) -> str:
|
|
73
|
+
return self.audit_meta.verification_url
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def from_dict(cls, payload: Dict[str, Any]) -> "LexGridResponse":
|
|
77
|
+
return cls(
|
|
78
|
+
status=payload.get("status", "success"),
|
|
79
|
+
suite=payload.get("suite", ""),
|
|
80
|
+
tool=payload.get("tool", ""),
|
|
81
|
+
deterministic_execution=payload.get("deterministic_execution", True),
|
|
82
|
+
data=payload.get("data", {}),
|
|
83
|
+
audit_meta=AuditMeta.from_dict(payload.get("_audit_meta", {})),
|
|
84
|
+
meta=ResponseMeta.from_dict(payload.get("meta", {})),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@dataclass
|
|
89
|
+
class CertificateVerification:
|
|
90
|
+
"""Official verification record returned by the LexGrid Statutory Verification Engine."""
|
|
91
|
+
status: str
|
|
92
|
+
certificate_id: str
|
|
93
|
+
authority: str
|
|
94
|
+
normative_ref: str
|
|
95
|
+
suite_id: str
|
|
96
|
+
tool_name: str
|
|
97
|
+
tables_version: str
|
|
98
|
+
deterministic_hash: str
|
|
99
|
+
digital_seal: str
|
|
100
|
+
auth_method: str
|
|
101
|
+
issued_at: str
|
|
102
|
+
verification_url: str
|
|
103
|
+
zero_data_retention_certified: bool = True
|
|
104
|
+
|
|
105
|
+
@classmethod
|
|
106
|
+
def from_dict(cls, data: Dict[str, Any]) -> "CertificateVerification":
|
|
107
|
+
return cls(
|
|
108
|
+
status=data.get("status", ""),
|
|
109
|
+
certificate_id=data.get("certificate_id", ""),
|
|
110
|
+
authority=data.get("authority", ""),
|
|
111
|
+
normative_ref=data.get("normative_ref", ""),
|
|
112
|
+
suite_id=data.get("suite_id", ""),
|
|
113
|
+
tool_name=data.get("tool_name", ""),
|
|
114
|
+
tables_version=data.get("tables_version", ""),
|
|
115
|
+
deterministic_hash=data.get("deterministic_hash", ""),
|
|
116
|
+
digital_seal=data.get("digital_seal", ""),
|
|
117
|
+
auth_method=data.get("auth_method", ""),
|
|
118
|
+
issued_at=data.get("issued_at", ""),
|
|
119
|
+
verification_url=data.get("verification_url", ""),
|
|
120
|
+
zero_data_retention_certified=data.get("zero_data_retention_certified", True),
|
|
121
|
+
)
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lexgrid
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python SDK for NovaPixel LexGrid — Sovereign EU Compliance, Regulatory Auditing & Statutory Verification Engine
|
|
5
|
+
Author-email: NovaPixel <lexgrid@novapixel.it>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://lexgrid.novapixel.it
|
|
8
|
+
Project-URL: Documentation, https://lexgrid.novapixel.it/openapi.json
|
|
9
|
+
Project-URL: Compliance & DPO, https://lexgrid.novapixel.it/compliance-policy
|
|
10
|
+
Project-URL: Verification Registry, https://lexgrid.novapixel.it/verify/LG-2026-B81C-9E4F-2A7D
|
|
11
|
+
Keywords: compliance,mcp,ai-agents,vies,anac,altman-z-score,appalti,csrd,gdpr,sovereign-ai,langchain,crewai
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
15
|
+
Classifier: Intended Audience :: Legal Industry
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
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 :: Security
|
|
23
|
+
Classifier: Topic :: Office/Business :: Financial :: Accounting
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
29
|
+
Requires-Dist: httpx>=0.25.0; extra == "dev"
|
|
30
|
+
|
|
31
|
+
# LexGrid Python SDK 🏛️⚡
|
|
32
|
+
|
|
33
|
+
> **Official Python Client for NovaPixel LexGrid — Sovereign EU Compliance, Regulatory Auditing & Statutory Verification Engine.**
|
|
34
|
+
|
|
35
|
+
Zero external dependencies (`urllib`-native). Thread-safe. Conforming to **Strict Zero-Data-Retention (ZDR)** and returning verifiable cryptographic **Audit Certificates** (`_audit_meta`) with every execution.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 📦 Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install lexgrid
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
*(Or copy the `lexgrid` directory directly into your project — zero 3rd party runtime dependencies required)*
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 🚀 Quickstart
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from lexgrid import LexGridClient, AccountingImbalanceError
|
|
53
|
+
|
|
54
|
+
# 1. Initialize client with your API Key
|
|
55
|
+
client = LexGridClient(api_key="your-api-key")
|
|
56
|
+
|
|
57
|
+
# 2. Check European VAT on VIES with Local Shadow Mirror resilience
|
|
58
|
+
vies = client.eu_tax.verify_vies("IT01234567890", company_name="NovaPixel S.r.l.")
|
|
59
|
+
print("Valid:", vies.data["is_valid"])
|
|
60
|
+
print("Official Certificate ID:", vies.certificate_id)
|
|
61
|
+
print("Verification Link:", vies.verification_url)
|
|
62
|
+
|
|
63
|
+
# 3. Calculate Public Procurement Anomaly Threshold ex D.Lgs. 36/2023 Art. 110
|
|
64
|
+
tender = client.gov_appalti.calculate_anomaly(
|
|
65
|
+
bids=[12.5, 14.2, 10.8, 15.0, 13.9, 11.4],
|
|
66
|
+
method="METODO_A",
|
|
67
|
+
tender_base_price=250000.0,
|
|
68
|
+
)
|
|
69
|
+
print("Exclusion Threshold:", tender.data["anomaly_threshold"])
|
|
70
|
+
print("Normative Reference:", tender.audit_meta.normative_ref)
|
|
71
|
+
|
|
72
|
+
# 4. Altman Z-Score with Pre-Flight Balance Sheet Sanity Guard
|
|
73
|
+
try:
|
|
74
|
+
default_risk = client.fin_esg.predict_default(
|
|
75
|
+
total_assets=1000000.0,
|
|
76
|
+
total_liabilities=600000.0,
|
|
77
|
+
equity=400000.0, # Assets == Liabilities + Equity (Exact balance)
|
|
78
|
+
retained_earnings=150000.0,
|
|
79
|
+
ebit=95000.0,
|
|
80
|
+
revenue=1200000.0,
|
|
81
|
+
)
|
|
82
|
+
print("Z-Score:", default_risk.data["z_score"])
|
|
83
|
+
print("Risk Level:", default_risk.data["risk_band"])
|
|
84
|
+
except AccountingImbalanceError as e:
|
|
85
|
+
# Catches GIGO (Garbage In, Garbage Out) and OCR hallucinations before calculation
|
|
86
|
+
print(f"Audit Blocked: {e.message}")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 🔍 Verifying Statutory Audit Certificates
|
|
92
|
+
|
|
93
|
+
Every response from LexGrid is accompanied by a cryptographic certificate (`_audit_meta`):
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
# Verify certificate in the statutory registry
|
|
97
|
+
cert = client.get_certificate("LG-2026-B81C-9E4F-2A7D")
|
|
98
|
+
print("Status:", cert.status) # "VALID_OFFICIALLY_ISSUED"
|
|
99
|
+
print("Deterministic Hash:", cert.deterministic_hash)
|
|
100
|
+
print("Digital Seal:", cert.digital_seal)
|
|
101
|
+
|
|
102
|
+
# Download printable HTML Dossier for court or administrative record inclusion
|
|
103
|
+
html_dossier = client.download_dossier_html("LG-2026-B81C-9E4F-2A7D")
|
|
104
|
+
with open("dossier_rup.html", "w", encoding="utf-8") as f:
|
|
105
|
+
f.write(html_dossier)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 🏛️ All 20 Specialized Suites & Shorthand Properties
|
|
111
|
+
|
|
112
|
+
Access any of the 20 vertical domains directly via property names, ergonomic shorthand aliases, or dynamic runner:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
# Shorthand aliases or canonical properties:
|
|
116
|
+
client.tax # or client.eu_tax (EU Tax, KYB, VIES & e-Invoicing)
|
|
117
|
+
client.fin # or client.fin_esg (Financial Forensics & CSRD VSME)
|
|
118
|
+
client.sec # or client.net_sec (NetSec, Deliverability & RDAP)
|
|
119
|
+
client.gdpr # or client.web_gdpr (Web GDPR, Cookie CMP & AI Act)
|
|
120
|
+
client.appalti # or client.gov_appalti (ANAC Public Procurement D.Lgs 36/2023)
|
|
121
|
+
client.dora # or client.dora_nis2 (DORA Banking/ICT & NIS2)
|
|
122
|
+
client.dogane # or client.customs_cbam (Customs CBAM, TARIC & Dual-Use)
|
|
123
|
+
client.lavoro # or client.hr_labour (HR Labour Law & IRPEF Simulator)
|
|
124
|
+
client.materials # or client.materials_dpp (Materials DPP & CPR)
|
|
125
|
+
client.energy # or client.energy_epbd (Energy Decarbonization & Case Green EPBD)
|
|
126
|
+
client.pii # or client.sovereign_pii (Sovereign PII Scrubber & AI Act)
|
|
127
|
+
client.xbrl # or client.xbrl_fin (XBRL ESEF & EU Taxonomy)
|
|
128
|
+
client.peppol # or client.einvoice_vida (Universal Peppol BIS 3.0 & ViDA)
|
|
129
|
+
client.grants # or client.grants_funding (EU Grants & Transizione 5.0)
|
|
130
|
+
client.carbon # or client.carbon_factors (Scope 1-2-3 GHG & CSRD)
|
|
131
|
+
client.ted # or client.ted_procurement (TED eForms & CPV Classifier)
|
|
132
|
+
client.reach # or client.chemicals_reach (REACH SVHC & RoHS 3)
|
|
133
|
+
client.aml # or client.aml_compliance (EU AMLA & 6AMLD)
|
|
134
|
+
client.eudr # or client.agri_food_eudr (EUDR Deforestation & FIC Allergens)
|
|
135
|
+
client.mdr # or client.pharma_medical_mdr (EU MDR, IVDR & FMD Serialization)
|
|
136
|
+
|
|
137
|
+
# Or dynamic execution for any tool across all 90 endpoints:
|
|
138
|
+
res = client.suite("dora").call("incident_severity_triage", {
|
|
139
|
+
"incidentType": "system_downtime",
|
|
140
|
+
"affectedUsers": 50000,
|
|
141
|
+
"durationHours": 4.5,
|
|
142
|
+
})
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## 🤖 AI Agent Framework Integrations (LangChain & CrewAI)
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from langchain.tools import tool
|
|
151
|
+
from lexgrid import LexGridClient
|
|
152
|
+
|
|
153
|
+
client = LexGridClient(api_key="your-api-key")
|
|
154
|
+
|
|
155
|
+
@tool
|
|
156
|
+
def verify_eu_vat(vat_number: str) -> str:
|
|
157
|
+
"""Verifies European VAT on official VIES registry with sanctions screening."""
|
|
158
|
+
res = client.eu_tax.verify_vies(vat_number)
|
|
159
|
+
return (
|
|
160
|
+
f"Valid: {res.data['is_valid']}. "
|
|
161
|
+
f"Certificate: {res.certificate_id} ({res.verification_url})"
|
|
162
|
+
)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## 🛡️ License & Compliance
|
|
168
|
+
|
|
169
|
+
- **License:** MIT License
|
|
170
|
+
- **Zero-Data-Retention:** Strictly stateless in-memory execution in volatile RAM ($< 50\text{ ms}$). No customer payloads saved to disk.
|
|
171
|
+
- **DPO Policy:** [https://lexgrid.novapixel.it/compliance-policy](https://lexgrid.novapixel.it/compliance-policy)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
lexgrid/__init__.py,sha256=jQgL7S3a9FrW1Kn6dHFmCY9bAHyhG9_BBGPDZp6I54Q,810
|
|
2
|
+
lexgrid/client.py,sha256=UU-D_dRLUMiDcQj6ZI76VZbcrTNGmh3NOMf8xzDkZco,48583
|
|
3
|
+
lexgrid/exceptions.py,sha256=AkZRUwoKAqjMfzK6n69LArOm7nl_qO0FEmYm2WA6MpA,1734
|
|
4
|
+
lexgrid/models.py,sha256=J1gS5fD7cOdrkO3pJF2NO3xC2_89YLby_gZKaZm-pYs,4028
|
|
5
|
+
lexgrid-1.0.0.dist-info/METADATA,sha256=17JsPl6jLtR4lX7gCa4OM-GHuO9d6y9IEblR0biXerI,6941
|
|
6
|
+
lexgrid-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
lexgrid-1.0.0.dist-info/top_level.txt,sha256=vMmATlTf8KPoqbS7vOjSRqZJwr8aHVdTsFykop6XZ3Y,8
|
|
8
|
+
lexgrid-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lexgrid
|