planframe 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ # Python bytecode / caches
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Virtual environments
7
+ .venv/
8
+ venv/
9
+ ENV/
10
+ env/
11
+ .env/
12
+
13
+ # Packaging / build artifacts
14
+ build/
15
+ dist/
16
+ *.egg-info/
17
+ *.egg
18
+ pip-wheel-metadata/
19
+
20
+ # Test / coverage artifacts
21
+ .pytest_cache/
22
+ .coverage
23
+ .coverage.*
24
+ coverage.xml
25
+ htmlcov/
26
+
27
+ # Type check / lint caches
28
+ .mypy_cache/
29
+ .pyright/
30
+ .ruff_cache/
31
+
32
+ # Notebook checkpoints
33
+ .ipynb_checkpoints/
34
+
35
+ # IDE/editor settings
36
+ .vscode/
37
+ .idea/
38
+
39
+ # OS files
40
+ .DS_Store
41
+ Thumbs.db
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PlanFrame Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: planframe
3
+ Version: 0.1.0
4
+ Summary: Core typed relational planning layer for Python DataFrames.
5
+ Project-URL: Repository, https://github.com/eddiethedean/planframe
6
+ Project-URL: Documentation, https://github.com/eddiethedean/planframe/blob/main/README.md
7
+ Project-URL: Issues, https://github.com/eddiethedean/planframe/issues
8
+ Author: PlanFrame Contributors
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Typing :: Typed
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: pydantic>=1.10
18
+ Requires-Dist: typing-extensions>=4.8
19
+ Description-Content-Type: text/markdown
20
+
21
+ ## planframe
22
+
23
+ Core package for PlanFrame (typed planning layer). Import as `planframe`.
24
+
25
+ ### What you get
26
+ - `planframe.Frame`: immutable, schema-aware transformation plan (**always lazy**)
27
+ - `planframe.expr`: typed expression IR (`col`, `lit`, arithmetic/compare/boolean ops, `coalesce`, `if_else`, etc.)
28
+ - `planframe.schema`: schema reflection (dataclass + Pydantic) and materialization
29
+
30
+ ### Note on backends
31
+ `planframe` is backend-agnostic. It does not execute anything until `collect()` (even for eager backends). To execute plans you need an adapter package (e.g. `planframe-polars`).
32
+
33
+ ### Typing
34
+ PlanFrame includes `py.typed` plus generated stubs (notably `planframe/frame.pyi`) to improve static typing in editors and Pyright.
35
+
36
+ If you modify the `Frame` API, regenerate stubs from the repo root:
37
+
38
+ ```bash
39
+ python scripts/generate_typing_stubs.py
40
+ python scripts/generate_typing_stubs.py --check
41
+ ```
42
+
@@ -0,0 +1,22 @@
1
+ ## planframe
2
+
3
+ Core package for PlanFrame (typed planning layer). Import as `planframe`.
4
+
5
+ ### What you get
6
+ - `planframe.Frame`: immutable, schema-aware transformation plan (**always lazy**)
7
+ - `planframe.expr`: typed expression IR (`col`, `lit`, arithmetic/compare/boolean ops, `coalesce`, `if_else`, etc.)
8
+ - `planframe.schema`: schema reflection (dataclass + Pydantic) and materialization
9
+
10
+ ### Note on backends
11
+ `planframe` is backend-agnostic. It does not execute anything until `collect()` (even for eager backends). To execute plans you need an adapter package (e.g. `planframe-polars`).
12
+
13
+ ### Typing
14
+ PlanFrame includes `py.typed` plus generated stubs (notably `planframe/frame.pyi`) to improve static typing in editors and Pyright.
15
+
16
+ If you modify the `Frame` API, regenerate stubs from the repo root:
17
+
18
+ ```bash
19
+ python scripts/generate_typing_stubs.py
20
+ python scripts/generate_typing_stubs.py --check
21
+ ```
22
+
@@ -0,0 +1,4 @@
1
+ from planframe.frame import Frame
2
+ from planframe.schema.ir import Schema
3
+
4
+ __all__ = ["Frame", "Schema"]
@@ -0,0 +1,18 @@
1
+ from planframe.backend.adapter import BackendAdapter, BaseAdapter
2
+ from planframe.backend.errors import (
3
+ PlanFrameBackendError,
4
+ PlanFrameError,
5
+ PlanFrameExecutionError,
6
+ PlanFrameExpressionError,
7
+ PlanFrameSchemaError,
8
+ )
9
+
10
+ __all__ = [
11
+ "BackendAdapter",
12
+ "BaseAdapter",
13
+ "PlanFrameError",
14
+ "PlanFrameBackendError",
15
+ "PlanFrameExecutionError",
16
+ "PlanFrameExpressionError",
17
+ "PlanFrameSchemaError",
18
+ ]
@@ -0,0 +1,256 @@
1
+ from __future__ import annotations
2
+
3
+ from abc import ABC, abstractmethod
4
+ from typing import Any, Generic, TypeVar
5
+
6
+ BackendFrameT = TypeVar("BackendFrameT")
7
+ BackendExprT = TypeVar("BackendExprT")
8
+
9
+
10
+ class BaseAdapter(ABC, Generic[BackendFrameT, BackendExprT]):
11
+ """Backend execution base class.
12
+
13
+ Core PlanFrame code must not import backend libraries. Adapters translate PlanFrame
14
+ operations + expression IR into backend-native operations.
15
+ """
16
+
17
+ name: str
18
+
19
+ @abstractmethod
20
+ def select(self, df: BackendFrameT, columns: tuple[str, ...]) -> BackendFrameT: ...
21
+
22
+ @abstractmethod
23
+ def drop(self, df: BackendFrameT, columns: tuple[str, ...]) -> BackendFrameT: ...
24
+
25
+ @abstractmethod
26
+ def rename(self, df: BackendFrameT, mapping: dict[str, str]) -> BackendFrameT: ...
27
+
28
+ @abstractmethod
29
+ def with_column(self, df: BackendFrameT, name: str, expr: BackendExprT) -> BackendFrameT: ...
30
+
31
+ @abstractmethod
32
+ def cast(self, df: BackendFrameT, name: str, dtype: Any) -> BackendFrameT: ...
33
+
34
+ @abstractmethod
35
+ def filter(self, df: BackendFrameT, predicate: BackendExprT) -> BackendFrameT: ...
36
+
37
+ @abstractmethod
38
+ def sort(
39
+ self,
40
+ df: BackendFrameT,
41
+ columns: tuple[str, ...],
42
+ *,
43
+ descending: bool = False,
44
+ nulls_last: bool = False,
45
+ ) -> BackendFrameT: ...
46
+
47
+ @abstractmethod
48
+ def unique(
49
+ self,
50
+ df: BackendFrameT,
51
+ subset: tuple[str, ...] | None,
52
+ *,
53
+ keep: str = "first",
54
+ maintain_order: bool = False,
55
+ ) -> BackendFrameT: ...
56
+
57
+ @abstractmethod
58
+ def duplicated(
59
+ self,
60
+ df: BackendFrameT,
61
+ subset: tuple[str, ...] | None,
62
+ *,
63
+ keep: str | bool = "first",
64
+ out_name: str = "duplicated",
65
+ ) -> BackendFrameT: ...
66
+
67
+ @abstractmethod
68
+ def group_by_agg(
69
+ self,
70
+ df: BackendFrameT,
71
+ *,
72
+ keys: tuple[str, ...],
73
+ named_aggs: dict[str, tuple[str, str]],
74
+ ) -> BackendFrameT: ...
75
+
76
+ @abstractmethod
77
+ def drop_nulls(
78
+ self,
79
+ df: BackendFrameT,
80
+ subset: tuple[str, ...] | None,
81
+ ) -> BackendFrameT: ...
82
+
83
+ @abstractmethod
84
+ def fill_null(
85
+ self,
86
+ df: BackendFrameT,
87
+ value: Any,
88
+ subset: tuple[str, ...] | None,
89
+ ) -> BackendFrameT: ...
90
+
91
+ @abstractmethod
92
+ def melt(
93
+ self,
94
+ df: BackendFrameT,
95
+ *,
96
+ id_vars: tuple[str, ...],
97
+ value_vars: tuple[str, ...],
98
+ variable_name: str,
99
+ value_name: str,
100
+ ) -> BackendFrameT: ...
101
+
102
+ @abstractmethod
103
+ def join(
104
+ self,
105
+ left: BackendFrameT,
106
+ right: BackendFrameT,
107
+ *,
108
+ on: tuple[str, ...],
109
+ how: str = "inner",
110
+ suffix: str = "_right",
111
+ ) -> BackendFrameT: ...
112
+
113
+ @abstractmethod
114
+ def slice(
115
+ self,
116
+ df: BackendFrameT,
117
+ *,
118
+ offset: int,
119
+ length: int | None,
120
+ ) -> BackendFrameT: ...
121
+
122
+ @abstractmethod
123
+ def head(self, df: BackendFrameT, n: int) -> BackendFrameT: ...
124
+
125
+ @abstractmethod
126
+ def tail(self, df: BackendFrameT, n: int) -> BackendFrameT: ...
127
+
128
+ @abstractmethod
129
+ def concat_vertical(self, left: BackendFrameT, right: BackendFrameT) -> BackendFrameT: ...
130
+
131
+ @abstractmethod
132
+ def concat_horizontal(self, left: BackendFrameT, right: BackendFrameT) -> BackendFrameT: ...
133
+
134
+ @abstractmethod
135
+ def pivot(
136
+ self,
137
+ df: BackendFrameT,
138
+ *,
139
+ index: tuple[str, ...],
140
+ on: str,
141
+ values: str,
142
+ agg: str = "first",
143
+ on_columns: tuple[str, ...] | None = None,
144
+ separator: str = "_",
145
+ ) -> BackendFrameT: ...
146
+
147
+ @abstractmethod
148
+ def write_parquet(
149
+ self,
150
+ df: BackendFrameT,
151
+ path: str,
152
+ *,
153
+ compression: str = "zstd",
154
+ row_group_size: int | None = None,
155
+ partition_by: tuple[str, ...] | None = None,
156
+ storage_options: dict[str, Any] | None = None,
157
+ ) -> None: ...
158
+
159
+ @abstractmethod
160
+ def write_csv(
161
+ self,
162
+ df: BackendFrameT,
163
+ path: str,
164
+ *,
165
+ separator: str = ",",
166
+ include_header: bool = True,
167
+ storage_options: dict[str, Any] | None = None,
168
+ ) -> None: ...
169
+
170
+ @abstractmethod
171
+ def write_ndjson(
172
+ self, df: BackendFrameT, path: str, *, storage_options: dict[str, Any] | None = None
173
+ ) -> None: ...
174
+
175
+ @abstractmethod
176
+ def write_ipc(
177
+ self,
178
+ df: BackendFrameT,
179
+ path: str,
180
+ *,
181
+ compression: str = "uncompressed",
182
+ storage_options: dict[str, Any] | None = None,
183
+ ) -> None: ...
184
+
185
+ @abstractmethod
186
+ def write_database(
187
+ self,
188
+ df: BackendFrameT,
189
+ *,
190
+ table_name: str,
191
+ connection: Any,
192
+ if_table_exists: str = "fail",
193
+ engine: str | None = None,
194
+ ) -> None: ...
195
+
196
+ @abstractmethod
197
+ def write_excel(self, df: BackendFrameT, path: str, *, worksheet: str = "Sheet1") -> None: ...
198
+
199
+ @abstractmethod
200
+ def write_delta(
201
+ self,
202
+ df: BackendFrameT,
203
+ target: str,
204
+ *,
205
+ mode: str = "error",
206
+ storage_options: dict[str, Any] | None = None,
207
+ ) -> None: ...
208
+
209
+ @abstractmethod
210
+ def write_avro(
211
+ self,
212
+ df: BackendFrameT,
213
+ path: str,
214
+ *,
215
+ compression: str = "uncompressed",
216
+ name: str = "",
217
+ ) -> None: ...
218
+
219
+ @abstractmethod
220
+ def explode(self, df: BackendFrameT, column: str) -> BackendFrameT: ...
221
+
222
+ @abstractmethod
223
+ def unnest(self, df: BackendFrameT, column: str) -> BackendFrameT: ...
224
+
225
+ @abstractmethod
226
+ def drop_nulls_all(
227
+ self, df: BackendFrameT, subset: tuple[str, ...] | None
228
+ ) -> BackendFrameT: ...
229
+
230
+ @abstractmethod
231
+ def sample(
232
+ self,
233
+ df: BackendFrameT,
234
+ *,
235
+ n: int | None = None,
236
+ frac: float | None = None,
237
+ with_replacement: bool = False,
238
+ shuffle: bool = False,
239
+ seed: int | None = None,
240
+ ) -> BackendFrameT: ...
241
+
242
+ @abstractmethod
243
+ def compile_expr(self, expr: Any) -> BackendExprT: ...
244
+
245
+ @abstractmethod
246
+ def collect(self, df: BackendFrameT) -> BackendFrameT: ...
247
+
248
+ @abstractmethod
249
+ def to_dicts(self, df: BackendFrameT) -> list[dict[str, object]]: ...
250
+
251
+ @abstractmethod
252
+ def to_dict(self, df: BackendFrameT) -> dict[str, list[object]]: ...
253
+
254
+
255
+ # Backwards-compatible name for older imports.
256
+ BackendAdapter = BaseAdapter
@@ -0,0 +1,18 @@
1
+ class PlanFrameError(Exception):
2
+ """Base exception for PlanFrame."""
3
+
4
+
5
+ class PlanFrameSchemaError(PlanFrameError):
6
+ """Raised when schema inference/evolution fails."""
7
+
8
+
9
+ class PlanFrameExpressionError(PlanFrameError):
10
+ """Raised when expression typing/compilation fails."""
11
+
12
+
13
+ class PlanFrameBackendError(PlanFrameError):
14
+ """Raised when a backend adapter fails or is misused."""
15
+
16
+
17
+ class PlanFrameExecutionError(PlanFrameBackendError):
18
+ """Raised when backend execution/collection fails."""
@@ -0,0 +1,99 @@
1
+ from planframe.expr.api import (
2
+ Expr,
3
+ add,
4
+ abs_,
5
+ and_,
6
+ between,
7
+ ceil,
8
+ col,
9
+ contains,
10
+ coalesce,
11
+ day,
12
+ eq,
13
+ ends_with,
14
+ floor,
15
+ ge,
16
+ gt,
17
+ if_else,
18
+ infer_dtype,
19
+ is_not_null,
20
+ is_null,
21
+ isin,
22
+ length,
23
+ le,
24
+ lit,
25
+ lt,
26
+ log,
27
+ mul,
28
+ month,
29
+ ne,
30
+ not_,
31
+ or_,
32
+ over,
33
+ pow_,
34
+ replace,
35
+ strip,
36
+ split,
37
+ round_,
38
+ starts_with,
39
+ sub,
40
+ truediv,
41
+ upper,
42
+ lower,
43
+ year,
44
+ exp,
45
+ clip,
46
+ xor,
47
+ sqrt,
48
+ is_finite,
49
+ )
50
+
51
+ __all__ = [
52
+ "Expr",
53
+ "add",
54
+ "abs_",
55
+ "and_",
56
+ "between",
57
+ "ceil",
58
+ "col",
59
+ "contains",
60
+ "coalesce",
61
+ "day",
62
+ "eq",
63
+ "ends_with",
64
+ "floor",
65
+ "ge",
66
+ "gt",
67
+ "if_else",
68
+ "infer_dtype",
69
+ "is_not_null",
70
+ "is_null",
71
+ "isin",
72
+ "length",
73
+ "le",
74
+ "lit",
75
+ "lt",
76
+ "log",
77
+ "mul",
78
+ "month",
79
+ "ne",
80
+ "not_",
81
+ "or_",
82
+ "over",
83
+ "pow_",
84
+ "replace",
85
+ "strip",
86
+ "split",
87
+ "round_",
88
+ "starts_with",
89
+ "sub",
90
+ "truediv",
91
+ "upper",
92
+ "lower",
93
+ "year",
94
+ "exp",
95
+ "clip",
96
+ "xor",
97
+ "sqrt",
98
+ "is_finite",
99
+ ]