datasentry-core 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. datasentry_core-0.1.0/.gitignore +32 -0
  2. datasentry_core-0.1.0/PKG-INFO +59 -0
  3. datasentry_core-0.1.0/README.md +39 -0
  4. datasentry_core-0.1.0/pyproject.toml +30 -0
  5. datasentry_core-0.1.0/src/datasentry_core/__init__.py +111 -0
  6. datasentry_core-0.1.0/src/datasentry_core/connectors/__init__.py +49 -0
  7. datasentry_core-0.1.0/src/datasentry_core/connectors/base.py +108 -0
  8. datasentry_core-0.1.0/src/datasentry_core/connectors/csv.py +312 -0
  9. datasentry_core-0.1.0/src/datasentry_core/connectors/duckdb.py +105 -0
  10. datasentry_core-0.1.0/src/datasentry_core/connectors/errors.py +19 -0
  11. datasentry_core-0.1.0/src/datasentry_core/connectors/file_based.py +209 -0
  12. datasentry_core-0.1.0/src/datasentry_core/connectors/jsonl.py +71 -0
  13. datasentry_core-0.1.0/src/datasentry_core/connectors/parquet.py +64 -0
  14. datasentry_core-0.1.0/src/datasentry_core/connectors/registry.py +55 -0
  15. datasentry_core-0.1.0/src/datasentry_core/connectors/spec.py +37 -0
  16. datasentry_core-0.1.0/src/datasentry_core/connectors/xlsx.py +109 -0
  17. datasentry_core-0.1.0/src/datasentry_core/contracts/__init__.py +24 -0
  18. datasentry_core-0.1.0/src/datasentry_core/contracts/exporters.py +330 -0
  19. datasentry_core-0.1.0/src/datasentry_core/detectors/__init__.py +15 -0
  20. datasentry_core-0.1.0/src/datasentry_core/detectors/base.py +120 -0
  21. datasentry_core-0.1.0/src/datasentry_core/detectors/common.py +156 -0
  22. datasentry_core-0.1.0/src/datasentry_core/detectors/cross_field.py +157 -0
  23. datasentry_core-0.1.0/src/datasentry_core/detectors/cross_table.py +220 -0
  24. datasentry_core-0.1.0/src/datasentry_core/detectors/datetime.py +343 -0
  25. datasentry_core-0.1.0/src/datasentry_core/detectors/initial/__init__.py +117 -0
  26. datasentry_core-0.1.0/src/datasentry_core/detectors/initial/anomaly_ml.py +204 -0
  27. datasentry_core-0.1.0/src/datasentry_core/detectors/initial/categorical.py +252 -0
  28. datasentry_core-0.1.0/src/datasentry_core/detectors/initial/formula.py +66 -0
  29. datasentry_core-0.1.0/src/datasentry_core/detectors/initial/missing.py +150 -0
  30. datasentry_core-0.1.0/src/datasentry_core/detectors/initial/numeric.py +302 -0
  31. datasentry_core-0.1.0/src/datasentry_core/detectors/initial/textual.py +407 -0
  32. datasentry_core-0.1.0/src/datasentry_core/detectors/initial/uniqueness.py +183 -0
  33. datasentry_core-0.1.0/src/datasentry_core/detectors/missingness.py +424 -0
  34. datasentry_core-0.1.0/src/datasentry_core/detectors/runner.py +228 -0
  35. datasentry_core-0.1.0/src/datasentry_core/detectors/safe_eval.py +255 -0
  36. datasentry_core-0.1.0/src/datasentry_core/detectors/textual_variants.py +300 -0
  37. datasentry_core-0.1.0/src/datasentry_core/drift/__init__.py +8 -0
  38. datasentry_core-0.1.0/src/datasentry_core/drift/engine.py +182 -0
  39. datasentry_core-0.1.0/src/datasentry_core/engine/__init__.py +16 -0
  40. datasentry_core-0.1.0/src/datasentry_core/engine/base.py +34 -0
  41. datasentry_core-0.1.0/src/datasentry_core/engine/duckdb.py +79 -0
  42. datasentry_core-0.1.0/src/datasentry_core/engine/fusion.py +193 -0
  43. datasentry_core-0.1.0/src/datasentry_core/engine/profiler.py +165 -0
  44. datasentry_core-0.1.0/src/datasentry_core/engine/sql_guard.py +23 -0
  45. datasentry_core-0.1.0/src/datasentry_core/llm/provider.py +66 -0
  46. datasentry_core-0.1.0/src/datasentry_core/models/__init__.py +118 -0
  47. datasentry_core-0.1.0/src/datasentry_core/models/audit.py +46 -0
  48. datasentry_core-0.1.0/src/datasentry_core/models/contract.py +89 -0
  49. datasentry_core-0.1.0/src/datasentry_core/models/detector.py +66 -0
  50. datasentry_core-0.1.0/src/datasentry_core/models/drift.py +47 -0
  51. datasentry_core-0.1.0/src/datasentry_core/models/enums.py +126 -0
  52. datasentry_core-0.1.0/src/datasentry_core/models/evidence.py +39 -0
  53. datasentry_core-0.1.0/src/datasentry_core/models/feedback.py +30 -0
  54. datasentry_core-0.1.0/src/datasentry_core/models/fingerprint.py +24 -0
  55. datasentry_core-0.1.0/src/datasentry_core/models/issue.py +49 -0
  56. datasentry_core-0.1.0/src/datasentry_core/models/llm.py +69 -0
  57. datasentry_core-0.1.0/src/datasentry_core/models/profile.py +79 -0
  58. datasentry_core-0.1.0/src/datasentry_core/models/quality.py +16 -0
  59. datasentry_core-0.1.0/src/datasentry_core/models/repair.py +94 -0
  60. datasentry_core-0.1.0/src/datasentry_core/models/rules.py +82 -0
  61. datasentry_core-0.1.0/src/datasentry_core/models/scan.py +112 -0
  62. datasentry_core-0.1.0/src/datasentry_core/models/validation.py +22 -0
  63. datasentry_core-0.1.0/src/datasentry_core/plugins.py +91 -0
  64. datasentry_core-0.1.0/src/datasentry_core/privacy/redactor.py +155 -0
  65. datasentry_core-0.1.0/src/datasentry_core/repair/__init__.py +5 -0
  66. datasentry_core-0.1.0/src/datasentry_core/repair/engine.py +455 -0
  67. datasentry_core-0.1.0/src/datasentry_core/reporting/__init__.py +100 -0
  68. datasentry_core-0.1.0/src/datasentry_core/reporting/html.py +230 -0
  69. datasentry_core-0.1.0/src/datasentry_core/reporting/junit.py +80 -0
  70. datasentry_core-0.1.0/src/datasentry_core/reporting/markdown.py +83 -0
  71. datasentry_core-0.1.0/src/datasentry_core/reporting/sarif.py +92 -0
  72. datasentry_core-0.1.0/src/datasentry_core/rules/engine.py +133 -0
  73. datasentry_core-0.1.0/src/datasentry_core/scoring/__init__.py +30 -0
  74. datasentry_core-0.1.0/src/datasentry_core/scoring/engine.py +138 -0
  75. datasentry_core-0.1.0/src/datasentry_core/scoring/gate.py +96 -0
  76. datasentry_core-0.1.0/src/datasentry_core/scoring/quality.py +137 -0
  77. datasentry_core-0.1.0/src/datasentry_core/scoring/weights.py +33 -0
  78. datasentry_core-0.1.0/src/datasentry_core/storage/__init__.py +15 -0
  79. datasentry_core-0.1.0/src/datasentry_core/storage/paths.py +47 -0
  80. datasentry_core-0.1.0/src/datasentry_core/storage/schema.py +343 -0
  81. datasentry_core-0.1.0/src/datasentry_core/storage/store.py +675 -0
@@ -0,0 +1,32 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .venv/
6
+ dist/
7
+ build/
8
+ .coverage
9
+ htmlcov/
10
+ .pytest_cache/
11
+ .ruff_cache/
12
+ .mypy_cache/
13
+ hypothesis/
14
+ .hypothesis/
15
+
16
+ # Project data
17
+ .datasentry/
18
+ *.db
19
+ *.sqlite3
20
+
21
+ # Env / secrets
22
+ .env
23
+ credentials.json
24
+
25
+ # OS
26
+ .DS_Store
27
+
28
+ # Editors
29
+ .idea/
30
+ .vscode/
31
+ ~$*
32
+ workspace/
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: datasentry-core
3
+ Version: 0.1.0
4
+ Summary: DataSentry AI core domain models and engine (detectors, fusion, scoring, repairs).
5
+ License: Apache-2.0
6
+ Keywords: data-observability,data-quality,duckdb
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: License :: OSI Approved :: Apache Software License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Requires-Python: >=3.12
13
+ Requires-Dist: charset-normalizer>=3.3
14
+ Requires-Dist: duckdb>=1.0
15
+ Requires-Dist: openpyxl>=3.1
16
+ Requires-Dist: pyarrow>=16.0
17
+ Requires-Dist: pydantic>=2.7
18
+ Requires-Dist: scikit-learn>=1.5
19
+ Description-Content-Type: text/markdown
20
+
21
+ # datasentry-core
22
+
23
+ DataSentry AI 核心领域模型与引擎:连接器、检测器、融合、评分、
24
+ 修复、规则引擎与隐私脱敏。纯离线、零网络依赖,可独立测试。
25
+
26
+ ```
27
+ pip install datasentry-core
28
+ ```
29
+
30
+ ## 模块
31
+
32
+ - `connectors/` — 多格式数据源(CSV / Parquet / JSONL / XLSX)
33
+ - `detectors/` — 检测器注册表与 36+ 内置检测器(`Detector` 协议)
34
+ - `engine/` — 画像、融合、评分
35
+ - `repair/` — 修复引擎(propose → preview → apply → rollback)
36
+ - `rules/` — 规则模型与预运行引擎(期望语义取反)
37
+ - `privacy/` — 确定性 PII 脱敏(mask_profile / mask_rows)
38
+ - `llm/` — LLM Provider 协议与数据结构(零网络)
39
+ - `plugins.py` — 检测器插件加载(插件 API v1,ADR-031)
40
+
41
+ ## 使用
42
+
43
+ ```python
44
+ from datasentry_core.connectors import DataSourceSpec, default_registry
45
+ from datasentry_core.detectors.initial import register_default_detectors
46
+ from datasentry_core.detectors import DetectorRegistry
47
+ from datasentry_core.detectors.runner import ScanRunner
48
+
49
+ registry = DetectorRegistry()
50
+ register_default_detectors(registry)
51
+ runner = ScanRunner(registry)
52
+
53
+ handle = default_registry().open(DataSourceSpec(source_type="csv", path="data.csv"))
54
+ runs = runner.run_all(handle, config)
55
+ ```
56
+
57
+ ## 许可
58
+
59
+ Apache-2.0。完整产品(CLI / API / UI)见 `datasentry` 包。
@@ -0,0 +1,39 @@
1
+ # datasentry-core
2
+
3
+ DataSentry AI 核心领域模型与引擎:连接器、检测器、融合、评分、
4
+ 修复、规则引擎与隐私脱敏。纯离线、零网络依赖,可独立测试。
5
+
6
+ ```
7
+ pip install datasentry-core
8
+ ```
9
+
10
+ ## 模块
11
+
12
+ - `connectors/` — 多格式数据源(CSV / Parquet / JSONL / XLSX)
13
+ - `detectors/` — 检测器注册表与 36+ 内置检测器(`Detector` 协议)
14
+ - `engine/` — 画像、融合、评分
15
+ - `repair/` — 修复引擎(propose → preview → apply → rollback)
16
+ - `rules/` — 规则模型与预运行引擎(期望语义取反)
17
+ - `privacy/` — 确定性 PII 脱敏(mask_profile / mask_rows)
18
+ - `llm/` — LLM Provider 协议与数据结构(零网络)
19
+ - `plugins.py` — 检测器插件加载(插件 API v1,ADR-031)
20
+
21
+ ## 使用
22
+
23
+ ```python
24
+ from datasentry_core.connectors import DataSourceSpec, default_registry
25
+ from datasentry_core.detectors.initial import register_default_detectors
26
+ from datasentry_core.detectors import DetectorRegistry
27
+ from datasentry_core.detectors.runner import ScanRunner
28
+
29
+ registry = DetectorRegistry()
30
+ register_default_detectors(registry)
31
+ runner = ScanRunner(registry)
32
+
33
+ handle = default_registry().open(DataSourceSpec(source_type="csv", path="data.csv"))
34
+ runs = runner.run_all(handle, config)
35
+ ```
36
+
37
+ ## 许可
38
+
39
+ Apache-2.0。完整产品(CLI / API / UI)见 `datasentry` 包。
@@ -0,0 +1,30 @@
1
+ [project]
2
+ name = "datasentry-core"
3
+ version = "0.1.0"
4
+ description = "DataSentry AI core domain models and engine (detectors, fusion, scoring, repairs)."
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ license = { text = "Apache-2.0" }
8
+ keywords = ["data-quality", "data-observability", "duckdb"]
9
+ classifiers = [
10
+ "Development Status :: 3 - Alpha",
11
+ "License :: OSI Approved :: Apache Software License",
12
+ "Operating System :: OS Independent",
13
+ "Programming Language :: Python :: 3.12",
14
+ "Programming Language :: Python :: 3.13",
15
+ ]
16
+ dependencies = [
17
+ "pydantic>=2.7",
18
+ "duckdb>=1.0",
19
+ "pyarrow>=16.0",
20
+ "charset-normalizer>=3.3",
21
+ "openpyxl>=3.1",
22
+ "scikit-learn>=1.5",
23
+ ]
24
+
25
+ [build-system]
26
+ requires = ["hatchling"]
27
+ build-backend = "hatchling.build"
28
+
29
+ [tool.hatch.build.targets.wheel]
30
+ packages = ["src/datasentry_core"]
@@ -0,0 +1,111 @@
1
+ """DataSentry AI core package."""
2
+
3
+ from datasentry_core.models import (
4
+ AIExplanation,
5
+ AuditEvent,
6
+ BusinessCriticality,
7
+ CauseHypothesis,
8
+ ColumnCheck,
9
+ ColumnContract,
10
+ ColumnDrift,
11
+ ColumnProfile,
12
+ Condition,
13
+ Contract,
14
+ DatasetContract,
15
+ DatasetFingerprint,
16
+ DatasetProfile,
17
+ DetectorRun,
18
+ DriftReport,
19
+ Evidence,
20
+ EvidenceProvenance,
21
+ EvidenceType,
22
+ FeedbackEntry,
23
+ Issue,
24
+ IssueStatus,
25
+ LLMInvocation,
26
+ LLMUsageSummary,
27
+ MaskConfig,
28
+ QualityDimension,
29
+ QualityGate,
30
+ QualityScore,
31
+ RecommendedAction,
32
+ RepairOperation,
33
+ RepairOperationRecord,
34
+ RepairPreview,
35
+ RepairProposal,
36
+ RepairProposalStatus,
37
+ RepairRun,
38
+ RepairRunStatus,
39
+ ReproducibilityInfo,
40
+ RiskLevel,
41
+ RowBeforeAfter,
42
+ Rule,
43
+ RuleCandidate,
44
+ RulePreflightReport,
45
+ RuleType,
46
+ SamplingConfig,
47
+ SamplingInfo,
48
+ ScanConfig,
49
+ ScanRun,
50
+ SchemaChange,
51
+ SemanticEvidence,
52
+ SemanticProfile,
53
+ Severity,
54
+ ValidationResult,
55
+ )
56
+
57
+ __all__ = [
58
+ "AIExplanation",
59
+ "AuditEvent",
60
+ "BusinessCriticality",
61
+ "CauseHypothesis",
62
+ "ColumnCheck",
63
+ "ColumnContract",
64
+ "ColumnDrift",
65
+ "ColumnProfile",
66
+ "Condition",
67
+ "Contract",
68
+ "DatasetContract",
69
+ "DatasetFingerprint",
70
+ "DatasetProfile",
71
+ "DetectorRun",
72
+ "DriftReport",
73
+ "Evidence",
74
+ "EvidenceProvenance",
75
+ "EvidenceType",
76
+ "FeedbackEntry",
77
+ "Issue",
78
+ "IssueStatus",
79
+ "LLMInvocation",
80
+ "LLMUsageSummary",
81
+ "MaskConfig",
82
+ "QualityDimension",
83
+ "QualityGate",
84
+ "QualityScore",
85
+ "RecommendedAction",
86
+ "RepairOperation",
87
+ "RepairOperationRecord",
88
+ "RepairPreview",
89
+ "RepairProposal",
90
+ "RepairProposalStatus",
91
+ "RepairRun",
92
+ "RepairRunStatus",
93
+ "ReproducibilityInfo",
94
+ "RiskLevel",
95
+ "RowBeforeAfter",
96
+ "Rule",
97
+ "RuleCandidate",
98
+ "RulePreflightReport",
99
+ "RuleType",
100
+ "SamplingConfig",
101
+ "SamplingInfo",
102
+ "ScanConfig",
103
+ "ScanRun",
104
+ "SchemaChange",
105
+ "SemanticEvidence",
106
+ "SemanticProfile",
107
+ "Severity",
108
+ "ValidationResult",
109
+ ]
110
+
111
+ __version__ = "0.1.0"
@@ -0,0 +1,49 @@
1
+ """连接器包:数据源读取抽象(49.1/四十一 Step 2)。"""
2
+
3
+ from datasentry_core.connectors.base import (
4
+ ColumnInfo,
5
+ DataConnector,
6
+ DataHandle,
7
+ FingerprintMode,
8
+ FrameBatch,
9
+ LoadWarning,
10
+ SamplingMethod,
11
+ SchemaInfo,
12
+ )
13
+ from datasentry_core.connectors.csv import CsvConnector
14
+ from datasentry_core.connectors.duckdb import DuckdbConnector
15
+ from datasentry_core.connectors.errors import (
16
+ ConnectorError,
17
+ DataSourceNotFoundError,
18
+ UnsafeSqlError,
19
+ UnsupportedFormatError,
20
+ )
21
+ from datasentry_core.connectors.jsonl import JsonlConnector
22
+ from datasentry_core.connectors.parquet import ParquetConnector
23
+ from datasentry_core.connectors.registry import ConnectorRegistry, default_registry
24
+ from datasentry_core.connectors.spec import DataSourceSpec, DataSourceType
25
+ from datasentry_core.connectors.xlsx import XlsxConnector
26
+
27
+ __all__ = [
28
+ "ColumnInfo",
29
+ "ConnectorError",
30
+ "ConnectorRegistry",
31
+ "CsvConnector",
32
+ "DataConnector",
33
+ "DataHandle",
34
+ "DataSourceNotFoundError",
35
+ "DataSourceSpec",
36
+ "DataSourceType",
37
+ "DuckdbConnector",
38
+ "FingerprintMode",
39
+ "FrameBatch",
40
+ "JsonlConnector",
41
+ "LoadWarning",
42
+ "ParquetConnector",
43
+ "SamplingMethod",
44
+ "SchemaInfo",
45
+ "UnsafeSqlError",
46
+ "UnsupportedFormatError",
47
+ "XlsxConnector",
48
+ "default_registry",
49
+ ]
@@ -0,0 +1,108 @@
1
+ """连接器协议与共享类型(49.1)。
2
+
3
+ 统一返回 PyArrow 帧(FrameBatch),与 DuckDB 零拷贝互操作(ADR-005)。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from collections.abc import Iterator
9
+ from pathlib import Path
10
+ from typing import Any, Literal, Protocol
11
+
12
+ import pyarrow as pa
13
+ from pydantic import BaseModel, ConfigDict, Field
14
+
15
+ from datasentry_core.connectors.spec import DataSourceSpec, DataSourceType
16
+ from datasentry_core.models.enums import Severity
17
+ from datasentry_core.models.fingerprint import DatasetFingerprint
18
+
19
+ SamplingMethod = Literal[
20
+ "random", "stratified", "reservoir", "time_based", "rare_oversampling", "none"
21
+ ]
22
+ FingerprintMode = Literal["full", "sampled", "metadata_only"]
23
+
24
+
25
+ class FrameBatch(BaseModel):
26
+ """一批数据(49.1):PyArrow Table + 来源与位置元信息。"""
27
+
28
+ model_config = ConfigDict(arbitrary_types_allowed=True)
29
+
30
+ source: DataSourceSpec
31
+ table: pa.Table
32
+ batch_index: int = 0
33
+ row_offset: int = 0
34
+
35
+ @property
36
+ def row_count(self) -> int:
37
+ """本批行数。"""
38
+ rows = self.table.num_rows
39
+ assert isinstance(rows, int)
40
+ return rows
41
+
42
+ @property
43
+ def column_names(self) -> list[str]:
44
+ """本批列名。"""
45
+ return list(self.table.column_names)
46
+
47
+
48
+ class ColumnInfo(BaseModel):
49
+ """单列信息(49.1 describe 输出)。"""
50
+
51
+ name: str
52
+ physical_type: str
53
+ nullable: bool = True
54
+
55
+
56
+ class SchemaInfo(BaseModel):
57
+ """数据源 Schema 描述。"""
58
+
59
+ columns: list[ColumnInfo] = Field(default_factory=list)
60
+
61
+ @property
62
+ def column_names(self) -> list[str]:
63
+ """列名列表。"""
64
+ return [c.name for c in self.columns]
65
+
66
+
67
+ class LoadWarning(BaseModel):
68
+ """加载期警告(如 CSV 公式注入标记),value_preview 必须截断脱敏。"""
69
+
70
+ row: int = Field(ge=0)
71
+ column: str
72
+ message: str
73
+ severity: Severity = Severity.MEDIUM
74
+ value_preview: str = ""
75
+
76
+
77
+ class DataHandle(Protocol):
78
+ """打开后的数据句柄(49.1)。连接器不持有分析逻辑。"""
79
+
80
+ @property
81
+ def source_type(self) -> DataSourceType: ...
82
+ @property
83
+ def source_path(self) -> Path | None: ...
84
+
85
+ @property
86
+ def table_name(self) -> str | None:
87
+ """DuckDB 等需要表名的数据源返回表名,其他返回 None(Step 40)。"""
88
+ return None
89
+
90
+ def schema(self) -> SchemaInfo: ...
91
+ def read_batches(self, batch_size: int = 65536) -> Iterator[FrameBatch]: ...
92
+ def read_sample(self, n: int, method: SamplingMethod = "random") -> FrameBatch: ...
93
+ def sql_aggregate(self, sql: str, params: dict[str, Any] | None = None) -> FrameBatch: ...
94
+ def count_rows(self) -> int: ...
95
+ def fingerprint(self, mode: FingerprintMode = "full") -> DatasetFingerprint: ...
96
+ def warnings(self) -> list[LoadWarning]: ...
97
+ def close(self) -> None: ...
98
+
99
+
100
+ class DataConnector(Protocol):
101
+ """数据源连接器(49.1)。"""
102
+
103
+ connector_id: str
104
+ display_name: str
105
+
106
+ def supports(self, source: DataSourceSpec) -> bool: ...
107
+ def open(self, source: DataSourceSpec) -> DataHandle: ...
108
+ def close(self) -> None: ...