votinvv-datapulse 0.0.1__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.
- votinvv_datapulse-0.0.1/LICENSE +201 -0
- votinvv_datapulse-0.0.1/PKG-INFO +77 -0
- votinvv_datapulse-0.0.1/README.md +50 -0
- votinvv_datapulse-0.0.1/datapulse/__init__.py +39 -0
- votinvv_datapulse-0.0.1/datapulse/decorators.py +153 -0
- votinvv_datapulse-0.0.1/datapulse/dev.py +50 -0
- votinvv_datapulse-0.0.1/datapulse/flow.py +65 -0
- votinvv_datapulse-0.0.1/datapulse/params.py +68 -0
- votinvv_datapulse-0.0.1/datapulse/secrets.py +63 -0
- votinvv_datapulse-0.0.1/datapulse/sources.py +60 -0
- votinvv_datapulse-0.0.1/datapulse/types.py +58 -0
- votinvv_datapulse-0.0.1/pyproject.toml +48 -0
- votinvv_datapulse-0.0.1/setup.cfg +4 -0
- votinvv_datapulse-0.0.1/votinvv_datapulse.egg-info/PKG-INFO +77 -0
- votinvv_datapulse-0.0.1/votinvv_datapulse.egg-info/SOURCES.txt +16 -0
- votinvv_datapulse-0.0.1/votinvv_datapulse.egg-info/dependency_links.txt +1 -0
- votinvv_datapulse-0.0.1/votinvv_datapulse.egg-info/requires.txt +6 -0
- votinvv_datapulse-0.0.1/votinvv_datapulse.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: votinvv-datapulse
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: DataPulse SDK — decorators and runtime context for spec authors
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/votinvv/datapulse
|
|
7
|
+
Project-URL: Repository, https://github.com/votinvv/datapulse
|
|
8
|
+
Project-URL: Issues, https://github.com/votinvv/datapulse/issues
|
|
9
|
+
Keywords: data-engineering,pipelines,scd2,postgresql,etl
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Topic :: Database
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: postgres
|
|
23
|
+
Requires-Dist: psycopg[binary]>=3.2; extra == "postgres"
|
|
24
|
+
Provides-Extra: oracle
|
|
25
|
+
Requires-Dist: oracledb>=3.0; extra == "oracle"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# DataPulse SDK
|
|
29
|
+
|
|
30
|
+
The developer-facing library of [DataPulse](https://github.com/votinvv/datapulse) —
|
|
31
|
+
declarative data pipelines over PostgreSQL with SCD2 versioning, parallel
|
|
32
|
+
builds and a full audit trail.
|
|
33
|
+
|
|
34
|
+
Spec authors install this package for IDE autocompletion and local runs:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
pip install votinvv-datapulse
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The distribution is named `votinvv-datapulse`; the import package is `datapulse`:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from datapulse import spec, attr, mode, Self
|
|
44
|
+
from datapulse.types import bigint, text, timestamptz
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@spec(
|
|
48
|
+
dataset="raw.customer",
|
|
49
|
+
num=1,
|
|
50
|
+
descr="Customers",
|
|
51
|
+
attrs=[
|
|
52
|
+
attr("customer_id", bigint, descr="Customer id", is_primary_key=True),
|
|
53
|
+
attr("full_name", text, descr="Full name"),
|
|
54
|
+
],
|
|
55
|
+
modes=[mode("initial", "init", True), mode("increment", "incr", True)],
|
|
56
|
+
)
|
|
57
|
+
def build(param):
|
|
58
|
+
with Self() as db:
|
|
59
|
+
db.execute("insert into raw.customer_1_$ (...) select ...")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The SDK is pure stdlib — database drivers import lazily. To execute mappings
|
|
63
|
+
locally (e.g. via `datapulse.dev.run_local`), pull the drivers you need:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
pip install "votinvv-datapulse[postgres]" # psycopg
|
|
67
|
+
pip install "votinvv-datapulse[oracle]" # oracledb
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The server side — engine, HTTP API and UI — ships as the
|
|
71
|
+
[`votinvv/datapulse`](https://hub.docker.com/r/votinvv/datapulse) Docker
|
|
72
|
+
image; see the [project README](https://github.com/votinvv/datapulse) for the
|
|
73
|
+
full picture.
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
[Apache-2.0](https://github.com/votinvv/datapulse/blob/main/LICENSE)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# DataPulse SDK
|
|
2
|
+
|
|
3
|
+
The developer-facing library of [DataPulse](https://github.com/votinvv/datapulse) —
|
|
4
|
+
declarative data pipelines over PostgreSQL with SCD2 versioning, parallel
|
|
5
|
+
builds and a full audit trail.
|
|
6
|
+
|
|
7
|
+
Spec authors install this package for IDE autocompletion and local runs:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pip install votinvv-datapulse
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The distribution is named `votinvv-datapulse`; the import package is `datapulse`:
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from datapulse import spec, attr, mode, Self
|
|
17
|
+
from datapulse.types import bigint, text, timestamptz
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@spec(
|
|
21
|
+
dataset="raw.customer",
|
|
22
|
+
num=1,
|
|
23
|
+
descr="Customers",
|
|
24
|
+
attrs=[
|
|
25
|
+
attr("customer_id", bigint, descr="Customer id", is_primary_key=True),
|
|
26
|
+
attr("full_name", text, descr="Full name"),
|
|
27
|
+
],
|
|
28
|
+
modes=[mode("initial", "init", True), mode("increment", "incr", True)],
|
|
29
|
+
)
|
|
30
|
+
def build(param):
|
|
31
|
+
with Self() as db:
|
|
32
|
+
db.execute("insert into raw.customer_1_$ (...) select ...")
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The SDK is pure stdlib — database drivers import lazily. To execute mappings
|
|
36
|
+
locally (e.g. via `datapulse.dev.run_local`), pull the drivers you need:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
pip install "votinvv-datapulse[postgres]" # psycopg
|
|
40
|
+
pip install "votinvv-datapulse[oracle]" # oracledb
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The server side — engine, HTTP API and UI — ships as the
|
|
44
|
+
[`votinvv/datapulse`](https://hub.docker.com/r/votinvv/datapulse) Docker
|
|
45
|
+
image; see the [project README](https://github.com/votinvv/datapulse) for the
|
|
46
|
+
full picture.
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
[Apache-2.0](https://github.com/votinvv/datapulse/blob/main/LICENSE)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""DataPulse SDK — the developer-facing library.
|
|
2
|
+
|
|
3
|
+
Installed by spec authors (`pip install data-pulse`) and imported in spec files:
|
|
4
|
+
|
|
5
|
+
from datapulse import spec, attr, mode, Self
|
|
6
|
+
from datapulse.types import bigint, text
|
|
7
|
+
|
|
8
|
+
@spec(dataset="raw.customer", num=1, attrs=[...], modes=[...])
|
|
9
|
+
def build(param):
|
|
10
|
+
with Self() as db:
|
|
11
|
+
db.execute("insert into raw.customer_1_$ (...) select ...")
|
|
12
|
+
|
|
13
|
+
This package has NO runtime dependencies on Postgres, FastAPI, or the server —
|
|
14
|
+
psycopg is imported lazily inside `Self` only. It carries: the declarative
|
|
15
|
+
decorators, the type aliases, the `BuildParams` shape (so the IDE can
|
|
16
|
+
autocomplete `param.`), the built-in `Self` context and the `secret()` helper.
|
|
17
|
+
The server reuses the same decorators for validation/apply.
|
|
18
|
+
|
|
19
|
+
The metadata payload a `@spec` builds lives on the function as the attribute
|
|
20
|
+
`__datapulse__` — a plain dict the server reads by importing the module.
|
|
21
|
+
|
|
22
|
+
User contexts (Oracle / S3 / Kafka) live in a developer-authored `context.py`
|
|
23
|
+
as `@contextmanager` functions and read their secrets via `secret(...)`.
|
|
24
|
+
"""
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
__version__ = "0.0.1"
|
|
28
|
+
|
|
29
|
+
from .decorators import attr, mode, spec
|
|
30
|
+
from .flow import CatalogSpec, flowspec
|
|
31
|
+
from .params import BuildParams
|
|
32
|
+
from .sources import Self
|
|
33
|
+
from .secrets import secret, secret_section, SecretError
|
|
34
|
+
from .types import DataType
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"spec", "attr", "mode", "DataType", "flowspec", "CatalogSpec",
|
|
38
|
+
"BuildParams", "Self", "secret", "secret_section", "SecretError",
|
|
39
|
+
]
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""Declarative decorators: `@spec`, `attr`, `mode`.
|
|
2
|
+
|
|
3
|
+
A spec file imports `spec` and decorates its `build(param)` function. The
|
|
4
|
+
decorator attaches the metadata payload as `build.__datapulse__` — a plain dict
|
|
5
|
+
the server reads when the module is imported at apply time. Nothing about the
|
|
6
|
+
function itself changes; it is still a normal Python callable that the engine
|
|
7
|
+
will invoke as `build(param)` in production and the developer may invoke directly
|
|
8
|
+
(e.g. via `datapulse.dev.run_local` from a scratch script or a test).
|
|
9
|
+
|
|
10
|
+
The payload shape is the SAME dict shape the server's DDL planner consumes, so
|
|
11
|
+
no translation layer is needed between SDK and server.
|
|
12
|
+
|
|
13
|
+
Design choices:
|
|
14
|
+
- `attr`/`mode` are factory functions returning dicts, not classes: a spec is
|
|
15
|
+
data, and the server treats it as data. Keeping it as dicts avoids any
|
|
16
|
+
magic and keeps `__datapulse__` trivially serialisable.
|
|
17
|
+
- `order_id` defaults to declaration order (1-based), matching the XML format.
|
|
18
|
+
- `is_chunk` implies `is_primary_key` (the chunk attribute is part of the
|
|
19
|
+
logical key) — enforced here at decoration time.
|
|
20
|
+
"""
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
from typing import Any, Callable
|
|
24
|
+
|
|
25
|
+
from .types import MODE_TYPES
|
|
26
|
+
|
|
27
|
+
# `core` holds the product's journals and helpers; they live in the same
|
|
28
|
+
# database as the data, so a dataset must not collide with them.
|
|
29
|
+
RESERVED_SCHEMAS = frozenset({"public", "core", "pg_catalog", "information_schema"})
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def attr(
|
|
33
|
+
code: str,
|
|
34
|
+
data_type: str,
|
|
35
|
+
*,
|
|
36
|
+
descr: str | None = None,
|
|
37
|
+
is_primary_key: bool = False,
|
|
38
|
+
is_chunk: bool = False,
|
|
39
|
+
order_id: int | None = None,
|
|
40
|
+
) -> dict:
|
|
41
|
+
"""Declare one attribute (column) of a spec.
|
|
42
|
+
|
|
43
|
+
`code` — column name (PostgreSQL identifier)
|
|
44
|
+
`data_type` — one of datapulse.types.* (or a matching string)
|
|
45
|
+
`descr` — human description (defaults to `code`)
|
|
46
|
+
`is_primary_key` — part of the logical key
|
|
47
|
+
`is_chunk` — the chunking attribute; there must be exactly one per
|
|
48
|
+
spec, and it must be part of the key
|
|
49
|
+
`order_id` — physical column order (defaults to declaration order)
|
|
50
|
+
"""
|
|
51
|
+
return {
|
|
52
|
+
"code": code,
|
|
53
|
+
"descr": descr or code,
|
|
54
|
+
"data_type": data_type,
|
|
55
|
+
"is_primary_key": bool(is_primary_key),
|
|
56
|
+
"is_chunk": bool(is_chunk),
|
|
57
|
+
"order_id": order_id, # filled in by @spec if None
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def mode(code: str, type_code: str, is_clear: bool) -> dict:
|
|
62
|
+
"""Declare one build mode of a spec.
|
|
63
|
+
|
|
64
|
+
`code` — mode name (free-form; `initial`/`increment` are conventional)
|
|
65
|
+
`type_code` — one of init/incr/sect/appd/skip (datapulse.types.MODE_TYPES)
|
|
66
|
+
`is_clear` — does a build in this mode consume EVERY source change up to its
|
|
67
|
+
snapshot? Required, never inferred: the next incremental build
|
|
68
|
+
starts its delta at the last clear build's snapshot, so calling
|
|
69
|
+
a partial mode clear silently loses whatever changed in between.
|
|
70
|
+
`initial`/`increment` are normally True; a mode that reloads a
|
|
71
|
+
section (`sect`) or appends (`appd`) is normally False.
|
|
72
|
+
"""
|
|
73
|
+
if type_code not in MODE_TYPES:
|
|
74
|
+
raise ValueError(
|
|
75
|
+
f"mode type_code must be one of {MODE_TYPES}, got {type_code!r}"
|
|
76
|
+
)
|
|
77
|
+
if not isinstance(is_clear, bool):
|
|
78
|
+
raise ValueError(
|
|
79
|
+
f"mode {code!r}: is_clear must be True or False (declare it explicitly)"
|
|
80
|
+
)
|
|
81
|
+
return {"mode_code": code, "type_code": type_code, "is_clear": is_clear}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def spec(
|
|
85
|
+
*,
|
|
86
|
+
dataset: str,
|
|
87
|
+
num: int,
|
|
88
|
+
descr: str = "",
|
|
89
|
+
parallel: int = 1,
|
|
90
|
+
attrs: list[dict],
|
|
91
|
+
modes: list[dict] | None = None,
|
|
92
|
+
sources: list[str] | None = None,
|
|
93
|
+
) -> Callable[[Callable], Callable]:
|
|
94
|
+
"""Decorate `def build(param): ...` with the spec's metadata.
|
|
95
|
+
|
|
96
|
+
The metadata is attached as `build.__datapulse__` and the function is returned
|
|
97
|
+
unchanged, so the same function is what the engine calls in production and
|
|
98
|
+
what the developer may call from a scratch script or a test.
|
|
99
|
+
|
|
100
|
+
`dataset` — qualified 'schema.name' (the data DB schema + table prefix)
|
|
101
|
+
`num` — spec number within the dataset (1, 2, ... for parallel runs)
|
|
102
|
+
`parallel` — worker parallelism across chunks
|
|
103
|
+
`attrs` — list of attr(...) dicts
|
|
104
|
+
`modes` — list of mode(...) dicts
|
|
105
|
+
`sources` — list of dataset codes this spec reads from
|
|
106
|
+
"""
|
|
107
|
+
if num < 1:
|
|
108
|
+
raise ValueError(f"spec num must be >= 1, got {num}")
|
|
109
|
+
if parallel < 1:
|
|
110
|
+
raise ValueError(f"parallel must be >= 1, got {parallel}")
|
|
111
|
+
if not attrs:
|
|
112
|
+
raise ValueError("a spec must declare at least one attribute")
|
|
113
|
+
if "." not in dataset or dataset.split(".", 1)[0].lower() in RESERVED_SCHEMAS:
|
|
114
|
+
raise ValueError(
|
|
115
|
+
f"dataset must be a qualified 'schema.name' and not under "
|
|
116
|
+
f"{'/'.join(sorted(RESERVED_SCHEMAS))}: {dataset!r}"
|
|
117
|
+
)
|
|
118
|
+
if dataset.split(".", 1)[1][-1:].isdigit():
|
|
119
|
+
# The spec's full name is <dataset>_<num> (like its physical table);
|
|
120
|
+
# a digit-ending dataset name would make that suffix ambiguous.
|
|
121
|
+
raise ValueError(
|
|
122
|
+
f"the dataset name cannot end with a digit: {dataset!r} "
|
|
123
|
+
"(the _<num> suffix is reserved for the spec number)"
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
# Fill order_id by declaration order; enforce chunk⇒key.
|
|
127
|
+
prepared_attrs: list[dict] = []
|
|
128
|
+
for i, a in enumerate(attrs, start=1):
|
|
129
|
+
a = dict(a) # don't mutate the caller's dict
|
|
130
|
+
if a.get("order_id") is None:
|
|
131
|
+
a["order_id"] = i
|
|
132
|
+
if a.get("is_chunk") and not a.get("is_primary_key"):
|
|
133
|
+
raise ValueError(
|
|
134
|
+
f"attribute {a['code']!r}: is_chunk implies is_primary_key (the chunk "
|
|
135
|
+
"attribute must be part of the logical key)"
|
|
136
|
+
)
|
|
137
|
+
prepared_attrs.append(a)
|
|
138
|
+
|
|
139
|
+
payload = {
|
|
140
|
+
"dataset_code": dataset,
|
|
141
|
+
"build_spec_num": int(num),
|
|
142
|
+
"descr": descr or "",
|
|
143
|
+
"parallel_cnt": int(parallel),
|
|
144
|
+
"attrs": prepared_attrs,
|
|
145
|
+
"modes": list(modes or []),
|
|
146
|
+
"sources": list(sources or []),
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
def decorate(build_fn: Callable[..., Any]) -> Callable[..., Any]:
|
|
150
|
+
build_fn.__datapulse__ = payload # type: ignore[attr-defined]
|
|
151
|
+
return build_fn
|
|
152
|
+
|
|
153
|
+
return decorate
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""`run_local` — run a spec's `build(param)` in the IDE, no server.
|
|
2
|
+
|
|
3
|
+
The spec file itself stays clean (no executable tail); the developer calls
|
|
4
|
+
run_local from a scratch script, a REPL or a test:
|
|
5
|
+
|
|
6
|
+
from datapulse.dev import run_local
|
|
7
|
+
run_local(build, mode_code="increment")
|
|
8
|
+
|
|
9
|
+
`run_local` builds a local `BuildParams`, calls `build(param)`, and prints a
|
|
10
|
+
one-line summary. The mapping talks to the data DB itself (via `Self`), so a
|
|
11
|
+
local run needs `DATAPULSE_SECRETS_FILE` pointing at a store whose `Self`
|
|
12
|
+
section reaches the developer's local data DB. There is nothing to collect and
|
|
13
|
+
show anymore — the mapping wrote its slice into the interface table directly.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Any, Callable
|
|
18
|
+
|
|
19
|
+
from .params import BuildParams
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def run_local(
|
|
23
|
+
build_fn: Callable[..., Any],
|
|
24
|
+
*,
|
|
25
|
+
mode_code: str = "initial",
|
|
26
|
+
from_build_id: int = 0,
|
|
27
|
+
to_build_id: int | None = None,
|
|
28
|
+
previous_time: Any = None,
|
|
29
|
+
keys: str | None = None,
|
|
30
|
+
parallel_cnt: int | None = None,
|
|
31
|
+
) -> BuildParams:
|
|
32
|
+
"""Run `build_fn` with a local `BuildParams`, print a summary, return it.
|
|
33
|
+
|
|
34
|
+
`parallel_cnt` defaults to whatever the spec declares, so a local run sees
|
|
35
|
+
the same value the engine would pass.
|
|
36
|
+
"""
|
|
37
|
+
meta = getattr(build_fn, "__datapulse__", None) or {}
|
|
38
|
+
param = BuildParams(
|
|
39
|
+
mode_code=mode_code,
|
|
40
|
+
from_build_id=from_build_id,
|
|
41
|
+
to_build_id=to_build_id,
|
|
42
|
+
previous_time=previous_time,
|
|
43
|
+
keys=keys,
|
|
44
|
+
parallel_cnt=parallel_cnt if parallel_cnt is not None
|
|
45
|
+
else int(meta.get("parallel_cnt", 1)),
|
|
46
|
+
)
|
|
47
|
+
build_fn(param)
|
|
48
|
+
who = f"{meta['dataset_code']} #{meta['build_spec_num']}" if meta else build_fn.__name__
|
|
49
|
+
print(f"[run_local] {who} mode={mode_code} — build() returned")
|
|
50
|
+
return param
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""`@flowspec` — flow templates the data engineer authors in `flowspec.py`.
|
|
2
|
+
|
|
3
|
+
A flowspec is a plain function that receives the spec CATALOG and returns the
|
|
4
|
+
launch plan — a list of `(spec_name, mode_code)` pairs. It lives in one
|
|
5
|
+
`flowspec.py` (a settings object, applied through the same upgrade transport as
|
|
6
|
+
specs and connect.py) and shows up as a launch button in the UI:
|
|
7
|
+
|
|
8
|
+
from datapulse import flowspec
|
|
9
|
+
|
|
10
|
+
@flowspec(descr="Daily increment of the whole warehouse")
|
|
11
|
+
def daily(catalog):
|
|
12
|
+
return [(s.name, "increment") for s in catalog if "increment" in s.modes]
|
|
13
|
+
|
|
14
|
+
@flowspec(descr="Micro-batch carousel", repeat=True)
|
|
15
|
+
def carousel(catalog):
|
|
16
|
+
return [(s.name, "increment") for s in catalog if "increment" in s.modes]
|
|
17
|
+
|
|
18
|
+
Why code and not a declarative list: "every spec that has an increment mode" is
|
|
19
|
+
a QUERY against the catalog, not a list — it stays current as specs come and
|
|
20
|
+
go. The engine re-evaluates the flowspec on every launch (and on every repeat
|
|
21
|
+
iteration), so a freshly applied spec joins the next run by itself.
|
|
22
|
+
|
|
23
|
+
`repeat=True` relaunches the flow as user `system` each time an iteration
|
|
24
|
+
completes fully — a quasi-online micro-batch pipeline. An iteration completes
|
|
25
|
+
when EVERY build reached done; a failed build holds its dependent subtree until
|
|
26
|
+
support marks it fixed (the flow waits — see the server docs), so a repeat
|
|
27
|
+
carousel never spins over unresolved breakage.
|
|
28
|
+
|
|
29
|
+
The launch screen's `keys` value is passed by the ENGINE into every build of
|
|
30
|
+
the flow (`param.keys`); the flowspec function does not see or handle it.
|
|
31
|
+
"""
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
from dataclasses import dataclass
|
|
35
|
+
from typing import Any, Callable
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class CatalogSpec:
|
|
40
|
+
"""One installed spec, as a flowspec's `catalog` argument presents it."""
|
|
41
|
+
|
|
42
|
+
name: str # full spec name: 'raw.customer_1'
|
|
43
|
+
dataset_code: str # 'raw.customer'
|
|
44
|
+
num: int # spec number within the dataset
|
|
45
|
+
modes: tuple[str, ...] # declared mode codes, e.g. ('increment', 'initial')
|
|
46
|
+
sources: tuple[str, ...] # dataset codes this spec reads from
|
|
47
|
+
descr: str = ""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def flowspec(*, descr: str = "", repeat: bool = False) -> Callable[[Callable], Callable]:
|
|
51
|
+
"""Declare a flow template. The function name is the flowspec's code (what
|
|
52
|
+
the UI button and the journal show); the function must accept the catalog
|
|
53
|
+
(a list of CatalogSpec) and return an iterable of (spec_name, mode_code)
|
|
54
|
+
pairs. The metadata rides on the function as `__datapulse_flowspec__` — the
|
|
55
|
+
same pattern as `@spec`."""
|
|
56
|
+
|
|
57
|
+
def decorate(fn: Callable[..., Any]) -> Callable[..., Any]:
|
|
58
|
+
fn.__datapulse_flowspec__ = { # type: ignore[attr-defined]
|
|
59
|
+
"code": fn.__name__,
|
|
60
|
+
"descr": descr or "",
|
|
61
|
+
"repeat": bool(repeat),
|
|
62
|
+
}
|
|
63
|
+
return fn
|
|
64
|
+
|
|
65
|
+
return decorate
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""BuildParams — the parameter set of one build, handed by the engine to
|
|
2
|
+
`build(param)`.
|
|
3
|
+
|
|
4
|
+
This used to be a `BuildContext` with `read`/`write`/`connection` methods. The
|
|
5
|
+
model changed: the mapping fills its interface table ITSELF — through the `Self`
|
|
6
|
+
context (see `sources.py`) with plain SQL — and the engine then compares and
|
|
7
|
+
merges it in (SCD2). So `build` receives only the recompute PARAMETERS, no
|
|
8
|
+
data-access methods.
|
|
9
|
+
|
|
10
|
+
The mental model is a PL/pgSQL load procedure: the core calls a function with a
|
|
11
|
+
fixed parameter set. Here the set is packed into one `param` object (instead of
|
|
12
|
+
a long signature) — adding a field does not break existing mappings, and
|
|
13
|
+
`param.` autocompletes in the IDE.
|
|
14
|
+
|
|
15
|
+
Fields:
|
|
16
|
+
mode_code — the NAME of the launch mode (`initial` / `increment` /
|
|
17
|
+
`manual` / ...); the mapping branches its logic on it. The
|
|
18
|
+
mode's TYPE (init/incr/sect/appd/skip) is the engine's
|
|
19
|
+
business (the interface → spec-table merge) and is not part
|
|
20
|
+
of the parameters.
|
|
21
|
+
from_build_id — the delta's lower bound (EXCLUSIVE): the source snapshot of
|
|
22
|
+
this spec's last CLEAR successful build. 0 on the first build
|
|
23
|
+
— so `build_id > 0` reads the sources whole. Never None: it
|
|
24
|
+
is inlined into an f-string.
|
|
25
|
+
to_build_id — the delta's upper bound and THIS build's source snapshot
|
|
26
|
+
(INCLUSIVE). The engine freezes the sources at it: if a
|
|
27
|
+
source build was still running when this build was created,
|
|
28
|
+
it is `min(its build_id) - 1`, otherwise the build's own id.
|
|
29
|
+
previous_time — when the previous clear successful build finished (a
|
|
30
|
+
time-based watermark: `where updated_at >=
|
|
31
|
+
param.previous_time`), or None.
|
|
32
|
+
keys — "recompute keys": the raw input from the build launch screen.
|
|
33
|
+
Whether to use them is the mapping's decision (the typical
|
|
34
|
+
case is a pinpoint recompute). None when nothing was entered.
|
|
35
|
+
parallel_cnt — the spec's parallelism. The engine slices the merge into that
|
|
36
|
+
many chunks itself; for the mapping it is a hint — a heavy
|
|
37
|
+
statement can be wrapped in
|
|
38
|
+
`call core.parallel(param.parallel_cnt)`.
|
|
39
|
+
|
|
40
|
+
A source's delta is read straight off its dataset view (all columns, all rows):
|
|
41
|
+
|
|
42
|
+
from raw.loan_contract
|
|
43
|
+
where build_id > param.from_build_id and build_id <= param.to_build_id
|
|
44
|
+
|
|
45
|
+
A source's as-of snapshot — same `to_build_id`, via the SCD2 predicate
|
|
46
|
+
(`end_build_id` is INCLUSIVE — the last build in which the version is still
|
|
47
|
+
current):
|
|
48
|
+
|
|
49
|
+
where build_id <= param.to_build_id
|
|
50
|
+
and (end_build_id is null or end_build_id >= param.to_build_id)
|
|
51
|
+
and is_active
|
|
52
|
+
"""
|
|
53
|
+
from __future__ import annotations
|
|
54
|
+
|
|
55
|
+
from dataclasses import dataclass
|
|
56
|
+
from typing import Any
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass
|
|
60
|
+
class BuildParams:
|
|
61
|
+
"""The static parameter set the engine hands to `build(param)`."""
|
|
62
|
+
|
|
63
|
+
mode_code: str = "initial"
|
|
64
|
+
from_build_id: int = 0
|
|
65
|
+
to_build_id: int | None = None
|
|
66
|
+
previous_time: Any = None # datetime/str — the engine fills it; None on the first build
|
|
67
|
+
keys: str | None = None
|
|
68
|
+
parallel_cnt: int = 1
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""`secret(context, key)` — fetches a context's secret value from the store.
|
|
2
|
+
|
|
3
|
+
Secrets live OUTSIDE the code and OUTSIDE git: the context file (`context.py`)
|
|
4
|
+
carries only the connection CODE, while the values (passwords, DSNs) sit in a
|
|
5
|
+
separate store. Today the store is a plain JSON file, its path in the
|
|
6
|
+
`DATAPULSE_SECRETS_FILE` env var:
|
|
7
|
+
|
|
8
|
+
{ "RBS": {"dsn": "...", "user": "...", "password": "..."},
|
|
9
|
+
"Self": {"host": "...", "port": 5433, "user": "...",
|
|
10
|
+
"password": "...", "dbname": "datapulse"} }
|
|
11
|
+
|
|
12
|
+
The "context → set of fields" model mirrors Vault (path → fields), so the store
|
|
13
|
+
backend can later be swapped for Vault without touching `secret()` call sites.
|
|
14
|
+
The file is read on every access (not a hot path — only when a connection is
|
|
15
|
+
opened), so a secrets edit is picked up without a restart.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
ENV_SECRETS_FILE = "DATAPULSE_SECRETS_FILE"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class SecretError(RuntimeError):
|
|
27
|
+
"""A secret is missing or the store is unreadable/misconfigured."""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _store() -> dict:
|
|
31
|
+
path = os.environ.get(ENV_SECRETS_FILE)
|
|
32
|
+
if not path:
|
|
33
|
+
raise SecretError(
|
|
34
|
+
f"{ENV_SECRETS_FILE} is not set — no secrets store configured."
|
|
35
|
+
)
|
|
36
|
+
p = Path(path)
|
|
37
|
+
if not p.is_file():
|
|
38
|
+
raise SecretError(f"secrets file not found: {p}")
|
|
39
|
+
try:
|
|
40
|
+
data = json.loads(p.read_text(encoding="utf-8"))
|
|
41
|
+
except Exception as e: # noqa: BLE001
|
|
42
|
+
raise SecretError(f"cannot read secrets file {p}: {e}")
|
|
43
|
+
if not isinstance(data, dict):
|
|
44
|
+
raise SecretError(
|
|
45
|
+
f"secrets file {p} must be a JSON object {{context: {{key: value}}}}."
|
|
46
|
+
)
|
|
47
|
+
return data
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def secret_section(context: str) -> dict:
|
|
51
|
+
"""All secrets of one context as a dict. Raises SecretError if absent."""
|
|
52
|
+
section = _store().get(context)
|
|
53
|
+
if not isinstance(section, dict):
|
|
54
|
+
raise SecretError(f"no secrets for context {context!r} in the store.")
|
|
55
|
+
return dict(section)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def secret(context: str, key: str):
|
|
59
|
+
"""One secret value. Raises SecretError with a clear message if not set."""
|
|
60
|
+
section = secret_section(context)
|
|
61
|
+
if key not in section:
|
|
62
|
+
raise SecretError(f"secret {context}.{key} is not set.")
|
|
63
|
+
return section[key]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Built-in contexts shipped by the product.
|
|
2
|
+
|
|
3
|
+
`Self` — the connection to the project's DATA database. A mapping uses it to
|
|
4
|
+
fill its own interface table with plain SQL:
|
|
5
|
+
|
|
6
|
+
from datapulse import Self
|
|
7
|
+
|
|
8
|
+
def build(param):
|
|
9
|
+
with Self() as db:
|
|
10
|
+
db.execute(f'''
|
|
11
|
+
insert into raw.customer_1_$ (customer_id, full_name, updated_at)
|
|
12
|
+
select customer_id, full_name, updated_at
|
|
13
|
+
from staging.customer
|
|
14
|
+
where updated_at >= '{param.previous_time}'
|
|
15
|
+
''')
|
|
16
|
+
|
|
17
|
+
The interface-table name (`schema.name_<num>_$`) is written by hand on purpose —
|
|
18
|
+
the engineer copy-pastes the SELECT from DataGrip, no magic name substitution.
|
|
19
|
+
The engine takes over after the interface table is filled: it compares and
|
|
20
|
+
merges into the SCD2 spec table.
|
|
21
|
+
|
|
22
|
+
`Self`'s credentials come from the `Self` section of the secrets store
|
|
23
|
+
(see `secrets.py`). psycopg is imported LAZILY — the SDK carries no driver
|
|
24
|
+
dependency; the product image ships psycopg, and a developer installs it only if
|
|
25
|
+
they run a spec locally. `with Self() as db` yields a psycopg connection (it has
|
|
26
|
+
`.execute()`, `.cursor()`, `.commit()`); the connection commits on a clean exit
|
|
27
|
+
and rolls back on an exception.
|
|
28
|
+
|
|
29
|
+
User contexts (Oracle / S3 / Kafka / ...) are NOT here — they live in the
|
|
30
|
+
developer-authored `context.py` as `@contextmanager` functions. Only `Self` is
|
|
31
|
+
built in, because only the product knows it always targets Postgres.
|
|
32
|
+
"""
|
|
33
|
+
from __future__ import annotations
|
|
34
|
+
|
|
35
|
+
from contextlib import contextmanager
|
|
36
|
+
|
|
37
|
+
from .secrets import secret_section
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@contextmanager
|
|
41
|
+
def Self():
|
|
42
|
+
"""Open a connection to the project's data DB (yields a psycopg connection)."""
|
|
43
|
+
import psycopg # lazy: the driver is provided by the image / dev environment
|
|
44
|
+
|
|
45
|
+
p = secret_section("Self")
|
|
46
|
+
conn = psycopg.connect(
|
|
47
|
+
host=p["host"],
|
|
48
|
+
port=int(p.get("port", 5432)),
|
|
49
|
+
dbname=p["dbname"],
|
|
50
|
+
user=p["user"],
|
|
51
|
+
password=p.get("password", ""),
|
|
52
|
+
)
|
|
53
|
+
try:
|
|
54
|
+
yield conn
|
|
55
|
+
conn.commit()
|
|
56
|
+
except BaseException:
|
|
57
|
+
conn.rollback()
|
|
58
|
+
raise
|
|
59
|
+
finally:
|
|
60
|
+
conn.close()
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Type aliases for spec attributes.
|
|
2
|
+
|
|
3
|
+
These are plain strings kept in one place so:
|
|
4
|
+
- the IDE autocompletes `bigint`, `text`, ... (no typos in `data_type`)
|
|
5
|
+
- the server's whitelist matches exactly what the SDK advertises
|
|
6
|
+
|
|
7
|
+
The server re-exports the same whitelist from its own validation module so the
|
|
8
|
+
two never drift apart.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
# PostgreSQL types a spec attribute may use. Matches the XSD `columnType`
|
|
13
|
+
# whitelist the previous XML format allowed (so existing specs translate 1:1).
|
|
14
|
+
bigint = "bigint"
|
|
15
|
+
integer = "integer"
|
|
16
|
+
smallint = "smallint"
|
|
17
|
+
text = "text"
|
|
18
|
+
boolean = "boolean"
|
|
19
|
+
date = "date"
|
|
20
|
+
timestamptz = "timestamptz"
|
|
21
|
+
jsonb = "jsonb"
|
|
22
|
+
uuid = "uuid"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def varchar(n: int) -> str:
|
|
26
|
+
return f"varchar({n})"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def numeric(precision: int, scale: int) -> str:
|
|
30
|
+
return f"numeric({precision},{scale})"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# The full whitelist, as a regex pattern (the server validates against it too).
|
|
34
|
+
ALLOWED_TYPES_PATTERN = (
|
|
35
|
+
r"^(bigint|integer|smallint|text|boolean|date|timestamptz|jsonb|uuid"
|
|
36
|
+
r"|varchar\(\d+\)|numeric\(\d+,\d+\))$"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# Reserved attribute names — the engine injects its own physical columns with
|
|
40
|
+
# these names (SCD2), and the dataset view adds build_spec_number, so a spec
|
|
41
|
+
# cannot declare them.
|
|
42
|
+
RESERVED_ATTRS = frozenset({"build_id", "end_build_id", "is_active", "build_spec_number"})
|
|
43
|
+
|
|
44
|
+
# Build-mode types — how the engine moves the interface table into the spec table:
|
|
45
|
+
# init — full reload: rows absent from the slice are closed (tombstoned)
|
|
46
|
+
# incr — increment: only the keys present in the slice are touched
|
|
47
|
+
# sect — section reload: like init, but scoped to the chunk values in the slice
|
|
48
|
+
# appd — append only: rows are inserted, nothing is compared or closed
|
|
49
|
+
# skip — do nothing (the mapping is not even called); counters journal as 0
|
|
50
|
+
MODE_TYPES = ("init", "incr", "sect", "appd", "skip")
|
|
51
|
+
|
|
52
|
+
# A convenience alias used in `attr(..., data_type=DataType.bigint)`.
|
|
53
|
+
DataType = type("DataType", (), {
|
|
54
|
+
"bigint": bigint, "integer": integer, "smallint": smallint,
|
|
55
|
+
"text": text, "boolean": boolean, "date": date,
|
|
56
|
+
"timestamptz": timestamptz, "jsonb": jsonb, "uuid": uuid,
|
|
57
|
+
"varchar": staticmethod(varchar), "numeric": staticmethod(numeric),
|
|
58
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
# Distribution name on PyPI is votinvv-datapulse (plain "datapulse" is taken
|
|
7
|
+
# by an unrelated package, and PyPI rejects near-identical names like
|
|
8
|
+
# data-pulse); the import package stays `datapulse`.
|
|
9
|
+
name = "votinvv-datapulse"
|
|
10
|
+
dynamic = ["version"]
|
|
11
|
+
description = "DataPulse SDK — decorators and runtime context for spec authors"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "Apache-2.0"
|
|
14
|
+
requires-python = ">=3.11"
|
|
15
|
+
keywords = ["data-engineering", "pipelines", "scd2", "postgresql", "etl"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
|
+
"Topic :: Database",
|
|
25
|
+
"Topic :: Software Development :: Libraries",
|
|
26
|
+
]
|
|
27
|
+
# No third-party runtime deps: the SDK is pure stdlib so a spec author can
|
|
28
|
+
# `pip install votinvv-datapulse` and `from datapulse import spec` with nothing else.
|
|
29
|
+
# Drivers import lazily (psycopg inside Self) — pull them via extras when the
|
|
30
|
+
# mapping runs locally.
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
postgres = ["psycopg[binary]>=3.2"]
|
|
34
|
+
oracle = ["oracledb>=3.0"]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/votinvv/datapulse"
|
|
38
|
+
Repository = "https://github.com/votinvv/datapulse"
|
|
39
|
+
Issues = "https://github.com/votinvv/datapulse/issues"
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.dynamic]
|
|
42
|
+
version = { attr = "datapulse.__version__" }
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.packages.find]
|
|
45
|
+
where = ["."]
|
|
46
|
+
# Only ship the SDK package (datapulse/). The build root is sdk/, which contains
|
|
47
|
+
# only the datapulse package + this pyproject.toml — nothing else to exclude.
|
|
48
|
+
include = ["datapulse*"]
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: votinvv-datapulse
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: DataPulse SDK — decorators and runtime context for spec authors
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/votinvv/datapulse
|
|
7
|
+
Project-URL: Repository, https://github.com/votinvv/datapulse
|
|
8
|
+
Project-URL: Issues, https://github.com/votinvv/datapulse/issues
|
|
9
|
+
Keywords: data-engineering,pipelines,scd2,postgresql,etl
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Topic :: Database
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: postgres
|
|
23
|
+
Requires-Dist: psycopg[binary]>=3.2; extra == "postgres"
|
|
24
|
+
Provides-Extra: oracle
|
|
25
|
+
Requires-Dist: oracledb>=3.0; extra == "oracle"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# DataPulse SDK
|
|
29
|
+
|
|
30
|
+
The developer-facing library of [DataPulse](https://github.com/votinvv/datapulse) —
|
|
31
|
+
declarative data pipelines over PostgreSQL with SCD2 versioning, parallel
|
|
32
|
+
builds and a full audit trail.
|
|
33
|
+
|
|
34
|
+
Spec authors install this package for IDE autocompletion and local runs:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
pip install votinvv-datapulse
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The distribution is named `votinvv-datapulse`; the import package is `datapulse`:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from datapulse import spec, attr, mode, Self
|
|
44
|
+
from datapulse.types import bigint, text, timestamptz
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@spec(
|
|
48
|
+
dataset="raw.customer",
|
|
49
|
+
num=1,
|
|
50
|
+
descr="Customers",
|
|
51
|
+
attrs=[
|
|
52
|
+
attr("customer_id", bigint, descr="Customer id", is_primary_key=True),
|
|
53
|
+
attr("full_name", text, descr="Full name"),
|
|
54
|
+
],
|
|
55
|
+
modes=[mode("initial", "init", True), mode("increment", "incr", True)],
|
|
56
|
+
)
|
|
57
|
+
def build(param):
|
|
58
|
+
with Self() as db:
|
|
59
|
+
db.execute("insert into raw.customer_1_$ (...) select ...")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The SDK is pure stdlib — database drivers import lazily. To execute mappings
|
|
63
|
+
locally (e.g. via `datapulse.dev.run_local`), pull the drivers you need:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
pip install "votinvv-datapulse[postgres]" # psycopg
|
|
67
|
+
pip install "votinvv-datapulse[oracle]" # oracledb
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The server side — engine, HTTP API and UI — ships as the
|
|
71
|
+
[`votinvv/datapulse`](https://hub.docker.com/r/votinvv/datapulse) Docker
|
|
72
|
+
image; see the [project README](https://github.com/votinvv/datapulse) for the
|
|
73
|
+
full picture.
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
[Apache-2.0](https://github.com/votinvv/datapulse/blob/main/LICENSE)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
datapulse/__init__.py
|
|
5
|
+
datapulse/decorators.py
|
|
6
|
+
datapulse/dev.py
|
|
7
|
+
datapulse/flow.py
|
|
8
|
+
datapulse/params.py
|
|
9
|
+
datapulse/secrets.py
|
|
10
|
+
datapulse/sources.py
|
|
11
|
+
datapulse/types.py
|
|
12
|
+
votinvv_datapulse.egg-info/PKG-INFO
|
|
13
|
+
votinvv_datapulse.egg-info/SOURCES.txt
|
|
14
|
+
votinvv_datapulse.egg-info/dependency_links.txt
|
|
15
|
+
votinvv_datapulse.egg-info/requires.txt
|
|
16
|
+
votinvv_datapulse.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
datapulse
|