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