dq-export-connector 0.1.0.dev17__tar.gz → 0.1.0.dev18__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 (63) hide show
  1. dq_export_connector-0.1.0.dev18/.gitignore +5 -0
  2. dq_export_connector-0.1.0.dev18/PKG-INFO +151 -0
  3. dq_export_connector-0.1.0.dev18/README.md +138 -0
  4. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/_models/export_connector_credentials.py +25 -2
  5. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/_models/export_report.py +130 -20
  6. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/_models/export_worker_config.py +100 -8
  7. dq_export_connector-0.1.0.dev18/dq_export_connector/_models/snap_validation_result.py +34 -0
  8. dq_export_connector-0.1.0.dev18/dq_export_connector/audience/classify.py +98 -0
  9. dq_export_connector-0.1.0.dev18/dq_export_connector/audience/http.py +237 -0
  10. dq_export_connector-0.1.0.dev18/dq_export_connector/audience/identifiers.py +121 -0
  11. dq_export_connector-0.1.0.dev18/dq_export_connector/audience/inputs.py +80 -0
  12. dq_export_connector-0.1.0.dev18/dq_export_connector/audience/oauth.py +321 -0
  13. dq_export_connector-0.1.0.dev18/dq_export_connector/audience/sync.py +313 -0
  14. dq_export_connector-0.1.0.dev18/dq_export_connector/bucket/__init__.py +0 -0
  15. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/bucket/export.py +1 -1
  16. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/errors.py +29 -3
  17. dq_export_connector-0.1.0.dev18/dq_export_connector/redact.py +105 -0
  18. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/report.py +4 -0
  19. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/runner.py +87 -6
  20. dq_export_connector-0.1.0.dev18/dq_export_connector/snap/__init__.py +0 -0
  21. dq_export_connector-0.1.0.dev18/dq_export_connector/snap/client.py +143 -0
  22. dq_export_connector-0.1.0.dev18/dq_export_connector/snap/destination.py +154 -0
  23. dq_export_connector-0.1.0.dev18/dq_export_connector/snap/export.py +136 -0
  24. dq_export_connector-0.1.0.dev18/dq_export_connector/snap/session.py +70 -0
  25. dq_export_connector-0.1.0.dev18/dq_export_connector/snap/validate.py +38 -0
  26. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/pyproject.toml +11 -3
  27. dq_export_connector-0.1.0.dev18/scripts/_local.py +74 -0
  28. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/scripts/codegen-models.sh +1 -1
  29. dq_export_connector-0.1.0.dev18/scripts/consent.py +99 -0
  30. dq_export_connector-0.1.0.dev18/scripts/run_local.py +46 -0
  31. dq_export_connector-0.1.0.dev18/tests/__init__.py +0 -0
  32. dq_export_connector-0.1.0.dev18/tests/conftest.py +37 -0
  33. dq_export_connector-0.1.0.dev18/tests/fakes/__init__.py +0 -0
  34. dq_export_connector-0.1.0.dev18/tests/fakes/snap_fake.py +256 -0
  35. dq_export_connector-0.1.0.dev18/tests/test_http_and_oauth.py +398 -0
  36. dq_export_connector-0.1.0.dev18/tests/test_identifiers_and_inputs.py +118 -0
  37. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/tests/test_live_buckets.py +2 -2
  38. dq_export_connector-0.1.0.dev18/tests/test_live_snap.py +115 -0
  39. dq_export_connector-0.1.0.dev18/tests/test_scripts.py +22 -0
  40. dq_export_connector-0.1.0.dev18/tests/test_snap_runner.py +592 -0
  41. dq_export_connector-0.1.0.dev18/tests/test_sync_input.py +171 -0
  42. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/uv.lock +227 -4
  43. dq_export_connector-0.1.0.dev17/.gitignore +0 -63
  44. dq_export_connector-0.1.0.dev17/PKG-INFO +0 -55
  45. dq_export_connector-0.1.0.dev17/README.md +0 -44
  46. dq_export_connector-0.1.0.dev17/dq_export_connector/redact.py +0 -52
  47. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/.python-version +0 -0
  48. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/__init__.py +0 -0
  49. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/_models/__init__.py +0 -0
  50. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/_models/bucket_validation_result.py +0 -0
  51. {dq_export_connector-0.1.0.dev17/dq_export_connector/bucket → dq_export_connector-0.1.0.dev18/dq_export_connector/audience}/__init__.py +0 -0
  52. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/bucket/paths.py +0 -0
  53. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/bucket/store.py +0 -0
  54. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/bucket/upload.py +0 -0
  55. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/bucket/validate.py +0 -0
  56. {dq_export_connector-0.1.0.dev17/dq_export_connector/bucket → dq_export_connector-0.1.0.dev18/dq_export_connector}/datasets.py +0 -0
  57. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/dq_export_connector/log.py +0 -0
  58. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/tests/test_models_are_current.py +0 -0
  59. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/tests/test_paths.py +0 -0
  60. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/tests/test_redact.py +0 -0
  61. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/tests/test_runner.py +0 -0
  62. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/tests/test_store.py +0 -0
  63. {dq_export_connector-0.1.0.dev17 → dq_export_connector-0.1.0.dev18}/tests/test_upload.py +0 -0
@@ -0,0 +1,5 @@
1
+ # Local secrets for the consent CLI and the local runner.
2
+ credentials*.json
3
+ platform_secrets*.json
4
+ local/
5
+ /config*.json
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.5
2
+ Name: dq-export-connector
3
+ Version: 0.1.0.dev18
4
+ Summary: Worker logic for the Export Connector DCR.
5
+ Author: Decentriq
6
+ Requires-Python: >=3.10
7
+ Requires-Dist: pydantic<3,>=2.14
8
+ Provides-Extra: bucket
9
+ Requires-Dist: obstore<0.12,>=0.11.1; extra == 'bucket'
10
+ Provides-Extra: snap
11
+ Requires-Dist: requests<3,>=2.32; extra == 'snap'
12
+ Description-Content-Type: text/markdown
13
+
14
+ # dq-export-connector
15
+
16
+ Worker logic for the **Export Connector DCR**: one package for every
17
+ Connector Kind, each in its own sub-package with an extra of the same name for
18
+ its dependencies.
19
+
20
+ - The **bucket** kind uploads each Input's dataset to S3, Azure Blob or GCS
21
+ through [`obstore`](https://developmentseed.org/obstore/).
22
+ - The **snap** kind fills one Snap Segment per Input with hashed identifiers,
23
+ through Snap's Marketing API.
24
+
25
+ ddc pins this package by hash in a fully locked `requirements.txt` and runs
26
+ `dq_export_connector.runner.main` in the task's Python environment. It is
27
+ published to PyPI, since the compiled graph installs it from there.
28
+
29
+ - `dq_export_connector.runner`: the entry point. Reads `/input/config.json`,
30
+ `/input/credentials.json` and any platform secret under
31
+ `/input/platform_secrets/`, sets up logging, dispatches on the Connector Kind
32
+ and the action, then writes what the action reports.
33
+ - `dq_export_connector.errors`: the codes the worker reports, and
34
+ `ExportConnectorError`, which stops a run with one. Codes are named for the
35
+ situation, not the kind, so any kind can report them.
36
+ - `dq_export_connector.report`: collects a run's error, warnings and receipt
37
+ while it runs, and cuts each message to ddc's 1,000 characters once redacted.
38
+ - `dq_export_connector.redact`: keeps every value from the sealed half, and
39
+ URL query strings, out of log lines and result messages. For the ad
40
+ platforms it also masks tokens, `key=secret` pairs, JWTs and SHA-256 hex.
41
+ - `dq_export_connector.datasets`: how an Input's dataset maps to files (a
42
+ stored ZIP, or one raw file).
43
+ - `dq_export_connector.bucket`: the bucket kind.
44
+ - `dq_export_connector.audience`: what the ad-platform kinds share: HTTPS to an
45
+ allowlist with retries by idempotency class, OAuth, identifier
46
+ normalisation, and the per-Input sync flow.
47
+ - `dq_export_connector.snap`: the snap kind.
48
+ - `dq_export_connector._models`: pydantic models generated from ddc's JSON
49
+ schemas, so the config the worker reads and the report and validation
50
+ result it writes match ddc's Rust types. Regenerate them with
51
+ `scripts/codegen-models.sh` after the types change and
52
+ `decentriq_dcr_compiler` has been rebuilt; a test fails while they are
53
+ stale.
54
+
55
+ ```sh
56
+ uv run pytest # unit tests, against obstore's in-memory store and a fake Snap API
57
+ uv run pytest -m live # against real buckets and Snap, credentials from the environment
58
+ uv run mypy dq_export_connector tests scripts
59
+ ```
60
+
61
+ ## Snap
62
+
63
+ A Snap connector's config names the ad account and, per Input, a Segment, the
64
+ identifier type its lines hold and a Merge Mode. ddc validates it. The
65
+ credentials are the refresh token of the Snap user who consented; Decentriq's
66
+ Snap app is the `export_connector_snap_app` platform secret
67
+ (`{"clientId", "clientSecret"}`).
68
+
69
+ A run looks each Segment up by name in the ad account and creates it when
70
+ there is none, marked `Managed by Decentriq`. It writes into a same-named
71
+ Segment whoever made it, with a `SEGMENT_NOT_MANAGED` warning when Decentriq
72
+ didn't. ADD adds the Input's values; REPLACE empties the Segment first, so it
73
+ is briefly empty. A run stops at the first Input that fails. When the failure
74
+ came after the Segment changed, the error says so; a rerun is safe in both
75
+ modes. Don't run one connector twice at the same time.
76
+
77
+ An Input is one file of values, or a stored ZIP holding one: one value per
78
+ line, UTF-8, optional BOM, LF or CRLF, surrounding double quotes removed,
79
+ empty lines skipped, no header.
80
+
81
+ ### Identifiers
82
+
83
+ | Type | Normalisation before SHA-256 | Snap schema |
84
+ |---|---|---|
85
+ | `EMAIL` | trim, lowercase; exactly one `@` with text on both sides | `EMAIL_SHA256` |
86
+ | `PHONE` | drop a `(0)` right after the country code (`+44 (0)20…`, `+44-(0)20…`), keep digits (any script's, as ASCII; drops `+`), drop a leading `00`; 8–15 digits, not starting with `0` | `PHONE_SHA256` |
87
+ | `IDFA`, `GAID` | UUID form with hyphens, lowercased | `MOBILE_AD_ID_SHA256` |
88
+ | `*_SHA256` | must be 64 hex characters; lowercased, otherwise unchanged | as above |
89
+
90
+ A pre-hashed value only matches if it was hashed from the same form: for
91
+ `PHONE_SHA256`, the digits with country code and no `+` (`41791234567`).
92
+
93
+ Up to 25% invalid rows gives an `INVALID_ROWS` warning; more fails the run
94
+ before the Segment changes. An empty Input gives an `EMPTY_DATASET` warning
95
+ and leaves its Segment as it was, in both modes.
96
+
97
+ The receipt counts invalid rows by reason (`counts.invalidReasons`, and in the
98
+ warning or error message), never with the values themselves:
99
+
100
+ | Reason | Meaning |
101
+ |---|---|
102
+ | `EMAIL_NO_AT_SIGN`, `EMAIL_MULTIPLE_AT_SIGNS` | not exactly one `@` |
103
+ | `EMAIL_EMPTY_LOCAL_PART`, `EMAIL_EMPTY_DOMAIN` | nothing before or after the `@` |
104
+ | `PHONE_NO_DIGITS` | no digits at all |
105
+ | `PHONE_NATIONAL_FORMAT` | starts with `0` after dropping `00`, i.e. no country code |
106
+ | `PHONE_TOO_SHORT`, `PHONE_TOO_LONG` | fewer than 8 or more than 15 digits |
107
+ | `NOT_A_MOBILE_AD_ID` | not a UUID with hyphens |
108
+ | `NOT_SHA256_HEX` | a `*_SHA256` value that isn't 64 hex characters |
109
+ | `NOT_UTF8` | the line isn't valid UTF-8 |
110
+ | `CONTROL_CHARACTERS` | the value holds control characters or a byte order mark, usually because the file is UTF-16 |
111
+
112
+ ### Testing against Snap
113
+
114
+ The local files are gitignored in this directory:
115
+
116
+ - `platform_secrets.json`: `{"export_connector_snap_app": {"clientId": …, "clientSecret": …}}`, the dev app.
117
+ - `credentials.json`: written by the consent CLI.
118
+ - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "grantExpiresAt": null, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
119
+
120
+ 1. Consent, as the Snap user who has a role on the test ad account. The
121
+ redirect URI must be an https URI registered on the app; only the URL the
122
+ browser lands on matters.
123
+
124
+ ```sh
125
+ uv run python scripts/consent.py snap --platform-secrets platform_secrets.json \
126
+ --redirect-uri "$REDIRECT_URI" --out credentials.json --config config.json
127
+ ```
128
+ 2. Run:
129
+
130
+ ```sh
131
+ mkdir -p local/inputs && printf 'a@example.com\nb@example.com\n' > local/inputs/segA
132
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
133
+ --platform-secrets platform_secrets.json --mode validate
134
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
135
+ --platform-secrets platform_secrets.json
136
+ ```
137
+ 3. Live tests, including the check that Snap doesn't rotate refresh tokens:
138
+
139
+ ```sh
140
+ DQ_EXPORT_LIVE_SNAP_DIR=$PWD uv run pytest -m live -s tests/test_live_snap.py
141
+ ```
142
+
143
+ ## Releasing
144
+
145
+ Bump the version with `uv version <version> --no-sync`, which also updates
146
+ `uv.lock`, commit, and push a `dq-export-connector-v<version>` tag on that
147
+ commit; the `Publish dq-export-connector to PyPI` workflow tests, builds and
148
+ uploads it. Use `.devN` versions while developing; PyPI releases can't be replaced.
149
+ ddc then pins the new version, as
150
+ [ddc's export worker README](../../dcr-compiler/ddc/src/archv2/data_room/export_connector/README.md)
151
+ describes.
@@ -0,0 +1,138 @@
1
+ # dq-export-connector
2
+
3
+ Worker logic for the **Export Connector DCR**: one package for every
4
+ Connector Kind, each in its own sub-package with an extra of the same name for
5
+ its dependencies.
6
+
7
+ - The **bucket** kind uploads each Input's dataset to S3, Azure Blob or GCS
8
+ through [`obstore`](https://developmentseed.org/obstore/).
9
+ - The **snap** kind fills one Snap Segment per Input with hashed identifiers,
10
+ through Snap's Marketing API.
11
+
12
+ ddc pins this package by hash in a fully locked `requirements.txt` and runs
13
+ `dq_export_connector.runner.main` in the task's Python environment. It is
14
+ published to PyPI, since the compiled graph installs it from there.
15
+
16
+ - `dq_export_connector.runner`: the entry point. Reads `/input/config.json`,
17
+ `/input/credentials.json` and any platform secret under
18
+ `/input/platform_secrets/`, sets up logging, dispatches on the Connector Kind
19
+ and the action, then writes what the action reports.
20
+ - `dq_export_connector.errors`: the codes the worker reports, and
21
+ `ExportConnectorError`, which stops a run with one. Codes are named for the
22
+ situation, not the kind, so any kind can report them.
23
+ - `dq_export_connector.report`: collects a run's error, warnings and receipt
24
+ while it runs, and cuts each message to ddc's 1,000 characters once redacted.
25
+ - `dq_export_connector.redact`: keeps every value from the sealed half, and
26
+ URL query strings, out of log lines and result messages. For the ad
27
+ platforms it also masks tokens, `key=secret` pairs, JWTs and SHA-256 hex.
28
+ - `dq_export_connector.datasets`: how an Input's dataset maps to files (a
29
+ stored ZIP, or one raw file).
30
+ - `dq_export_connector.bucket`: the bucket kind.
31
+ - `dq_export_connector.audience`: what the ad-platform kinds share: HTTPS to an
32
+ allowlist with retries by idempotency class, OAuth, identifier
33
+ normalisation, and the per-Input sync flow.
34
+ - `dq_export_connector.snap`: the snap kind.
35
+ - `dq_export_connector._models`: pydantic models generated from ddc's JSON
36
+ schemas, so the config the worker reads and the report and validation
37
+ result it writes match ddc's Rust types. Regenerate them with
38
+ `scripts/codegen-models.sh` after the types change and
39
+ `decentriq_dcr_compiler` has been rebuilt; a test fails while they are
40
+ stale.
41
+
42
+ ```sh
43
+ uv run pytest # unit tests, against obstore's in-memory store and a fake Snap API
44
+ uv run pytest -m live # against real buckets and Snap, credentials from the environment
45
+ uv run mypy dq_export_connector tests scripts
46
+ ```
47
+
48
+ ## Snap
49
+
50
+ A Snap connector's config names the ad account and, per Input, a Segment, the
51
+ identifier type its lines hold and a Merge Mode. ddc validates it. The
52
+ credentials are the refresh token of the Snap user who consented; Decentriq's
53
+ Snap app is the `export_connector_snap_app` platform secret
54
+ (`{"clientId", "clientSecret"}`).
55
+
56
+ A run looks each Segment up by name in the ad account and creates it when
57
+ there is none, marked `Managed by Decentriq`. It writes into a same-named
58
+ Segment whoever made it, with a `SEGMENT_NOT_MANAGED` warning when Decentriq
59
+ didn't. ADD adds the Input's values; REPLACE empties the Segment first, so it
60
+ is briefly empty. A run stops at the first Input that fails. When the failure
61
+ came after the Segment changed, the error says so; a rerun is safe in both
62
+ modes. Don't run one connector twice at the same time.
63
+
64
+ An Input is one file of values, or a stored ZIP holding one: one value per
65
+ line, UTF-8, optional BOM, LF or CRLF, surrounding double quotes removed,
66
+ empty lines skipped, no header.
67
+
68
+ ### Identifiers
69
+
70
+ | Type | Normalisation before SHA-256 | Snap schema |
71
+ |---|---|---|
72
+ | `EMAIL` | trim, lowercase; exactly one `@` with text on both sides | `EMAIL_SHA256` |
73
+ | `PHONE` | drop a `(0)` right after the country code (`+44 (0)20…`, `+44-(0)20…`), keep digits (any script's, as ASCII; drops `+`), drop a leading `00`; 8–15 digits, not starting with `0` | `PHONE_SHA256` |
74
+ | `IDFA`, `GAID` | UUID form with hyphens, lowercased | `MOBILE_AD_ID_SHA256` |
75
+ | `*_SHA256` | must be 64 hex characters; lowercased, otherwise unchanged | as above |
76
+
77
+ A pre-hashed value only matches if it was hashed from the same form: for
78
+ `PHONE_SHA256`, the digits with country code and no `+` (`41791234567`).
79
+
80
+ Up to 25% invalid rows gives an `INVALID_ROWS` warning; more fails the run
81
+ before the Segment changes. An empty Input gives an `EMPTY_DATASET` warning
82
+ and leaves its Segment as it was, in both modes.
83
+
84
+ The receipt counts invalid rows by reason (`counts.invalidReasons`, and in the
85
+ warning or error message), never with the values themselves:
86
+
87
+ | Reason | Meaning |
88
+ |---|---|
89
+ | `EMAIL_NO_AT_SIGN`, `EMAIL_MULTIPLE_AT_SIGNS` | not exactly one `@` |
90
+ | `EMAIL_EMPTY_LOCAL_PART`, `EMAIL_EMPTY_DOMAIN` | nothing before or after the `@` |
91
+ | `PHONE_NO_DIGITS` | no digits at all |
92
+ | `PHONE_NATIONAL_FORMAT` | starts with `0` after dropping `00`, i.e. no country code |
93
+ | `PHONE_TOO_SHORT`, `PHONE_TOO_LONG` | fewer than 8 or more than 15 digits |
94
+ | `NOT_A_MOBILE_AD_ID` | not a UUID with hyphens |
95
+ | `NOT_SHA256_HEX` | a `*_SHA256` value that isn't 64 hex characters |
96
+ | `NOT_UTF8` | the line isn't valid UTF-8 |
97
+ | `CONTROL_CHARACTERS` | the value holds control characters or a byte order mark, usually because the file is UTF-16 |
98
+
99
+ ### Testing against Snap
100
+
101
+ The local files are gitignored in this directory:
102
+
103
+ - `platform_secrets.json`: `{"export_connector_snap_app": {"clientId": …, "clientSecret": …}}`, the dev app.
104
+ - `credentials.json`: written by the consent CLI.
105
+ - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "grantExpiresAt": null, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
106
+
107
+ 1. Consent, as the Snap user who has a role on the test ad account. The
108
+ redirect URI must be an https URI registered on the app; only the URL the
109
+ browser lands on matters.
110
+
111
+ ```sh
112
+ uv run python scripts/consent.py snap --platform-secrets platform_secrets.json \
113
+ --redirect-uri "$REDIRECT_URI" --out credentials.json --config config.json
114
+ ```
115
+ 2. Run:
116
+
117
+ ```sh
118
+ mkdir -p local/inputs && printf 'a@example.com\nb@example.com\n' > local/inputs/segA
119
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
120
+ --platform-secrets platform_secrets.json --mode validate
121
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
122
+ --platform-secrets platform_secrets.json
123
+ ```
124
+ 3. Live tests, including the check that Snap doesn't rotate refresh tokens:
125
+
126
+ ```sh
127
+ DQ_EXPORT_LIVE_SNAP_DIR=$PWD uv run pytest -m live -s tests/test_live_snap.py
128
+ ```
129
+
130
+ ## Releasing
131
+
132
+ Bump the version with `uv version <version> --no-sync`, which also updates
133
+ `uv.lock`, commit, and push a `dq-export-connector-v<version>` tag on that
134
+ commit; the `Publish dq-export-connector to PyPI` workflow tests, builds and
135
+ uploads it. Use `.devN` versions while developing; PyPI releases can't be replaced.
136
+ ddc then pins the new version, as
137
+ [ddc's export worker README](../../dcr-compiler/ddc/src/archv2/data_room/export_connector/README.md)
138
+ describes.
@@ -52,6 +52,19 @@ class BucketExportCredentials(
52
52
  ]
53
53
 
54
54
 
55
+ class SnapExportCredentials(BaseModel):
56
+ model_config = ConfigDict(
57
+ populate_by_name=True,
58
+ )
59
+ refresh_token: Annotated[
60
+ str,
61
+ Field(
62
+ alias='refreshToken',
63
+ description="The refresh token of the Snap user who consented. Snap doesn't rotate it.",
64
+ ),
65
+ ]
66
+
67
+
55
68
  class ExportConnectorCredentials1(BaseModel):
56
69
  model_config = ConfigDict(
57
70
  populate_by_name=True,
@@ -60,9 +73,19 @@ class ExportConnectorCredentials1(BaseModel):
60
73
  type: Literal['bucket']
61
74
 
62
75
 
63
- class ExportConnectorCredentials(RootModel[ExportConnectorCredentials1]):
76
+ class ExportConnectorCredentials2(BaseModel):
77
+ model_config = ConfigDict(
78
+ populate_by_name=True,
79
+ )
80
+ credentials: SnapExportCredentials
81
+ type: Literal['snap']
82
+
83
+
84
+ class ExportConnectorCredentials(
85
+ RootModel[ExportConnectorCredentials1 | ExportConnectorCredentials2]
86
+ ):
64
87
  root: Annotated[
65
- ExportConnectorCredentials1,
88
+ ExportConnectorCredentials1 | ExportConnectorCredentials2,
66
89
  Field(
67
90
  description='Keyed by Connector Kind, in step with [`ExportConnectorKind`]. The worker\nreads it at `/input/credentials.json`.',
68
91
  title='ExportConnectorCredentials',
@@ -3,9 +3,11 @@
3
3
 
4
4
  from __future__ import annotations
5
5
 
6
+ from enum import Enum
6
7
  from typing import Annotated, Literal
7
8
 
8
9
  from pydantic import BaseModel, ConfigDict, Field, RootModel
10
+ from typing_extensions import TypeAliasType
9
11
 
10
12
 
11
13
  class BucketConnection1(BaseModel):
@@ -80,6 +82,70 @@ class ExportTotals(BaseModel):
80
82
  ] = None
81
83
 
82
84
 
85
+ class MergeMode(Enum):
86
+ add = 'ADD'
87
+ replace = 'REPLACE'
88
+
89
+
90
+ InvalidReasonsAdditionalProperty = TypeAliasType(
91
+ "InvalidReasonsAdditionalProperty", Annotated[int, Field(ge=0)]
92
+ )
93
+
94
+
95
+ class SegmentCounts(BaseModel):
96
+ model_config = ConfigDict(
97
+ populate_by_name=True,
98
+ )
99
+ invalid: Annotated[int, Field(ge=0)]
100
+ invalid_reasons: Annotated[
101
+ dict[str, InvalidReasonsAdditionalProperty],
102
+ Field(
103
+ alias='invalidReasons',
104
+ description='Invalid rows per reason, such as `EMAIL_NO_AT_SIGN`.',
105
+ ),
106
+ ]
107
+ rejected_by_platform: Annotated[
108
+ int | None,
109
+ Field(
110
+ alias='rejectedByPlatform',
111
+ description="`None` where the platform doesn't say.",
112
+ ge=0,
113
+ ),
114
+ ] = None
115
+ rows: Annotated[
116
+ int, Field(description='Non-empty lines read from the Input.', ge=0)
117
+ ]
118
+ submitted: Annotated[
119
+ int,
120
+ Field(
121
+ description='Values sent to the platform, also from an Input that failed partway.',
122
+ ge=0,
123
+ ),
124
+ ]
125
+ valid: Annotated[int, Field(ge=0)]
126
+
127
+
128
+ class SegmentTotals(BaseModel):
129
+ model_config = ConfigDict(
130
+ populate_by_name=True,
131
+ )
132
+ invalid: Annotated[int, Field(ge=0)]
133
+ rows: Annotated[int, Field(ge=0)]
134
+ submitted: Annotated[int, Field(ge=0)]
135
+ valid: Annotated[int, Field(ge=0)]
136
+
137
+
138
+ class SnapSegmentStatus(BaseModel):
139
+ model_config = ConfigDict(
140
+ populate_by_name=True,
141
+ )
142
+ approximate_number_users: Annotated[
143
+ int | None, Field(alias='approximateNumberUsers', ge=0)
144
+ ] = None
145
+ targetable_status: Annotated[str | None, Field(alias='targetableStatus')] = None
146
+ upload_status: Annotated[str | None, Field(alias='uploadStatus')] = None
147
+
148
+
83
149
  class BucketInputReceipt(BaseModel):
84
150
  model_config = ConfigDict(
85
151
  populate_by_name=True,
@@ -113,8 +179,61 @@ class ExportReceiptV01(BaseModel):
113
179
  type: Literal['BUCKET']
114
180
 
115
181
 
116
- class ExportReceiptV0(RootModel[ExportReceiptV01]):
117
- root: ExportReceiptV01
182
+ class SnapInputReceipt(BaseModel):
183
+ model_config = ConfigDict(
184
+ populate_by_name=True,
185
+ )
186
+ counts: SegmentCounts
187
+ created: Annotated[bool, Field(description='Whether this run created the Segment.')]
188
+ leaf_id: Annotated[str, Field(alias='leafId')]
189
+ merge_mode: Annotated[MergeMode, Field(alias='mergeMode')]
190
+ segment_id: Annotated[
191
+ str | None,
192
+ Field(
193
+ alias='segmentId',
194
+ description='`None` until the run found or created the Segment.',
195
+ ),
196
+ ] = None
197
+ segment_name: Annotated[str, Field(alias='segmentName')]
198
+ segment_status: Annotated[
199
+ SnapSegmentStatus | None,
200
+ Field(
201
+ alias='segmentStatus',
202
+ description='The Segment as Snap reported it after the upload.',
203
+ ),
204
+ ] = None
205
+
206
+
207
+ class BucketExportReceiptV0(BaseModel):
208
+ model_config = ConfigDict(
209
+ populate_by_name=True,
210
+ )
211
+ connection: Annotated[
212
+ BucketConnection, Field(description='Where the run exported to.')
213
+ ]
214
+ export_prefix: Annotated[
215
+ str | None,
216
+ Field(
217
+ alias='exportPrefix',
218
+ description='The export prefix with its date tokens filled; `None` without one.',
219
+ ),
220
+ ] = None
221
+ inputs: list[BucketInputReceipt]
222
+ totals: ExportTotals
223
+
224
+
225
+ class ExportReceiptV02(BaseModel):
226
+ model_config = ConfigDict(
227
+ populate_by_name=True,
228
+ )
229
+ ad_account_id: Annotated[str, Field(alias='adAccountId')]
230
+ inputs: list[SnapInputReceipt]
231
+ totals: SegmentTotals
232
+ type: Literal['SNAP']
233
+
234
+
235
+ class ExportReceiptV0(RootModel[ExportReceiptV01 | ExportReceiptV02]):
236
+ root: ExportReceiptV01 | ExportReceiptV02
118
237
 
119
238
 
120
239
  class ExportReportV0(BaseModel):
@@ -134,6 +253,15 @@ class ExportReportV0(BaseModel):
134
253
  warnings: list[ExportMessage]
135
254
 
136
255
 
256
+ class SnapExportReceiptV0(BaseModel):
257
+ model_config = ConfigDict(
258
+ populate_by_name=True,
259
+ )
260
+ ad_account_id: Annotated[str, Field(alias='adAccountId')]
261
+ inputs: list[SnapInputReceipt]
262
+ totals: SegmentTotals
263
+
264
+
137
265
  class ExportReport1(BaseModel):
138
266
  model_config = ConfigDict(
139
267
  populate_by_name=True,
@@ -160,21 +288,3 @@ class ExportReport(RootModel[ExportReport1]):
160
288
  title='ExportReport',
161
289
  ),
162
290
  ]
163
-
164
-
165
- class BucketExportReceiptV0(BaseModel):
166
- model_config = ConfigDict(
167
- populate_by_name=True,
168
- )
169
- connection: Annotated[
170
- BucketConnection, Field(description='Where the run exported to.')
171
- ]
172
- export_prefix: Annotated[
173
- str | None,
174
- Field(
175
- alias='exportPrefix',
176
- description='The export prefix with its date tokens filled; `None` without one.',
177
- ),
178
- ] = None
179
- inputs: list[BucketInputReceipt]
180
- totals: ExportTotals
@@ -3,6 +3,7 @@
3
3
 
4
4
  from __future__ import annotations
5
5
 
6
+ from enum import Enum
6
7
  from typing import Annotated, Literal
7
8
 
8
9
  from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, RootModel
@@ -72,10 +73,6 @@ class ExportConnectorKind1(BaseModel):
72
73
  type: Literal['bucket']
73
74
 
74
75
 
75
- class ExportConnectorKind(RootModel[ExportConnectorKind1]):
76
- root: ExportConnectorKind1
77
-
78
-
79
76
  class ExportParams1(BaseModel):
80
77
  model_config = ConfigDict(
81
78
  populate_by_name=True,
@@ -83,8 +80,31 @@ class ExportParams1(BaseModel):
83
80
  type: Literal['bucket']
84
81
 
85
82
 
86
- class ExportParams(RootModel[ExportParams1]):
87
- root: ExportParams1
83
+ class ExportParams2(BaseModel):
84
+ model_config = ConfigDict(
85
+ populate_by_name=True,
86
+ )
87
+ type: Literal['snap']
88
+
89
+
90
+ class ExportParams(RootModel[ExportParams1 | ExportParams2]):
91
+ root: ExportParams1 | ExportParams2
92
+
93
+
94
+ class IdentifierType(Enum):
95
+ email = 'EMAIL'
96
+ email_sha256 = 'EMAIL_SHA256'
97
+ phone = 'PHONE'
98
+ phone_sha256 = 'PHONE_SHA256'
99
+ idfa = 'IDFA'
100
+ idfa_sha256 = 'IDFA_SHA256'
101
+ gaid = 'GAID'
102
+ gaid_sha256 = 'GAID_SHA256'
103
+
104
+
105
+ class MergeMode(Enum):
106
+ add = 'ADD'
107
+ replace = 'REPLACE'
88
108
 
89
109
 
90
110
  class ProvisionedPolicy(BaseModel):
@@ -105,6 +125,30 @@ class ProvisionedPolicy(BaseModel):
105
125
  ]
106
126
 
107
127
 
128
+ class SnapInput(BaseModel):
129
+ model_config = ConfigDict(
130
+ populate_by_name=True,
131
+ )
132
+ identifier_type: Annotated[IdentifierType, Field(alias='identifierType')]
133
+ leaf_id: Annotated[str, Field(alias='leafId')]
134
+ merge_mode: Annotated[MergeMode, Field(alias='mergeMode')]
135
+ retention_days: Annotated[
136
+ int | None,
137
+ Field(
138
+ alias='retentionDays',
139
+ description='Applied when the Segment is created.',
140
+ ge=0,
141
+ ),
142
+ ] = None
143
+ segment_name: Annotated[
144
+ str,
145
+ Field(
146
+ alias='segmentName',
147
+ description='The Segment is found by this name in the ad account, or created.',
148
+ ),
149
+ ]
150
+
151
+
108
152
  class ValidateConnectionParams1(BaseModel):
109
153
  model_config = ConfigDict(
110
154
  populate_by_name=True,
@@ -112,8 +156,17 @@ class ValidateConnectionParams1(BaseModel):
112
156
  type: Literal['bucket']
113
157
 
114
158
 
115
- class ValidateConnectionParams(RootModel[ValidateConnectionParams1]):
116
- root: ValidateConnectionParams1
159
+ class ValidateConnectionParams2(BaseModel):
160
+ model_config = ConfigDict(
161
+ populate_by_name=True,
162
+ )
163
+ type: Literal['snap']
164
+
165
+
166
+ class ValidateConnectionParams(
167
+ RootModel[ValidateConnectionParams1 | ValidateConnectionParams2]
168
+ ):
169
+ root: ValidateConnectionParams1 | ValidateConnectionParams2
117
170
 
118
171
 
119
172
  class BucketExportConfig(BaseModel):
@@ -174,6 +227,45 @@ class ExportConnectorDcrComputeAction(
174
227
  ]
175
228
 
176
229
 
230
+ class ExportConnectorKind2(BaseModel):
231
+ model_config = ConfigDict(
232
+ populate_by_name=True,
233
+ )
234
+ ad_account_id: Annotated[
235
+ str, Field(alias='adAccountId', description='A canonical, lowercase UUID.')
236
+ ]
237
+ grant_expires_at: Annotated[
238
+ str | None,
239
+ Field(
240
+ alias='grantExpiresAt',
241
+ description='RFC 3339. When the grant behind the credentials expires; runs warn as\nit nears.',
242
+ ),
243
+ ] = None
244
+ inputs: list[SnapInput]
245
+ type: Literal['snap']
246
+
247
+
248
+ class ExportConnectorKind(RootModel[ExportConnectorKind1 | ExportConnectorKind2]):
249
+ root: ExportConnectorKind1 | ExportConnectorKind2
250
+
251
+
252
+ class SnapExportConfig(BaseModel):
253
+ model_config = ConfigDict(
254
+ populate_by_name=True,
255
+ )
256
+ ad_account_id: Annotated[
257
+ str, Field(alias='adAccountId', description='A canonical, lowercase UUID.')
258
+ ]
259
+ grant_expires_at: Annotated[
260
+ str | None,
261
+ Field(
262
+ alias='grantExpiresAt',
263
+ description='RFC 3339. When the grant behind the credentials expires; runs warn as\nit nears.',
264
+ ),
265
+ ] = None
266
+ inputs: list[SnapInput]
267
+
268
+
177
269
  class ExportWorkerConfig(BaseModel):
178
270
  model_config = ConfigDict(
179
271
  populate_by_name=True,