py-datacents 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Derek Stearns
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.
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: py-datacents
3
+ Version: 0.1.0
4
+ Summary: A library for Home Assistant to help people make money from their data.
5
+ Author: Derek Stearns
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/djstearns/py-datacents
8
+ Project-URL: Repository, https://github.com/djstearns/py-datacents
9
+ Project-URL: Issues, https://github.com/djstearns/py-datacents/issues
10
+ Keywords: home-assistant,snowflake,snowpipe-streaming,circle,usdc
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: circle-developer-controlled-wallets<10,>=9.6
22
+ Requires-Dist: snowpipe-streaming<2,>=1.8
23
+ Dynamic: license-file
24
+
25
+ # py-datacents
26
+
27
+ A Python library for Home Assistant integrations that stream privacy-conscious
28
+ data-product events to Snowflake and submit contributor USDC payouts through
29
+ Circle developer-controlled wallets.
30
+
31
+ ## Install
32
+
33
+ ```shell
34
+ pip install py-datacents
35
+ ```
36
+
37
+ ## Stream data to Snowflake
38
+
39
+ Create a Snowpipe Streaming pipe/table for each dataset and configure Snowflake
40
+ key-pair authentication. Pass the database, schema names, and connection
41
+ properties to the publisher; credentials are not read from source files or
42
+ logged.
43
+
44
+ ```python
45
+ from datetime import datetime, timezone
46
+ from uuid import uuid4
47
+
48
+ from datacents import SnowpipeConfig, SnowpipeStreamingPublisher
49
+
50
+ publisher = SnowpipeStreamingPublisher(
51
+ SnowpipeConfig(
52
+ database="DATACENTS",
53
+ schemas={
54
+ "utilities": "UTILITIES",
55
+ "content": "CONTENT",
56
+ "cybersecurity": "CYBERSECURITY",
57
+ },
58
+ properties={
59
+ "account": "your_account",
60
+ "user": "DATACENTS_INGEST",
61
+ "private_key_file": "/run/secrets/snowflake_key.p8",
62
+ "url": "https://your_account.snowflakecomputing.com",
63
+ "role": "DATACENTS_INGEST_ROLE",
64
+ },
65
+ )
66
+ )
67
+
68
+ electric_event = {
69
+ "event_id": str(uuid4()),
70
+ "contributor_id": "hashed_contributor_id",
71
+ "timestamp": datetime.now(timezone.utc).isoformat(),
72
+ "reading_type": "instantaneous",
73
+ "power_w": 500.0,
74
+ "energy_kwh": 0.5,
75
+ "location": {
76
+ "country": "US",
77
+ "state_province": "CA",
78
+ "postal_code_prefix": "941",
79
+ "timezone": "America/Los_Angeles",
80
+ },
81
+ "device_metadata": {
82
+ "device_type": "smart_meter",
83
+ "manufacturer": "example",
84
+ },
85
+ }
86
+
87
+ publisher.publish_batch(
88
+ "utilities.electric_usage_events",
89
+ [electric_event],
90
+ )
91
+ publisher.close()
92
+ ```
93
+
94
+ Supported dataset identifiers and maximum batch sizes are:
95
+
96
+ | Dataset | Maximum events per batch |
97
+ | --- | ---: |
98
+ | `utilities.electric_usage_events` | 1000 |
99
+ | `utilities.water_usage_events` | 1000 |
100
+ | `content.media_playback_events` | 100 |
101
+ | `content.voice_assistant_interactions` | 100 |
102
+ | `content.content_discovery_events` | 100 |
103
+ | `cybersecurity.network_security_events` | 500 |
104
+ | `cybersecurity.iot_device_security_events` | 500 |
105
+ | `cybersecurity.authentication_events` | 500 |
106
+ | `cybersecurity.malware_threat_events` | 500 |
107
+
108
+ Nested event fields are flattened to the columns described by the data-product
109
+ specifications. Each batch call waits for Snowflake's durable acknowledgement;
110
+ keep the source events until the call succeeds so the caller can decide how to
111
+ recover from a failure or timeout.
112
+
113
+ ## Submit Circle USDC payouts
114
+
115
+ Use Circle TESTNET credentials for development. Configure a separate client,
116
+ wallet set, and credentials for each environment. The entity secret and API key
117
+ must come from a secret manager or the Home Assistant integration's protected
118
+ configuration; never expose them in frontend code or logs.
119
+
120
+ ```python
121
+ from datacents import CircleConfig, CirclePaymentsClient
122
+
123
+ payments = CirclePaymentsClient(
124
+ CircleConfig(
125
+ api_key="read from a secret store",
126
+ entity_secret="64 hexadecimal characters from a secret store",
127
+ environment="TESTNET",
128
+ blockchain="ARC-TESTNET",
129
+ token_address="the configured USDC token contract",
130
+ source_wallet_id="the platform payout wallet ID",
131
+ source_wallet_address="the platform payout wallet address",
132
+ )
133
+ )
134
+
135
+ payout = payments.transfer_usdc(
136
+ contributor_id="hashed_contributor_id",
137
+ destination_address="verified_contributor_address",
138
+ amount_atomic=5_000_000, # 5 USDC (six decimal places)
139
+ )
140
+ ```
141
+
142
+ Transfers use a fresh UUID v4 idempotency key and wait until Circle reports a
143
+ terminal state. Only `COMPLETE` is returned as a successful payout. A polling
144
+ timeout includes the transaction ID and idempotency key so the existing
145
+ transaction can be resumed rather than submitted again.
146
+
147
+ MAINNET transfers require an exact confirmation string from
148
+ `CirclePaymentsClient.mainnet_confirmation(...)` for the chain, token, source
149
+ wallet, destination, and amount. USDC amounts are integers in atomic units;
150
+ floating-point amounts are not accepted.
151
+
152
+ ## Development
153
+
154
+ Run the unit tests with:
155
+
156
+ ```shell
157
+ PYTHONPATH=src python -m unittest discover -s tests
158
+ ```
159
+
160
+ ## Publishing
161
+
162
+ The GitHub Actions workflow runs when changes reach `main`, including after a
163
+ PR merge. It builds and validates both distribution formats and runs the tests
164
+ on each push. It publishes to PyPI only when the version in `pyproject.toml`
165
+ increases from the previous `main` commit; version decreases fail the workflow.
166
+
167
+ Before the first release:
168
+
169
+ 1. In PyPI account settings, add a trusted publisher for project `py-datacents`,
170
+ owner `djstearns`, repository `py-datacents`, workflow `publish.yml`, and
171
+ GitHub environment `pypi`.
172
+ 2. Create the `pypi` environment in GitHub repository settings and configure
173
+ required reviewers for release approval.
174
+ 3. Increase the version in `pyproject.toml` in a release PR, merge it to
175
+ `main`, and approve the workflow deployment.
176
+
177
+ The workflow uses PyPI Trusted Publishing (OIDC); it does not require a stored
178
+ PyPI API token.
@@ -0,0 +1,154 @@
1
+ # py-datacents
2
+
3
+ A Python library for Home Assistant integrations that stream privacy-conscious
4
+ data-product events to Snowflake and submit contributor USDC payouts through
5
+ Circle developer-controlled wallets.
6
+
7
+ ## Install
8
+
9
+ ```shell
10
+ pip install py-datacents
11
+ ```
12
+
13
+ ## Stream data to Snowflake
14
+
15
+ Create a Snowpipe Streaming pipe/table for each dataset and configure Snowflake
16
+ key-pair authentication. Pass the database, schema names, and connection
17
+ properties to the publisher; credentials are not read from source files or
18
+ logged.
19
+
20
+ ```python
21
+ from datetime import datetime, timezone
22
+ from uuid import uuid4
23
+
24
+ from datacents import SnowpipeConfig, SnowpipeStreamingPublisher
25
+
26
+ publisher = SnowpipeStreamingPublisher(
27
+ SnowpipeConfig(
28
+ database="DATACENTS",
29
+ schemas={
30
+ "utilities": "UTILITIES",
31
+ "content": "CONTENT",
32
+ "cybersecurity": "CYBERSECURITY",
33
+ },
34
+ properties={
35
+ "account": "your_account",
36
+ "user": "DATACENTS_INGEST",
37
+ "private_key_file": "/run/secrets/snowflake_key.p8",
38
+ "url": "https://your_account.snowflakecomputing.com",
39
+ "role": "DATACENTS_INGEST_ROLE",
40
+ },
41
+ )
42
+ )
43
+
44
+ electric_event = {
45
+ "event_id": str(uuid4()),
46
+ "contributor_id": "hashed_contributor_id",
47
+ "timestamp": datetime.now(timezone.utc).isoformat(),
48
+ "reading_type": "instantaneous",
49
+ "power_w": 500.0,
50
+ "energy_kwh": 0.5,
51
+ "location": {
52
+ "country": "US",
53
+ "state_province": "CA",
54
+ "postal_code_prefix": "941",
55
+ "timezone": "America/Los_Angeles",
56
+ },
57
+ "device_metadata": {
58
+ "device_type": "smart_meter",
59
+ "manufacturer": "example",
60
+ },
61
+ }
62
+
63
+ publisher.publish_batch(
64
+ "utilities.electric_usage_events",
65
+ [electric_event],
66
+ )
67
+ publisher.close()
68
+ ```
69
+
70
+ Supported dataset identifiers and maximum batch sizes are:
71
+
72
+ | Dataset | Maximum events per batch |
73
+ | --- | ---: |
74
+ | `utilities.electric_usage_events` | 1000 |
75
+ | `utilities.water_usage_events` | 1000 |
76
+ | `content.media_playback_events` | 100 |
77
+ | `content.voice_assistant_interactions` | 100 |
78
+ | `content.content_discovery_events` | 100 |
79
+ | `cybersecurity.network_security_events` | 500 |
80
+ | `cybersecurity.iot_device_security_events` | 500 |
81
+ | `cybersecurity.authentication_events` | 500 |
82
+ | `cybersecurity.malware_threat_events` | 500 |
83
+
84
+ Nested event fields are flattened to the columns described by the data-product
85
+ specifications. Each batch call waits for Snowflake's durable acknowledgement;
86
+ keep the source events until the call succeeds so the caller can decide how to
87
+ recover from a failure or timeout.
88
+
89
+ ## Submit Circle USDC payouts
90
+
91
+ Use Circle TESTNET credentials for development. Configure a separate client,
92
+ wallet set, and credentials for each environment. The entity secret and API key
93
+ must come from a secret manager or the Home Assistant integration's protected
94
+ configuration; never expose them in frontend code or logs.
95
+
96
+ ```python
97
+ from datacents import CircleConfig, CirclePaymentsClient
98
+
99
+ payments = CirclePaymentsClient(
100
+ CircleConfig(
101
+ api_key="read from a secret store",
102
+ entity_secret="64 hexadecimal characters from a secret store",
103
+ environment="TESTNET",
104
+ blockchain="ARC-TESTNET",
105
+ token_address="the configured USDC token contract",
106
+ source_wallet_id="the platform payout wallet ID",
107
+ source_wallet_address="the platform payout wallet address",
108
+ )
109
+ )
110
+
111
+ payout = payments.transfer_usdc(
112
+ contributor_id="hashed_contributor_id",
113
+ destination_address="verified_contributor_address",
114
+ amount_atomic=5_000_000, # 5 USDC (six decimal places)
115
+ )
116
+ ```
117
+
118
+ Transfers use a fresh UUID v4 idempotency key and wait until Circle reports a
119
+ terminal state. Only `COMPLETE` is returned as a successful payout. A polling
120
+ timeout includes the transaction ID and idempotency key so the existing
121
+ transaction can be resumed rather than submitted again.
122
+
123
+ MAINNET transfers require an exact confirmation string from
124
+ `CirclePaymentsClient.mainnet_confirmation(...)` for the chain, token, source
125
+ wallet, destination, and amount. USDC amounts are integers in atomic units;
126
+ floating-point amounts are not accepted.
127
+
128
+ ## Development
129
+
130
+ Run the unit tests with:
131
+
132
+ ```shell
133
+ PYTHONPATH=src python -m unittest discover -s tests
134
+ ```
135
+
136
+ ## Publishing
137
+
138
+ The GitHub Actions workflow runs when changes reach `main`, including after a
139
+ PR merge. It builds and validates both distribution formats and runs the tests
140
+ on each push. It publishes to PyPI only when the version in `pyproject.toml`
141
+ increases from the previous `main` commit; version decreases fail the workflow.
142
+
143
+ Before the first release:
144
+
145
+ 1. In PyPI account settings, add a trusted publisher for project `py-datacents`,
146
+ owner `djstearns`, repository `py-datacents`, workflow `publish.yml`, and
147
+ GitHub environment `pypi`.
148
+ 2. Create the `pypi` environment in GitHub repository settings and configure
149
+ required reviewers for release approval.
150
+ 3. Increase the version in `pyproject.toml` in a release PR, merge it to
151
+ `main`, and approve the workflow deployment.
152
+
153
+ The workflow uses PyPI Trusted Publishing (OIDC); it does not require a stored
154
+ PyPI API token.
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "py-datacents"
7
+ version = "0.1.0"
8
+ description = "A library for Home Assistant to help people make money from their data."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11"
13
+ authors = [
14
+ { name = "Derek Stearns" },
15
+ ]
16
+ keywords = ["home-assistant", "snowflake", "snowpipe-streaming", "circle", "usdc"]
17
+ classifiers = [
18
+ "Development Status :: 3 - Alpha",
19
+ "Intended Audience :: Developers",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ ]
26
+ dependencies = [
27
+ "circle-developer-controlled-wallets>=9.6,<10",
28
+ "snowpipe-streaming>=1.8,<2",
29
+ ]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/djstearns/py-datacents"
33
+ Repository = "https://github.com/djstearns/py-datacents"
34
+ Issues = "https://github.com/djstearns/py-datacents/issues"
35
+
36
+ [tool.setuptools.packages.find]
37
+ where = ["src"]
38
+
39
+ [tool.uv.workspace]
40
+ members = [
41
+ "py-datacents",
42
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,25 @@
1
+ """Clients for publishing Datacents events and issuing Circle USDC payouts."""
2
+
3
+ from .circle import (
4
+ CircleConfig,
5
+ CirclePaymentsClient,
6
+ CirclePayout,
7
+ CirclePayoutError,
8
+ CirclePayoutTimeout,
9
+ )
10
+ from .events import DATASETS, EventValidationError, validate_and_flatten_batch
11
+ from .snowpipe import BatchReceipt, SnowpipeConfig, SnowpipeStreamingPublisher
12
+
13
+ __all__ = [
14
+ "BatchReceipt",
15
+ "CircleConfig",
16
+ "CirclePayout",
17
+ "CirclePayoutError",
18
+ "CirclePayoutTimeout",
19
+ "CirclePaymentsClient",
20
+ "DATASETS",
21
+ "EventValidationError",
22
+ "SnowpipeConfig",
23
+ "SnowpipeStreamingPublisher",
24
+ "validate_and_flatten_batch",
25
+ ]