peaq-os-sdk 0.0.2__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 (84) hide show
  1. peaq_os_sdk-0.0.2/LICENSE +201 -0
  2. peaq_os_sdk-0.0.2/PKG-INFO +229 -0
  3. peaq_os_sdk-0.0.2/README.md +202 -0
  4. peaq_os_sdk-0.0.2/pyproject.toml +68 -0
  5. peaq_os_sdk-0.0.2/setup.cfg +4 -0
  6. peaq_os_sdk-0.0.2/src/peaq_os_sdk/__init__.py +115 -0
  7. peaq_os_sdk-0.0.2/src/peaq_os_sdk/abis/BatchPrecompile.json +112 -0
  8. peaq_os_sdk-0.0.2/src/peaq_os_sdk/abis/DIDPrecompile.json +249 -0
  9. peaq_os_sdk-0.0.2/src/peaq_os_sdk/abis/EventRegistry.json +717 -0
  10. peaq_os_sdk-0.0.2/src/peaq_os_sdk/abis/IdentityRegistry.json +1403 -0
  11. peaq_os_sdk-0.0.2/src/peaq_os_sdk/abis/IdentityStaking.json +543 -0
  12. peaq_os_sdk-0.0.2/src/peaq_os_sdk/abis/MachineAccountFactory.json +182 -0
  13. peaq_os_sdk-0.0.2/src/peaq_os_sdk/abis/MachineNFT.json +935 -0
  14. peaq_os_sdk-0.0.2/src/peaq_os_sdk/abis/MachineNFTAdapter.json +1133 -0
  15. peaq_os_sdk-0.0.2/src/peaq_os_sdk/abis/MachineNFTBase.json +1592 -0
  16. peaq_os_sdk-0.0.2/src/peaq_os_sdk/abis/MachineSmartAccount.json +427 -0
  17. peaq_os_sdk-0.0.2/src/peaq_os_sdk/abis/__init__.py +27 -0
  18. peaq_os_sdk-0.0.2/src/peaq_os_sdk/bridge/__init__.py +8 -0
  19. peaq_os_sdk-0.0.2/src/peaq_os_sdk/bridge/_internal/__init__.py +1 -0
  20. peaq_os_sdk-0.0.2/src/peaq_os_sdk/bridge/_internal/send_param.py +55 -0
  21. peaq_os_sdk-0.0.2/src/peaq_os_sdk/bridge/_internal/validate_params.py +174 -0
  22. peaq_os_sdk-0.0.2/src/peaq_os_sdk/bridge/bridge_nft.py +141 -0
  23. peaq_os_sdk-0.0.2/src/peaq_os_sdk/bridge/quote_send.py +72 -0
  24. peaq_os_sdk-0.0.2/src/peaq_os_sdk/bridge/wait_for_bridge_arrival.py +172 -0
  25. peaq_os_sdk-0.0.2/src/peaq_os_sdk/client.py +983 -0
  26. peaq_os_sdk-0.0.2/src/peaq_os_sdk/constants.py +127 -0
  27. peaq_os_sdk-0.0.2/src/peaq_os_sdk/did/__init__.py +11 -0
  28. peaq_os_sdk-0.0.2/src/peaq_os_sdk/did/batch_did_write.py +99 -0
  29. peaq_os_sdk-0.0.2/src/peaq_os_sdk/did/did_precompile.py +142 -0
  30. peaq_os_sdk-0.0.2/src/peaq_os_sdk/did/write_machine_did_attributes.py +108 -0
  31. peaq_os_sdk-0.0.2/src/peaq_os_sdk/did/write_proxy_did_attributes.py +70 -0
  32. peaq_os_sdk-0.0.2/src/peaq_os_sdk/events/__init__.py +12 -0
  33. peaq_os_sdk-0.0.2/src/peaq_os_sdk/events/batch_submit_events.py +257 -0
  34. peaq_os_sdk-0.0.2/src/peaq_os_sdk/events/rate_limit_tracker.py +95 -0
  35. peaq_os_sdk-0.0.2/src/peaq_os_sdk/events/submit_event.py +161 -0
  36. peaq_os_sdk-0.0.2/src/peaq_os_sdk/exceptions/__init__.py +19 -0
  37. peaq_os_sdk-0.0.2/src/peaq_os_sdk/exceptions/api_error.py +15 -0
  38. peaq_os_sdk-0.0.2/src/peaq_os_sdk/exceptions/base.py +28 -0
  39. peaq_os_sdk-0.0.2/src/peaq_os_sdk/exceptions/rate_limit_exceeded.py +37 -0
  40. peaq_os_sdk-0.0.2/src/peaq_os_sdk/exceptions/rpc_error.py +17 -0
  41. peaq_os_sdk-0.0.2/src/peaq_os_sdk/exceptions/validation_error.py +41 -0
  42. peaq_os_sdk-0.0.2/src/peaq_os_sdk/exceptions/value_cap_exceeded.py +24 -0
  43. peaq_os_sdk-0.0.2/src/peaq_os_sdk/nft/__init__.py +11 -0
  44. peaq_os_sdk-0.0.2/src/peaq_os_sdk/nft/mint_nft.py +80 -0
  45. peaq_os_sdk-0.0.2/src/peaq_os_sdk/nft/token_id_of.py +46 -0
  46. peaq_os_sdk-0.0.2/src/peaq_os_sdk/query/__init__.py +9 -0
  47. peaq_os_sdk-0.0.2/src/peaq_os_sdk/query/_internal/__init__.py +1 -0
  48. peaq_os_sdk-0.0.2/src/peaq_os_sdk/query/_internal/did.py +30 -0
  49. peaq_os_sdk-0.0.2/src/peaq_os_sdk/query/_internal/error_codes.py +26 -0
  50. peaq_os_sdk-0.0.2/src/peaq_os_sdk/query/_internal/response_guards.py +333 -0
  51. peaq_os_sdk-0.0.2/src/peaq_os_sdk/query/http_client.py +155 -0
  52. peaq_os_sdk-0.0.2/src/peaq_os_sdk/query/query_machine.py +53 -0
  53. peaq_os_sdk-0.0.2/src/peaq_os_sdk/query/query_mcr.py +48 -0
  54. peaq_os_sdk-0.0.2/src/peaq_os_sdk/query/query_operator_machines.py +55 -0
  55. peaq_os_sdk-0.0.2/src/peaq_os_sdk/registration/__init__.py +25 -0
  56. peaq_os_sdk-0.0.2/src/peaq_os_sdk/registration/faucet.py +245 -0
  57. peaq_os_sdk-0.0.2/src/peaq_os_sdk/registration/fund_from_gas_station.py +193 -0
  58. peaq_os_sdk-0.0.2/src/peaq_os_sdk/registration/register_for.py +81 -0
  59. peaq_os_sdk-0.0.2/src/peaq_os_sdk/registration/register_machine.py +63 -0
  60. peaq_os_sdk-0.0.2/src/peaq_os_sdk/smart_account/__init__.py +8 -0
  61. peaq_os_sdk-0.0.2/src/peaq_os_sdk/smart_account/_internal/__init__.py +1 -0
  62. peaq_os_sdk-0.0.2/src/peaq_os_sdk/smart_account/_internal/validate_params.py +128 -0
  63. peaq_os_sdk-0.0.2/src/peaq_os_sdk/smart_account/deploy_smart_account.py +116 -0
  64. peaq_os_sdk-0.0.2/src/peaq_os_sdk/smart_account/get_smart_account_address.py +91 -0
  65. peaq_os_sdk-0.0.2/src/peaq_os_sdk/types/__init__.py +43 -0
  66. peaq_os_sdk-0.0.2/src/peaq_os_sdk/types/client.py +64 -0
  67. peaq_os_sdk-0.0.2/src/peaq_os_sdk/types/did.py +21 -0
  68. peaq_os_sdk-0.0.2/src/peaq_os_sdk/types/events.py +94 -0
  69. peaq_os_sdk-0.0.2/src/peaq_os_sdk/types/identity.py +8 -0
  70. peaq_os_sdk-0.0.2/src/peaq_os_sdk/types/primitives.py +11 -0
  71. peaq_os_sdk-0.0.2/src/peaq_os_sdk/types/queries.py +113 -0
  72. peaq_os_sdk-0.0.2/src/peaq_os_sdk/utils/__init__.py +13 -0
  73. peaq_os_sdk-0.0.2/src/peaq_os_sdk/utils/data_hash.py +21 -0
  74. peaq_os_sdk-0.0.2/src/peaq_os_sdk/utils/error_resolver.py +81 -0
  75. peaq_os_sdk-0.0.2/src/peaq_os_sdk/utils/transaction.py +175 -0
  76. peaq_os_sdk-0.0.2/src/peaq_os_sdk/validation/__init__.py +15 -0
  77. peaq_os_sdk-0.0.2/src/peaq_os_sdk/validation/did_attributes.py +151 -0
  78. peaq_os_sdk-0.0.2/src/peaq_os_sdk/validation/operational_limits.py +87 -0
  79. peaq_os_sdk-0.0.2/src/peaq_os_sdk/validation/submit_event.py +103 -0
  80. peaq_os_sdk-0.0.2/src/peaq_os_sdk.egg-info/PKG-INFO +229 -0
  81. peaq_os_sdk-0.0.2/src/peaq_os_sdk.egg-info/SOURCES.txt +82 -0
  82. peaq_os_sdk-0.0.2/src/peaq_os_sdk.egg-info/dependency_links.txt +1 -0
  83. peaq_os_sdk-0.0.2/src/peaq_os_sdk.egg-info/requires.txt +12 -0
  84. peaq_os_sdk-0.0.2/src/peaq_os_sdk.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,229 @@
1
+ Metadata-Version: 2.4
2
+ Name: peaq-os-sdk
3
+ Version: 0.0.2
4
+ Summary: Python SDK for peaqOS, the operating system for the machine economy — on-chain identity, credit rating, and omnichain infrastructure for robots and machines.
5
+ Author-email: peaqOS <info@peaq.xyz>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://www.peaq.xyz
8
+ Project-URL: Documentation, https://docs.peaq.xyz
9
+ Project-URL: Repository, https://github.com/peaqnetwork/peaq-os-sdk-py
10
+ Project-URL: Issues, https://github.com/peaqnetwork/peaq-os-sdk-py/issues
11
+ Keywords: peaq,peaqos,peaq-os,machine-economy,depin,robotics,ai-agents,blockchain,omnichain,peaqid,did,machine-nft,machine-tokenization,machine-credit-rating,mcr,sdk,python
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: web3>=6.0
16
+ Requires-Dist: eth-account
17
+ Requires-Dist: requests
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest; extra == "dev"
20
+ Requires-Dist: pytest-cov; extra == "dev"
21
+ Requires-Dist: mypy; extra == "dev"
22
+ Requires-Dist: ruff; extra == "dev"
23
+ Requires-Dist: black; extra == "dev"
24
+ Requires-Dist: build; extra == "dev"
25
+ Requires-Dist: flake8; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # peaq-os-sdk
29
+
30
+ Python SDK for the peaqOS protocol. Provides a typed wrapper around the peaq on-chain capabilities so integrators can onboard machines, submit events, mint NFTs, and query credit ratings without writing raw `web3.py` boilerplate.
31
+
32
+ ---
33
+
34
+ ## Install
35
+
36
+ ```bash
37
+ pip install peaq-os-sdk
38
+ ```
39
+
40
+ Dependencies installed automatically: `web3`, `eth-account`, `requests`.
41
+
42
+ ### Requirements
43
+
44
+ - Python `>= 3.10`
45
+ - A peaq RPC endpoint
46
+ - A funded wallet for the proxy operator (or for the machine itself, in self-managed mode)
47
+
48
+ ---
49
+
50
+ ## Quick start
51
+
52
+ ```python
53
+ from peaq_os_sdk import PeaqosClient
54
+
55
+ client = PeaqosClient(
56
+ rpc_url="https://peaq.api.onfinality.io/public",
57
+ private_key="0xYOUR_PRIVATE_KEY",
58
+ identity_registry="0x...",
59
+ identity_staking="0x...",
60
+ event_registry="0x...",
61
+ machine_nft="0x...",
62
+ did_registry="0x...",
63
+ batch_precompile="0x...",
64
+ )
65
+
66
+ print("signer address:", client.address)
67
+ ```
68
+
69
+ `PeaqosClient` is the only class consumers instantiate. All feature methods hang off it. The constructor performs synchronous validation and wires up the underlying `Web3` provider + signing account — no network I/O is issued at construction time.
70
+
71
+ [**Read More here >>**](docs/01_QUICK_START.md)
72
+
73
+ ---
74
+
75
+ ## MCR queries
76
+
77
+ Three read-only methods talk to the off-chain MCR API server at `client.api_url` (override via the `api_url` kwarg or `PEAQOS_MCR_API_URL`; defaults to `http://127.0.0.1:8000`). All three validate the DID prefix (`did:peaq:0x…`) locally and share a single `requests.Session` for connection pooling.
78
+
79
+ | Method | HTTP endpoint | Returns |
80
+ |---|---|---|
81
+ | `client.query_mcr(did)` | `GET /mcr/{did}` | `MCRResponse` TypedDict |
82
+ | `client.query_machine(did)` | `GET /machine/{did}` | `MachineProfileResponse` (NFT metadata JSON v1.0 as `dict[str, Any]`) |
83
+ | `client.query_operator_machines(did)` | `GET /operator/{did}/machines` | `OperatorMachinesResponse` |
84
+
85
+ `MCRResponse`:
86
+
87
+ ```python
88
+ {
89
+ "did": str,
90
+ "machine_id": int,
91
+ "mcr_score": int | None, # 0–100, None if Provisioned
92
+ "mcr": str, # "AAA" | "AA" | "A" | "BBB" | "BB" | "B" | "NR" | "Provisioned"
93
+ "bond_status": str, # "bonded" | "unbonded"
94
+ "negative_flag": bool, # active negative event flag
95
+ "event_count": int,
96
+ "revenue_event_count": int,
97
+ "activity_event_count": int,
98
+ "revenue_trend": str, # "up" | "stable" | "down" | "insufficient"
99
+ "total_revenue": float,
100
+ "average_revenue_per_event": float,
101
+ "last_updated": int | None,
102
+ }
103
+ ```
104
+
105
+ `OperatorMachinesResponse` carries `operator_did`, a `machines` list of `{did, machine_id, mcr_score, mcr, negative_flag}` entries, and a `pagination` object. `MachineProfileResponse` returns structured NFT metadata with a validated `peaqos` sub-object. Every failure path is an `ApiError` with a stable `.code` (`NOT_FOUND`, `SERVICE_UNAVAILABLE`, `SERVER_ERROR`, `HTTP_ERROR`, `BAD_RESPONSE`, `TIMEOUT`, `NETWORK_ERROR`). See [docs/03_QUERIES.md](docs/03_QUERIES.md) for the full endpoint and error reference.
106
+
107
+ ---
108
+
109
+ ## Smart account deployment
110
+
111
+ ERC-4337 smart accounts are provisioned via the `MachineAccountFactory` contract using CREATE2 — the deployed address is deterministic from `(owner, machine, daily_limit, salt)`, so the same tuple always resolves to the same address.
112
+
113
+ | Method | On-chain | Returns |
114
+ |---|---|---|
115
+ | `client.get_smart_account_address(owner, machine, daily_limit, salt)` | view call — no gas | predicted address |
116
+ | `client.deploy_smart_account(owner, machine, daily_limit, salt)` | `createAccount` tx | deployed address |
117
+
118
+ Because CREATE2 is deterministic, `predicted == deployed` for the same inputs — callers can preview the address, pre-fund it, or display it in a UI before paying gas. Configure the factory address via the optional `machine_account_factory` kwarg on `PeaqosClient` or the `MACHINE_ACCOUNT_FACTORY_ADDRESS` env var. See [docs/04_SMART_ACCOUNTS.md](docs/04_SMART_ACCOUNTS.md) for parameter rules and receipt-decoding error codes.
119
+
120
+ ---
121
+
122
+ ## Cross-chain NFT bridging
123
+
124
+ Machine NFTs move between peaq and Base over LayerZero v2. Two chains are recognised today; direction is inferred from the `source` / `destination` arguments.
125
+
126
+ | Chain | `SUPPORTED_CHAINS` id | `LAYERZERO_EIDS` |
127
+ |---|---|---|
128
+ | `"peaq"` | 3338 | **30302** |
129
+ | `"base"` | 8453 | **30184** |
130
+
131
+ | Direction | Source contract | Effect | `dstEid` |
132
+ |---|---|---|---|
133
+ | peaq → base | `MachineNFTAdapter` on peaq | NFT locked on peaq, minted on Base | `30184` |
134
+ | base → peaq | `MachineNFTBase` on Base | NFT burned on Base, unlocked on peaq | `30302` |
135
+
136
+ `client.bridge_nft(...)` estimates the LayerZero messaging fee via `quoteSend` **before** broadcasting and attaches that fee as `msg.value` on the actual `send` transaction so the message is correctly paid for. `PeaqosClient.wait_for_bridge_arrival(...)` is a static method (no client instance needed) that polls `MachineNFT.ownerOf(token_id)` on the destination every 10 seconds and returns `True` on arrival or `False` at timeout (default 300 s). See [docs/05_BRIDGE.md](docs/05_BRIDGE.md) for the full walkthrough including `options` handling, Base-source setup, and the complete error-code table.
137
+
138
+ ---
139
+
140
+ ## Documentation
141
+
142
+ Per-feature deep-dives live under [`docs/`](docs/):
143
+
144
+ - [**Quick Start**](docs/01_QUICK_START.md) — client initialization, configuration, environment variables, types, exception classes, validation, utilities, and constants.
145
+ - [**Machine identity & registration**](docs/02_REGISTRATION.md) — faucet 2FA enrollment, gas-station funding, self-managed and proxy-managed registration. Includes the full faucet error reference and the on-chain revert mapping.
146
+ - [**MCR queries**](docs/03_QUERIES.md) — `query_mcr`, `query_machine`, `query_operator_machines`, response shapes, rating tiers, and the full HTTP error-code table.
147
+ - [**Smart account deployment**](docs/04_SMART_ACCOUNTS.md) — `deploy_smart_account` and `get_smart_account_address`, CREATE2 determinism, parameter rules, and receipt-decoding error codes.
148
+ - [**Cross-chain NFT bridging**](docs/05_BRIDGE.md) — `bridge_nft` direction handling (peaq ↔ Base via LayerZero v2), supported chain IDs and LayerZero EIDs, LayerZero fee estimation, and `wait_for_bridge_arrival` polling semantics.
149
+ - [**Event submission**](docs/03_EVENTS.md) — single and batch event submission, pipeline details, limits, hashing, metadata mode, and rate-limiting behavior.
150
+ - [**NFT minting & DID attributes**](docs/04_NFT_AND_DID.md) — minting machine NFTs, querying token IDs, writing machine and proxy DID attributes atomically via the Batch precompile. Covers attribute key reference, data visibility options, and the atomic batch guarantee.
151
+
152
+ Additional capability docs (events, queries, smart accounts, bridging) will be added as the SDK grows.
153
+
154
+ ---
155
+
156
+ ## Development
157
+
158
+ ```bash
159
+ git clone https://github.com/peaqnetwork/peaq-os-sdk-py.git
160
+ cd peaq-os-sdk-py
161
+ python3 -m venv .venv
162
+ source .venv/bin/activate
163
+ pip install -e ".[dev]"
164
+ ```
165
+
166
+ ### Activate `.env` for Testing
167
+ ```
168
+ set -a
169
+ source .env
170
+ set +a
171
+ ```
172
+
173
+ ### Quality gates
174
+
175
+ ```bash
176
+ ruff check src tests # lint — zero warnings
177
+ black --check src tests # formatting
178
+ mypy src # strict type check, zero errors
179
+ pytest -q # all green
180
+ ```
181
+
182
+ The unit tests are hermetic — they mock `Web3` and `requests.Session` with handwritten stubs and never touch the network.
183
+
184
+ ### Optional integration tests
185
+
186
+ The repo ships an opt-in suite that talks to a real peaq devnet. It is skipped silently in normal `pytest -q` and only runs when the required environment variables are supplied.
187
+
188
+ **Registration integration suite** ([`tests/integration/registration/test_registration_integration.py`](tests/integration/registration/test_registration_integration.py)) — three end-to-end tests for the self-managed flow, proxy-managed flow, and double-registration revert. Gated behind the `integration` marker plus seven environment variables:
189
+
190
+ ```bash
191
+ PEAQOS_RPC_URL=https://peaq.api.onfinality.io/public
192
+ PEAQOS_PRIVATE_KEY=0xYOUR_FUNDED_TREASURY_KEY
193
+ IDENTITY_REGISTRY_ADDRESS=0xYOUR_DEPLOYED_REGISTRY_ADDRESS
194
+ IDENTITY_STAKING_ADDRESS=0xYOUR_DEPLOYED_STAKING_ADDRESS
195
+ PEAQOS_OWNER_ADDRESS=5GrwvaEF...
196
+ PEAQOS_FAUCET_URL=https://depinstation.peaq.xyz
197
+ PEAQOS_2FA_CODE=123456
198
+ ```
199
+
200
+ ```bash
201
+ pytest -m integration tests/integration/
202
+ ```
203
+
204
+ See [docs/02_REGISTRATION.md → Integration tests](docs/02_REGISTRATION.md#integration-tests) for the full breakdown of what each test verifies and operational warnings.
205
+
206
+ **NFT & DID integration suite** ([`tests/integration/nft_did/test_nft_and_did_integration.py`](tests/integration/nft_did/test_nft_and_did_integration.py)) — end-to-end tests for the full NFT lifecycle, atomic DID writes, and atomicity guarantee verification (all-or-nothing batch semantics). Includes 7 tests across minting, token queries, machine DID attributes, proxy DID attributes, and atomic revert scenarios. Requires the same env vars as the registration suite plus:
207
+
208
+ ```bash
209
+ EVENT_REGISTRY_ADDRESS=0x...
210
+ MACHINE_NFT_ADDRESS=0x...
211
+ DID_REGISTRY_ADDRESS=0x0000000000000000000000000000000000000800
212
+ BATCH_PRECOMPILE_ADDRESS=0x0000000000000000000000000000000000000805
213
+ ```
214
+
215
+ See [docs/04_NFT_AND_DID.md](docs/04_NFT_AND_DID.md) for the full breakdown.
216
+
217
+ `PEAQOS_PRIVATE_KEY` must match `^0x[0-9a-fA-F]{64}$`. **Never commit a real key. Never run the suite against mainnet.**
218
+
219
+ ### Build
220
+
221
+ ```bash
222
+ python -m build
223
+ ```
224
+
225
+ Produces `dist/peaq_os_sdk-<version>-py3-none-any.whl` and `dist/peaq_os_sdk-<version>.tar.gz` for downstream testing.
226
+
227
+ ## License
228
+
229
+ See [LICENSE](./LICENSE) for details.
@@ -0,0 +1,202 @@
1
+ # peaq-os-sdk
2
+
3
+ Python SDK for the peaqOS protocol. Provides a typed wrapper around the peaq on-chain capabilities so integrators can onboard machines, submit events, mint NFTs, and query credit ratings without writing raw `web3.py` boilerplate.
4
+
5
+ ---
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install peaq-os-sdk
11
+ ```
12
+
13
+ Dependencies installed automatically: `web3`, `eth-account`, `requests`.
14
+
15
+ ### Requirements
16
+
17
+ - Python `>= 3.10`
18
+ - A peaq RPC endpoint
19
+ - A funded wallet for the proxy operator (or for the machine itself, in self-managed mode)
20
+
21
+ ---
22
+
23
+ ## Quick start
24
+
25
+ ```python
26
+ from peaq_os_sdk import PeaqosClient
27
+
28
+ client = PeaqosClient(
29
+ rpc_url="https://peaq.api.onfinality.io/public",
30
+ private_key="0xYOUR_PRIVATE_KEY",
31
+ identity_registry="0x...",
32
+ identity_staking="0x...",
33
+ event_registry="0x...",
34
+ machine_nft="0x...",
35
+ did_registry="0x...",
36
+ batch_precompile="0x...",
37
+ )
38
+
39
+ print("signer address:", client.address)
40
+ ```
41
+
42
+ `PeaqosClient` is the only class consumers instantiate. All feature methods hang off it. The constructor performs synchronous validation and wires up the underlying `Web3` provider + signing account — no network I/O is issued at construction time.
43
+
44
+ [**Read More here >>**](docs/01_QUICK_START.md)
45
+
46
+ ---
47
+
48
+ ## MCR queries
49
+
50
+ Three read-only methods talk to the off-chain MCR API server at `client.api_url` (override via the `api_url` kwarg or `PEAQOS_MCR_API_URL`; defaults to `http://127.0.0.1:8000`). All three validate the DID prefix (`did:peaq:0x…`) locally and share a single `requests.Session` for connection pooling.
51
+
52
+ | Method | HTTP endpoint | Returns |
53
+ |---|---|---|
54
+ | `client.query_mcr(did)` | `GET /mcr/{did}` | `MCRResponse` TypedDict |
55
+ | `client.query_machine(did)` | `GET /machine/{did}` | `MachineProfileResponse` (NFT metadata JSON v1.0 as `dict[str, Any]`) |
56
+ | `client.query_operator_machines(did)` | `GET /operator/{did}/machines` | `OperatorMachinesResponse` |
57
+
58
+ `MCRResponse`:
59
+
60
+ ```python
61
+ {
62
+ "did": str,
63
+ "machine_id": int,
64
+ "mcr_score": int | None, # 0–100, None if Provisioned
65
+ "mcr": str, # "AAA" | "AA" | "A" | "BBB" | "BB" | "B" | "NR" | "Provisioned"
66
+ "bond_status": str, # "bonded" | "unbonded"
67
+ "negative_flag": bool, # active negative event flag
68
+ "event_count": int,
69
+ "revenue_event_count": int,
70
+ "activity_event_count": int,
71
+ "revenue_trend": str, # "up" | "stable" | "down" | "insufficient"
72
+ "total_revenue": float,
73
+ "average_revenue_per_event": float,
74
+ "last_updated": int | None,
75
+ }
76
+ ```
77
+
78
+ `OperatorMachinesResponse` carries `operator_did`, a `machines` list of `{did, machine_id, mcr_score, mcr, negative_flag}` entries, and a `pagination` object. `MachineProfileResponse` returns structured NFT metadata with a validated `peaqos` sub-object. Every failure path is an `ApiError` with a stable `.code` (`NOT_FOUND`, `SERVICE_UNAVAILABLE`, `SERVER_ERROR`, `HTTP_ERROR`, `BAD_RESPONSE`, `TIMEOUT`, `NETWORK_ERROR`). See [docs/03_QUERIES.md](docs/03_QUERIES.md) for the full endpoint and error reference.
79
+
80
+ ---
81
+
82
+ ## Smart account deployment
83
+
84
+ ERC-4337 smart accounts are provisioned via the `MachineAccountFactory` contract using CREATE2 — the deployed address is deterministic from `(owner, machine, daily_limit, salt)`, so the same tuple always resolves to the same address.
85
+
86
+ | Method | On-chain | Returns |
87
+ |---|---|---|
88
+ | `client.get_smart_account_address(owner, machine, daily_limit, salt)` | view call — no gas | predicted address |
89
+ | `client.deploy_smart_account(owner, machine, daily_limit, salt)` | `createAccount` tx | deployed address |
90
+
91
+ Because CREATE2 is deterministic, `predicted == deployed` for the same inputs — callers can preview the address, pre-fund it, or display it in a UI before paying gas. Configure the factory address via the optional `machine_account_factory` kwarg on `PeaqosClient` or the `MACHINE_ACCOUNT_FACTORY_ADDRESS` env var. See [docs/04_SMART_ACCOUNTS.md](docs/04_SMART_ACCOUNTS.md) for parameter rules and receipt-decoding error codes.
92
+
93
+ ---
94
+
95
+ ## Cross-chain NFT bridging
96
+
97
+ Machine NFTs move between peaq and Base over LayerZero v2. Two chains are recognised today; direction is inferred from the `source` / `destination` arguments.
98
+
99
+ | Chain | `SUPPORTED_CHAINS` id | `LAYERZERO_EIDS` |
100
+ |---|---|---|
101
+ | `"peaq"` | 3338 | **30302** |
102
+ | `"base"` | 8453 | **30184** |
103
+
104
+ | Direction | Source contract | Effect | `dstEid` |
105
+ |---|---|---|---|
106
+ | peaq → base | `MachineNFTAdapter` on peaq | NFT locked on peaq, minted on Base | `30184` |
107
+ | base → peaq | `MachineNFTBase` on Base | NFT burned on Base, unlocked on peaq | `30302` |
108
+
109
+ `client.bridge_nft(...)` estimates the LayerZero messaging fee via `quoteSend` **before** broadcasting and attaches that fee as `msg.value` on the actual `send` transaction so the message is correctly paid for. `PeaqosClient.wait_for_bridge_arrival(...)` is a static method (no client instance needed) that polls `MachineNFT.ownerOf(token_id)` on the destination every 10 seconds and returns `True` on arrival or `False` at timeout (default 300 s). See [docs/05_BRIDGE.md](docs/05_BRIDGE.md) for the full walkthrough including `options` handling, Base-source setup, and the complete error-code table.
110
+
111
+ ---
112
+
113
+ ## Documentation
114
+
115
+ Per-feature deep-dives live under [`docs/`](docs/):
116
+
117
+ - [**Quick Start**](docs/01_QUICK_START.md) — client initialization, configuration, environment variables, types, exception classes, validation, utilities, and constants.
118
+ - [**Machine identity & registration**](docs/02_REGISTRATION.md) — faucet 2FA enrollment, gas-station funding, self-managed and proxy-managed registration. Includes the full faucet error reference and the on-chain revert mapping.
119
+ - [**MCR queries**](docs/03_QUERIES.md) — `query_mcr`, `query_machine`, `query_operator_machines`, response shapes, rating tiers, and the full HTTP error-code table.
120
+ - [**Smart account deployment**](docs/04_SMART_ACCOUNTS.md) — `deploy_smart_account` and `get_smart_account_address`, CREATE2 determinism, parameter rules, and receipt-decoding error codes.
121
+ - [**Cross-chain NFT bridging**](docs/05_BRIDGE.md) — `bridge_nft` direction handling (peaq ↔ Base via LayerZero v2), supported chain IDs and LayerZero EIDs, LayerZero fee estimation, and `wait_for_bridge_arrival` polling semantics.
122
+ - [**Event submission**](docs/03_EVENTS.md) — single and batch event submission, pipeline details, limits, hashing, metadata mode, and rate-limiting behavior.
123
+ - [**NFT minting & DID attributes**](docs/04_NFT_AND_DID.md) — minting machine NFTs, querying token IDs, writing machine and proxy DID attributes atomically via the Batch precompile. Covers attribute key reference, data visibility options, and the atomic batch guarantee.
124
+
125
+ Additional capability docs (events, queries, smart accounts, bridging) will be added as the SDK grows.
126
+
127
+ ---
128
+
129
+ ## Development
130
+
131
+ ```bash
132
+ git clone https://github.com/peaqnetwork/peaq-os-sdk-py.git
133
+ cd peaq-os-sdk-py
134
+ python3 -m venv .venv
135
+ source .venv/bin/activate
136
+ pip install -e ".[dev]"
137
+ ```
138
+
139
+ ### Activate `.env` for Testing
140
+ ```
141
+ set -a
142
+ source .env
143
+ set +a
144
+ ```
145
+
146
+ ### Quality gates
147
+
148
+ ```bash
149
+ ruff check src tests # lint — zero warnings
150
+ black --check src tests # formatting
151
+ mypy src # strict type check, zero errors
152
+ pytest -q # all green
153
+ ```
154
+
155
+ The unit tests are hermetic — they mock `Web3` and `requests.Session` with handwritten stubs and never touch the network.
156
+
157
+ ### Optional integration tests
158
+
159
+ The repo ships an opt-in suite that talks to a real peaq devnet. It is skipped silently in normal `pytest -q` and only runs when the required environment variables are supplied.
160
+
161
+ **Registration integration suite** ([`tests/integration/registration/test_registration_integration.py`](tests/integration/registration/test_registration_integration.py)) — three end-to-end tests for the self-managed flow, proxy-managed flow, and double-registration revert. Gated behind the `integration` marker plus seven environment variables:
162
+
163
+ ```bash
164
+ PEAQOS_RPC_URL=https://peaq.api.onfinality.io/public
165
+ PEAQOS_PRIVATE_KEY=0xYOUR_FUNDED_TREASURY_KEY
166
+ IDENTITY_REGISTRY_ADDRESS=0xYOUR_DEPLOYED_REGISTRY_ADDRESS
167
+ IDENTITY_STAKING_ADDRESS=0xYOUR_DEPLOYED_STAKING_ADDRESS
168
+ PEAQOS_OWNER_ADDRESS=5GrwvaEF...
169
+ PEAQOS_FAUCET_URL=https://depinstation.peaq.xyz
170
+ PEAQOS_2FA_CODE=123456
171
+ ```
172
+
173
+ ```bash
174
+ pytest -m integration tests/integration/
175
+ ```
176
+
177
+ See [docs/02_REGISTRATION.md → Integration tests](docs/02_REGISTRATION.md#integration-tests) for the full breakdown of what each test verifies and operational warnings.
178
+
179
+ **NFT & DID integration suite** ([`tests/integration/nft_did/test_nft_and_did_integration.py`](tests/integration/nft_did/test_nft_and_did_integration.py)) — end-to-end tests for the full NFT lifecycle, atomic DID writes, and atomicity guarantee verification (all-or-nothing batch semantics). Includes 7 tests across minting, token queries, machine DID attributes, proxy DID attributes, and atomic revert scenarios. Requires the same env vars as the registration suite plus:
180
+
181
+ ```bash
182
+ EVENT_REGISTRY_ADDRESS=0x...
183
+ MACHINE_NFT_ADDRESS=0x...
184
+ DID_REGISTRY_ADDRESS=0x0000000000000000000000000000000000000800
185
+ BATCH_PRECOMPILE_ADDRESS=0x0000000000000000000000000000000000000805
186
+ ```
187
+
188
+ See [docs/04_NFT_AND_DID.md](docs/04_NFT_AND_DID.md) for the full breakdown.
189
+
190
+ `PEAQOS_PRIVATE_KEY` must match `^0x[0-9a-fA-F]{64}$`. **Never commit a real key. Never run the suite against mainnet.**
191
+
192
+ ### Build
193
+
194
+ ```bash
195
+ python -m build
196
+ ```
197
+
198
+ Produces `dist/peaq_os_sdk-<version>-py3-none-any.whl` and `dist/peaq_os_sdk-<version>.tar.gz` for downstream testing.
199
+
200
+ ## License
201
+
202
+ See [LICENSE](./LICENSE) for details.