synapse-filecoin-sdk 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.
Files changed (80) hide show
  1. synapse_filecoin_sdk-0.1.0/.github/workflows/publish-pypi.yml +51 -0
  2. synapse_filecoin_sdk-0.1.0/.gitignore +10 -0
  3. synapse_filecoin_sdk-0.1.0/LICENSE.md +228 -0
  4. synapse_filecoin_sdk-0.1.0/PKG-INFO +74 -0
  5. synapse_filecoin_sdk-0.1.0/QUICKSTART.md +272 -0
  6. synapse_filecoin_sdk-0.1.0/README.md +49 -0
  7. synapse_filecoin_sdk-0.1.0/demo.py +104 -0
  8. synapse_filecoin_sdk-0.1.0/get_usdfc.py +53 -0
  9. synapse_filecoin_sdk-0.1.0/pyproject.toml +48 -0
  10. synapse_filecoin_sdk-0.1.0/src/pynapse/__init__.py +6 -0
  11. synapse_filecoin_sdk-0.1.0/src/pynapse/_version.py +1 -0
  12. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/__init__.py +34 -0
  13. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/abi_registry.py +11 -0
  14. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/addresses.json +30 -0
  15. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/erc20_abi.json +92 -0
  16. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/errorsAbi.json +933 -0
  17. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/filecoinPayV1Abi.json +2424 -0
  18. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/filecoinWarmStorageServiceAbi.json +2363 -0
  19. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/filecoinWarmStorageServiceStateViewAbi.json +651 -0
  20. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/generated.py +35 -0
  21. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/payments_abi.json +205 -0
  22. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/pdpVerifierAbi.json +1266 -0
  23. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/providerIdSetAbi.json +161 -0
  24. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/serviceProviderRegistryAbi.json +1479 -0
  25. synapse_filecoin_sdk-0.1.0/src/pynapse/contracts/sessionKeyRegistryAbi.json +147 -0
  26. synapse_filecoin_sdk-0.1.0/src/pynapse/core/__init__.py +68 -0
  27. synapse_filecoin_sdk-0.1.0/src/pynapse/core/abis.py +25 -0
  28. synapse_filecoin_sdk-0.1.0/src/pynapse/core/chains.py +97 -0
  29. synapse_filecoin_sdk-0.1.0/src/pynapse/core/constants.py +27 -0
  30. synapse_filecoin_sdk-0.1.0/src/pynapse/core/errors.py +22 -0
  31. synapse_filecoin_sdk-0.1.0/src/pynapse/core/piece.py +263 -0
  32. synapse_filecoin_sdk-0.1.0/src/pynapse/core/rand.py +14 -0
  33. synapse_filecoin_sdk-0.1.0/src/pynapse/core/typed_data.py +320 -0
  34. synapse_filecoin_sdk-0.1.0/src/pynapse/core/utils.py +30 -0
  35. synapse_filecoin_sdk-0.1.0/src/pynapse/evm/__init__.py +3 -0
  36. synapse_filecoin_sdk-0.1.0/src/pynapse/evm/client.py +26 -0
  37. synapse_filecoin_sdk-0.1.0/src/pynapse/filbeam/__init__.py +3 -0
  38. synapse_filecoin_sdk-0.1.0/src/pynapse/filbeam/service.py +39 -0
  39. synapse_filecoin_sdk-0.1.0/src/pynapse/payments/__init__.py +17 -0
  40. synapse_filecoin_sdk-0.1.0/src/pynapse/payments/service.py +826 -0
  41. synapse_filecoin_sdk-0.1.0/src/pynapse/pdp/__init__.py +21 -0
  42. synapse_filecoin_sdk-0.1.0/src/pynapse/pdp/server.py +331 -0
  43. synapse_filecoin_sdk-0.1.0/src/pynapse/pdp/types.py +38 -0
  44. synapse_filecoin_sdk-0.1.0/src/pynapse/pdp/verifier.py +82 -0
  45. synapse_filecoin_sdk-0.1.0/src/pynapse/retriever/__init__.py +12 -0
  46. synapse_filecoin_sdk-0.1.0/src/pynapse/retriever/async_chain.py +227 -0
  47. synapse_filecoin_sdk-0.1.0/src/pynapse/retriever/chain.py +209 -0
  48. synapse_filecoin_sdk-0.1.0/src/pynapse/session/__init__.py +12 -0
  49. synapse_filecoin_sdk-0.1.0/src/pynapse/session/key.py +30 -0
  50. synapse_filecoin_sdk-0.1.0/src/pynapse/session/permissions.py +57 -0
  51. synapse_filecoin_sdk-0.1.0/src/pynapse/session/registry.py +90 -0
  52. synapse_filecoin_sdk-0.1.0/src/pynapse/sp_registry/__init__.py +11 -0
  53. synapse_filecoin_sdk-0.1.0/src/pynapse/sp_registry/capabilities.py +25 -0
  54. synapse_filecoin_sdk-0.1.0/src/pynapse/sp_registry/pdp_capabilities.py +102 -0
  55. synapse_filecoin_sdk-0.1.0/src/pynapse/sp_registry/service.py +446 -0
  56. synapse_filecoin_sdk-0.1.0/src/pynapse/sp_registry/types.py +52 -0
  57. synapse_filecoin_sdk-0.1.0/src/pynapse/storage/__init__.py +57 -0
  58. synapse_filecoin_sdk-0.1.0/src/pynapse/storage/async_context.py +682 -0
  59. synapse_filecoin_sdk-0.1.0/src/pynapse/storage/async_manager.py +757 -0
  60. synapse_filecoin_sdk-0.1.0/src/pynapse/storage/context.py +680 -0
  61. synapse_filecoin_sdk-0.1.0/src/pynapse/storage/manager.py +758 -0
  62. synapse_filecoin_sdk-0.1.0/src/pynapse/synapse.py +191 -0
  63. synapse_filecoin_sdk-0.1.0/src/pynapse/utils/__init__.py +25 -0
  64. synapse_filecoin_sdk-0.1.0/src/pynapse/utils/constants.py +25 -0
  65. synapse_filecoin_sdk-0.1.0/src/pynapse/utils/errors.py +3 -0
  66. synapse_filecoin_sdk-0.1.0/src/pynapse/utils/metadata.py +35 -0
  67. synapse_filecoin_sdk-0.1.0/src/pynapse/utils/piece_url.py +16 -0
  68. synapse_filecoin_sdk-0.1.0/src/pynapse/warm_storage/__init__.py +13 -0
  69. synapse_filecoin_sdk-0.1.0/src/pynapse/warm_storage/service.py +513 -0
  70. synapse_filecoin_sdk-0.1.0/tests/test_async_storage.py +355 -0
  71. synapse_filecoin_sdk-0.1.0/tests/test_chains.py +11 -0
  72. synapse_filecoin_sdk-0.1.0/tests/test_metadata.py +19 -0
  73. synapse_filecoin_sdk-0.1.0/tests/test_pdp_capabilities.py +24 -0
  74. synapse_filecoin_sdk-0.1.0/tests/test_piece.py +18 -0
  75. synapse_filecoin_sdk-0.1.0/tests/test_piece_url.py +17 -0
  76. synapse_filecoin_sdk-0.1.0/tests/test_rand.py +11 -0
  77. synapse_filecoin_sdk-0.1.0/tests/test_session_permissions.py +6 -0
  78. synapse_filecoin_sdk-0.1.0/tests/test_storage_manager.py +369 -0
  79. synapse_filecoin_sdk-0.1.0/tests/test_utils.py +15 -0
  80. synapse_filecoin_sdk-0.1.0/uv.lock +1728 -0
@@ -0,0 +1,51 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Check out repository
14
+ uses: actions/checkout@v4
15
+
16
+ - name: Set up Python
17
+ uses: actions/setup-python@v5
18
+ with:
19
+ python-version: "3.12"
20
+
21
+ - name: Build distribution artifacts
22
+ run: |
23
+ python -m pip install --upgrade pip
24
+ pip install build twine
25
+ python -m build
26
+ twine check dist/*
27
+
28
+ - name: Upload build artifacts
29
+ uses: actions/upload-artifact@v4
30
+ with:
31
+ name: python-package-distributions
32
+ path: dist/
33
+
34
+ publish:
35
+ needs: build
36
+ runs-on: ubuntu-latest
37
+ permissions:
38
+ id-token: write
39
+ environment:
40
+ name: pypi
41
+ steps:
42
+ - name: Download build artifacts
43
+ uses: actions/download-artifact@v4
44
+ with:
45
+ name: python-package-distributions
46
+ path: dist/
47
+
48
+ - name: Publish to PyPI
49
+ uses: pypa/gh-action-pypi-publish@release/v1
50
+ with:
51
+ packages-dir: dist/
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ *.pyd
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ .venv/
9
+ .pytest_cache/
10
+ .DS_Store
@@ -0,0 +1,228 @@
1
+ The contents of this repository are Copyright (c) corresponding authors and
2
+ contributors, licensed under the `Permissive License Stack` meaning either of:
3
+
4
+ - Apache-2.0 Software License: <https://www.apache.org/licenses/LICENSE-2.0>
5
+ - MIT Software License: <https://opensource.org/licenses/MIT>
6
+
7
+ You may not use the contents of this repository except in compliance
8
+ with one of the listed Licenses. For an extended clarification of the
9
+ intent behind the choice of Licensing please refer to
10
+ [Permissive License Stack](https://web.archive.org/web/20241127162157/https://www.protocol.ai/blog/announcing-the-permissive-license-stack/).
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the terms listed in this notice is distributed on
14
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15
+ either express or implied. See each License for the specific language
16
+ governing permissions and limitations under that License.
17
+
18
+ <!--- SPDX-License-Identifier: Apache-2.0 OR MIT -->
19
+ `SPDX-License-Identifier: Apache-2.0 OR MIT`
20
+
21
+ Verbatim copies of both licenses are included below:
22
+
23
+ <details><summary>Apache-2.0 Software License</summary>
24
+
25
+ ```text
26
+ Apache License
27
+ Version 2.0, January 2004
28
+ http://www.apache.org/licenses/
29
+
30
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
31
+
32
+ 1. Definitions.
33
+
34
+ "License" shall mean the terms and conditions for use, reproduction,
35
+ and distribution as defined by Sections 1 through 9 of this document.
36
+
37
+ "Licensor" shall mean the copyright owner or entity authorized by
38
+ the copyright owner that is granting the License.
39
+
40
+ "Legal Entity" shall mean the union of the acting entity and all
41
+ other entities that control, are controlled by, or are under common
42
+ control with that entity. For the purposes of this definition,
43
+ "control" means (i) the power, direct or indirect, to cause the
44
+ direction or management of such entity, whether by contract or
45
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
46
+ outstanding shares, or (iii) beneficial ownership of such entity.
47
+
48
+ "You" (or "Your") shall mean an individual or Legal Entity
49
+ exercising permissions granted by this License.
50
+
51
+ "Source" form shall mean the preferred form for making modifications,
52
+ including but not limited to software source code, documentation
53
+ source, and configuration files.
54
+
55
+ "Object" form shall mean any form resulting from mechanical
56
+ transformation or translation of a Source form, including but
57
+ not limited to compiled object code, generated documentation,
58
+ and conversions to other media types.
59
+
60
+ "Work" shall mean the work of authorship, whether in Source or
61
+ Object form, made available under the License, as indicated by a
62
+ copyright notice that is included in or attached to the work
63
+ (an example is provided in the Appendix below).
64
+
65
+ "Derivative Works" shall mean any work, whether in Source or Object
66
+ form, that is based on (or derived from) the Work and for which the
67
+ editorial revisions, annotations, elaborations, or other modifications
68
+ represent, as a whole, an original work of authorship. For the purposes
69
+ of this License, Derivative Works shall not include works that remain
70
+ separable from, or merely link (or bind by name) to the interfaces of,
71
+ the Work and Derivative Works thereof.
72
+
73
+ "Contribution" shall mean any work of authorship, including
74
+ the original version of the Work and any modifications or additions
75
+ to that Work or Derivative Works thereof, that is intentionally
76
+ submitted to Licensor for inclusion in the Work by the copyright owner
77
+ or by an individual or Legal Entity authorized to submit on behalf of
78
+ the copyright owner. For the purposes of this definition, "submitted"
79
+ means any form of electronic, verbal, or written communication sent
80
+ to the Licensor or its representatives, including but not limited to
81
+ communication on electronic mailing lists, source code control systems,
82
+ and issue tracking systems that are managed by, or on behalf of, the
83
+ Licensor for the purpose of discussing and improving the Work, but
84
+ excluding communication that is conspicuously marked or otherwise
85
+ designated in writing by the copyright owner as "Not a Contribution."
86
+
87
+ "Contributor" shall mean Licensor and any individual or Legal Entity
88
+ on behalf of whom a Contribution has been received by Licensor and
89
+ subsequently incorporated within the Work.
90
+
91
+ 2. Grant of Copyright License. Subject to the terms and conditions of
92
+ this License, each Contributor hereby grants to You a perpetual,
93
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
94
+ copyright license to reproduce, prepare Derivative Works of,
95
+ publicly display, publicly perform, sublicense, and distribute the
96
+ Work and such Derivative Works in Source or Object form.
97
+
98
+ 3. Grant of Patent License. Subject to the terms and conditions of
99
+ this License, each Contributor hereby grants to You a perpetual,
100
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
101
+ (except as stated in this section) patent license to make, have made,
102
+ use, offer to sell, sell, import, and otherwise transfer the Work,
103
+ where such license applies only to those patent claims licensable
104
+ by such Contributor that are necessarily infringed by their
105
+ Contribution(s) alone or by combination of their Contribution(s)
106
+ with the Work to which such Contribution(s) was submitted. If You
107
+ institute patent litigation against any entity (including a
108
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
109
+ or a Contribution incorporated within the Work constitutes direct
110
+ or contributory patent infringement, then any patent licenses
111
+ granted to You under this License for that Work shall terminate
112
+ as of the date such litigation is filed.
113
+
114
+ 4. Redistribution. You may reproduce and distribute copies of the
115
+ Work or Derivative Works thereof in any medium, with or without
116
+ modifications, and in Source or Object form, provided that You
117
+ meet the following conditions:
118
+
119
+ (a) You must give any other recipients of the Work or
120
+ Derivative Works a copy of this License; and
121
+
122
+ (b) You must cause any modified files to carry prominent notices
123
+ stating that You changed the files; and
124
+
125
+ (c) You must retain, in the Source form of any Derivative Works
126
+ that You distribute, all copyright, patent, trademark, and
127
+ attribution notices from the Source form of the Work,
128
+ excluding those notices that do not pertain to any part of
129
+ the Derivative Works; and
130
+
131
+ (d) If the Work includes a "NOTICE" text file as part of its
132
+ distribution, then any Derivative Works that You distribute must
133
+ include a readable copy of the attribution notices contained
134
+ within such NOTICE file, excluding those notices that do not
135
+ pertain to any part of the Derivative Works, in at least one
136
+ of the following places: within a NOTICE text file distributed
137
+ as part of the Derivative Works; within the Source form or
138
+ documentation, if provided along with the Derivative Works; or,
139
+ within a display generated by the Derivative Works, if and
140
+ wherever such third-party notices normally appear. The contents
141
+ of the NOTICE file are for informational purposes only and
142
+ do not modify the License. You may add Your own attribution
143
+ notices within Derivative Works that You distribute, alongside
144
+ or as an addendum to the NOTICE text from the Work, provided
145
+ that such additional attribution notices cannot be construed
146
+ as modifying the License.
147
+
148
+ You may add Your own copyright statement to Your modifications and
149
+ may provide additional or different license terms and conditions
150
+ for use, reproduction, or distribution of Your modifications, or
151
+ for any such Derivative Works as a whole, provided Your use,
152
+ reproduction, and distribution of the Work otherwise complies with
153
+ the conditions stated in this License.
154
+
155
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
156
+ any Contribution intentionally submitted for inclusion in the Work
157
+ by You to the Licensor shall be under the terms and conditions of
158
+ this License, without any additional terms or conditions.
159
+ Notwithstanding the above, nothing herein shall supersede or modify
160
+ the terms of any separate license agreement you may have executed
161
+ with Licensor regarding such Contributions.
162
+
163
+ 6. Trademarks. This License does not grant permission to use the trade
164
+ names, trademarks, service marks, or product names of the Licensor,
165
+ except as required for reasonable and customary use in describing the
166
+ origin of the Work and reproducing the content of the NOTICE file.
167
+
168
+ 7. Disclaimer of Warranty. Unless required by applicable law or
169
+ agreed to in writing, Licensor provides the Work (and each
170
+ Contributor provides its Contributions) on an "AS IS" BASIS,
171
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
172
+ implied, including, without limitation, any warranties or conditions
173
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
174
+ PARTICULAR PURPOSE. You are solely responsible for determining the
175
+ appropriateness of using or redistributing the Work and assume any
176
+ risks associated with Your exercise of permissions under this License.
177
+
178
+ 8. Limitation of Liability. In no event and under no legal theory,
179
+ whether in tort (including negligence), contract, or otherwise,
180
+ unless required by applicable law (such as deliberate and grossly
181
+ negligent acts) or agreed to in writing, shall any Contributor be
182
+ liable to You for damages, including any direct, indirect, special,
183
+ incidental, or consequential damages of any character arising as a
184
+ result of this License or out of the use or inability to use the
185
+ Work (including but not limited to damages for loss of goodwill,
186
+ work stoppage, computer failure or malfunction, or any and all
187
+ other commercial damages or losses), even if such Contributor
188
+ has been advised of the possibility of such damages.
189
+
190
+ 9. Accepting Warranty or Additional Liability. While redistributing
191
+ the Work or Derivative Works thereof, You may choose to offer,
192
+ and charge a fee for, acceptance of support, warranty, indemnity,
193
+ or other liability obligations and/or rights consistent with this
194
+ License. However, in accepting such obligations, You may act only
195
+ on Your own behalf and on Your sole responsibility, not on behalf
196
+ of any other Contributor, and only if You agree to indemnify,
197
+ defend, and hold each Contributor harmless for any liability
198
+ incurred by, or claims asserted against, such Contributor by reason
199
+ of your accepting any such warranty or additional liability.
200
+
201
+ END OF TERMS AND CONDITIONS
202
+ ```
203
+
204
+ </details>
205
+
206
+ <details><summary>MIT Software License</summary>
207
+
208
+ ```text
209
+ Permission is hereby granted, free of charge, to any person obtaining a copy
210
+ of this software and associated documentation files (the "Software"), to deal
211
+ in the Software without restriction, including without limitation the rights
212
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
213
+ copies of the Software, and to permit persons to whom the Software is
214
+ furnished to do so, subject to the following conditions:
215
+
216
+ The above copyright notice and this permission notice shall be included in
217
+ all copies or substantial portions of the Software.
218
+
219
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
220
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
221
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
222
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
223
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
224
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
225
+ THE SOFTWARE.
226
+ ```
227
+
228
+ </details>
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: synapse-filecoin-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for Filecoin Onchain Cloud (Synapse)
5
+ Project-URL: Homepage, https://github.com/FilOzone/synapse-sdk
6
+ Project-URL: Repository, https://github.com/FilOzone/synapse-sdk
7
+ Author: FilOz / Data Preservation Programs
8
+ License: Apache-2.0 OR MIT
9
+ License-File: LICENSE.md
10
+ Keywords: filecoin,pdp,storage,synapse,web3
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Python: >=3.11
18
+ Requires-Dist: httpx<0.28.0,>=0.25.0
19
+ Requires-Dist: multiformats<0.4.0,>=0.3.1
20
+ Requires-Dist: web3<7,>=6.0.0
21
+ Provides-Extra: test
22
+ Requires-Dist: pytest-asyncio<0.24,>=0.23.0; extra == 'test'
23
+ Requires-Dist: pytest<9,>=8.0.0; extra == 'test'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # Pynapse
27
+
28
+ Python SDK for Filecoin Onchain Cloud (Synapse).
29
+
30
+ This project mirrors the JS SDK in `FilOzone/synapse-sdk` and references the Go implementation in `data-preservation-programs/go-synapse` for parity.
31
+
32
+ ## Status
33
+
34
+ Work in progress. Parity is being implemented in incremental commits.
35
+
36
+ ## Install (dev)
37
+
38
+ ```bash
39
+ uv venv
40
+ uv pip install -e .[test]
41
+ ```
42
+
43
+ PyPI package name: `synapse-filecoin-sdk`
44
+ Python import: `pynapse`
45
+
46
+ ## Install (PyPI)
47
+
48
+ ```bash
49
+ pip install synapse-filecoin-sdk
50
+ ```
51
+
52
+ ## CommP / PieceCID
53
+
54
+ `pynapse` uses `stream-commp` from `go-fil-commp-hashhash` for PieceCID calculation.
55
+ Set `PYNAPSE_COMMP_HELPER` to override the helper path.
56
+
57
+ ## License
58
+
59
+ Dual-licensed under Apache-2.0 OR MIT. See `LICENSE.md`.
60
+
61
+ ## Publishing to PyPI
62
+
63
+ Publishing is automated via GitHub Actions in `.github/workflows/publish-pypi.yml`.
64
+
65
+ 1. In PyPI, create the project (or use an existing one) and configure a Trusted Publisher for this GitHub repository and workflow.
66
+ 2. In GitHub, optionally protect the `pypi` environment for manual approval.
67
+ 3. Tag a release and push the tag:
68
+
69
+ ```bash
70
+ git tag v0.1.1
71
+ git push origin v0.1.1
72
+ ```
73
+
74
+ The workflow builds the package, runs `twine check`, and publishes to PyPI via OIDC (no API token required).
@@ -0,0 +1,272 @@
1
+ # pynapse Quickstart - Upload to Filecoin Calibration Testnet
2
+
3
+ ## Prerequisites
4
+
5
+ 1. **Python 3.11+** with venv
6
+ 2. **Go** (to build stream-commp helper)
7
+ 3. **Test wallet** with:
8
+ - tFIL for gas (get from faucet: https://faucet.calibnet.chainsafe-fil.io/)
9
+ - USDFC for storage payments (get from https://stg.usdfc.net - mint by depositing tFIL)
10
+
11
+ ---
12
+
13
+ ## Step 1: Clone and Setup
14
+
15
+ ```bash
16
+ # Clone pynapse
17
+ git clone https://github.com/anjor/pynapse.git
18
+ cd pynapse
19
+
20
+ # Create venv and install from PyPI
21
+ python3 -m venv .venv
22
+ source .venv/bin/activate
23
+ pip install synapse-filecoin-sdk
24
+ ```
25
+
26
+ ## Step 2: Build stream-commp Helper
27
+
28
+ pynapse needs `stream-commp` to calculate Filecoin piece commitments:
29
+
30
+ ```bash
31
+ # Clone and build
32
+ cd /tmp
33
+ git clone https://github.com/filecoin-project/go-fil-commp-hashhash.git
34
+ cd go-fil-commp-hashhash/cmd/stream-commp
35
+ go build -o stream-commp .
36
+
37
+ # Install to your PATH (pick one)
38
+ sudo cp stream-commp /usr/local/bin/
39
+ # OR
40
+ cp stream-commp ~/go/bin/ # if ~/go/bin is in PATH
41
+ # OR
42
+ export PYNAPSE_COMMP_HELPER=/tmp/go-fil-commp-hashhash/cmd/stream-commp/stream-commp
43
+ ```
44
+
45
+ Verify: `stream-commp --help`
46
+
47
+ ## Step 3: Fund Your Wallet
48
+
49
+ You need:
50
+ - **tFIL** for gas (~1 tFIL is plenty)
51
+ - **USDFC** for storage payments (~10-50 USDFC for testing)
52
+
53
+ ### Get tFIL
54
+ Go to https://faucet.calibnet.chainsafe-fil.io/ and request tFIL for your wallet.
55
+
56
+ ### Get USDFC
57
+ 1. Go to https://stg.usdfc.net
58
+ 2. Connect wallet (Calibration network)
59
+ 3. Mint USDFC by depositing tFIL as collateral
60
+ 4. You'll get ~1.2x your deposit in USDFC
61
+
62
+ ## Step 4: Deposit USDFC & Approve Operator
63
+
64
+ Before uploading, you need to:
65
+ 1. Approve USDFC spending by the Payments contract
66
+ 2. Deposit USDFC to the Payments contract
67
+ 3. Approve the FWSS operator
68
+
69
+ Run this setup script (replace with your private key):
70
+
71
+ ```python
72
+ import asyncio
73
+ from web3 import AsyncWeb3
74
+
75
+ # CONFIG - Replace these!
76
+ PRIVATE_KEY = "0xYOUR_PRIVATE_KEY_HERE"
77
+ RPC_URL = "https://api.calibration.node.glif.io/rpc/v1"
78
+
79
+ # Contract addresses (Calibration)
80
+ USDFC = "0xb3042734b608a1B16e9e86B374A3f3e389B4cDf0"
81
+ PAYMENTS = "0x09a0fDc2723fAd1A7b8e3e00eE5DF73841df55a0"
82
+ FWSS = "0x02925630df557F957f70E112bA06e50965417CA0"
83
+
84
+ async def setup():
85
+ w3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider(RPC_URL))
86
+ acct = w3.eth.account.from_key(PRIVATE_KEY)
87
+ print(f"Wallet: {acct.address}")
88
+
89
+ # ERC20 ABI (minimal)
90
+ erc20_abi = [
91
+ {"inputs":[{"name":"spender","type":"address"},{"name":"amount","type":"uint256"}],"name":"approve","outputs":[{"type":"bool"}],"stateMutability":"nonpayable","type":"function"},
92
+ {"inputs":[{"name":"account","type":"address"}],"name":"balanceOf","outputs":[{"type":"uint256"}],"stateMutability":"view","type":"function"},
93
+ ]
94
+
95
+ # Payments ABI (minimal)
96
+ payments_abi = [
97
+ {"inputs":[{"name":"token","type":"address"},{"name":"to","type":"address"},{"name":"amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},
98
+ {"inputs":[{"name":"token","type":"address"},{"name":"account","type":"address"}],"name":"balanceOf","outputs":[{"type":"uint256"}],"stateMutability":"view","type":"function"},
99
+ {"inputs":[{"name":"operator","type":"address"},{"name":"approved","type":"bool"}],"name":"setOperatorApproval","outputs":[],"stateMutability":"nonpayable","type":"function"},
100
+ {"inputs":[{"name":"account","type":"address"},{"name":"operator","type":"address"}],"name":"isOperatorFor","outputs":[{"type":"bool"}],"stateMutability":"view","type":"function"},
101
+ ]
102
+
103
+ usdfc = w3.eth.contract(address=USDFC, abi=erc20_abi)
104
+ payments = w3.eth.contract(address=PAYMENTS, abi=payments_abi)
105
+
106
+ # Check balances
107
+ wallet_bal = await usdfc.functions.balanceOf(acct.address).call()
108
+ deposit_bal = await payments.functions.balanceOf(USDFC, acct.address).call()
109
+ print(f"USDFC in wallet: {wallet_bal / 1e18:.2f}")
110
+ print(f"USDFC deposited: {deposit_bal / 1e18:.2f}")
111
+
112
+ # 1. Approve USDFC spending (if needed)
113
+ if wallet_bal > 0:
114
+ print("\n1. Approving USDFC for Payments contract...")
115
+ tx = await usdfc.functions.approve(PAYMENTS, 2**256 - 1).build_transaction({
116
+ 'from': acct.address,
117
+ 'nonce': await w3.eth.get_transaction_count(acct.address),
118
+ 'gas': 100000,
119
+ 'maxFeePerGas': await w3.eth.gas_price,
120
+ 'maxPriorityFeePerGas': 1000000000,
121
+ })
122
+ signed = acct.sign_transaction(tx)
123
+ tx_hash = await w3.eth.send_raw_transaction(signed.raw_transaction)
124
+ await w3.eth.wait_for_transaction_receipt(tx_hash)
125
+ print(f" Approved: {tx_hash.hex()}")
126
+
127
+ # 2. Deposit USDFC (if wallet has balance)
128
+ if wallet_bal > 0:
129
+ deposit_amount = wallet_bal # Deposit all
130
+ print(f"\n2. Depositing {deposit_amount / 1e18:.2f} USDFC...")
131
+ tx = await payments.functions.deposit(USDFC, acct.address, deposit_amount).build_transaction({
132
+ 'from': acct.address,
133
+ 'nonce': await w3.eth.get_transaction_count(acct.address),
134
+ 'gas': 200000,
135
+ 'maxFeePerGas': await w3.eth.gas_price,
136
+ 'maxPriorityFeePerGas': 1000000000,
137
+ })
138
+ signed = acct.sign_transaction(tx)
139
+ tx_hash = await w3.eth.send_raw_transaction(signed.raw_transaction)
140
+ await w3.eth.wait_for_transaction_receipt(tx_hash)
141
+ print(f" Deposited: {tx_hash.hex()}")
142
+
143
+ # 3. Approve FWSS operator
144
+ is_approved = await payments.functions.isOperatorFor(acct.address, FWSS).call()
145
+ if not is_approved:
146
+ print("\n3. Approving FWSS operator...")
147
+ tx = await payments.functions.setOperatorApproval(FWSS, True).build_transaction({
148
+ 'from': acct.address,
149
+ 'nonce': await w3.eth.get_transaction_count(acct.address),
150
+ 'gas': 100000,
151
+ 'maxFeePerGas': await w3.eth.gas_price,
152
+ 'maxPriorityFeePerGas': 1000000000,
153
+ })
154
+ signed = acct.sign_transaction(tx)
155
+ tx_hash = await w3.eth.send_raw_transaction(signed.raw_transaction)
156
+ await w3.eth.wait_for_transaction_receipt(tx_hash)
157
+ print(f" Approved: {tx_hash.hex()}")
158
+ else:
159
+ print("\n3. FWSS operator already approved ✓")
160
+
161
+ print("\n✅ Setup complete! Ready to upload.")
162
+
163
+ asyncio.run(setup())
164
+ ```
165
+
166
+ ## Step 5: Upload a File!
167
+
168
+ ```python
169
+ import asyncio
170
+ from pynapse import AsyncSynapse
171
+
172
+ PRIVATE_KEY = "0xYOUR_PRIVATE_KEY_HERE"
173
+
174
+ async def upload_file():
175
+ # Connect to Calibration testnet
176
+ synapse = await AsyncSynapse.create(
177
+ rpc_url="https://api.calibration.node.glif.io/rpc/v1",
178
+ chain="calibration",
179
+ private_key=PRIVATE_KEY
180
+ )
181
+ print(f"Connected as {synapse.account}")
182
+
183
+ # Get storage context (auto-selects provider)
184
+ ctx = await synapse.storage.get_context()
185
+ print(f"Using provider: {ctx.provider.name}")
186
+ print(f"Dataset ID: {ctx.data_set_id}")
187
+
188
+ # Upload some data (min 256 bytes)
189
+ data = b"Hello, Filecoin! This is my first pynapse upload. " * 10
190
+ print(f"\nUploading {len(data)} bytes...")
191
+
192
+ result = await ctx.upload(data)
193
+
194
+ print(f"\n✅ Upload successful!")
195
+ print(f" Piece CID: {result.piece_cid}")
196
+ print(f" Size: {result.size} bytes")
197
+ print(f" TX Hash: {result.tx_hash}")
198
+
199
+ asyncio.run(upload_file())
200
+ ```
201
+
202
+ ## Step 6: Upload from a File
203
+
204
+ ```python
205
+ import asyncio
206
+ from pynapse import AsyncSynapse
207
+
208
+ PRIVATE_KEY = "0xYOUR_PRIVATE_KEY_HERE"
209
+
210
+ async def upload_from_file(filepath: str):
211
+ synapse = await AsyncSynapse.create(
212
+ rpc_url="https://api.calibration.node.glif.io/rpc/v1",
213
+ chain="calibration",
214
+ private_key=PRIVATE_KEY
215
+ )
216
+
217
+ ctx = await synapse.storage.get_context()
218
+
219
+ # Read file
220
+ with open(filepath, "rb") as f:
221
+ data = f.read()
222
+
223
+ # Min size is 256 bytes, max is 254 MiB
224
+ if len(data) < 256:
225
+ data = data + b'\x00' * (256 - len(data)) # Pad if needed
226
+
227
+ print(f"Uploading {filepath} ({len(data)} bytes)...")
228
+ result = await ctx.upload(data)
229
+
230
+ print(f"✅ Uploaded: {result.piece_cid}")
231
+ return result
232
+
233
+ asyncio.run(upload_from_file("./myfile.txt"))
234
+ ```
235
+
236
+ ---
237
+
238
+ ## Troubleshooting
239
+
240
+ ### "stream-commp helper not found"
241
+ Set the path: `export PYNAPSE_COMMP_HELPER=/path/to/stream-commp`
242
+
243
+ ### "insufficient funds"
244
+ - Check tFIL balance for gas
245
+ - Check USDFC deposited balance in Payments contract
246
+
247
+ ### "operator not approved"
248
+ Run Step 4 to approve the FWSS operator.
249
+
250
+ ### Upload hangs
251
+ - Network latency to Calibration RPC can be slow
252
+ - Storage context creation involves multiple contract calls
253
+
254
+ ---
255
+
256
+ ## Key Addresses (Calibration Testnet)
257
+
258
+ | Contract | Address |
259
+ |----------|---------|
260
+ | USDFC Token | `0xb3042734b608a1B16e9e86B374A3f3e389B4cDf0` |
261
+ | Payments | `0x09a0fDc2723fAd1A7b8e3e00eE5DF73841df55a0` |
262
+ | FWSS (Operator) | `0x02925630df557F957f70E112bA06e50965417CA0` |
263
+ | WarmStorage | `0xa9fEdb4e4acd6434adBE163b2e25f05E54bb4319` |
264
+ | SP Registry | `0xc21cbbF2a8F94f2C9C6D4a6A75C571eB45052e8A` |
265
+
266
+ ---
267
+
268
+ ## Next Steps
269
+
270
+ - Try uploading larger files (up to 254 MiB)
271
+ - Explore batch uploads with `ctx.upload_batch([data1, data2, ...])`
272
+ - Check the SDK source for more options
@@ -0,0 +1,49 @@
1
+ # Pynapse
2
+
3
+ Python SDK for Filecoin Onchain Cloud (Synapse).
4
+
5
+ This project mirrors the JS SDK in `FilOzone/synapse-sdk` and references the Go implementation in `data-preservation-programs/go-synapse` for parity.
6
+
7
+ ## Status
8
+
9
+ Work in progress. Parity is being implemented in incremental commits.
10
+
11
+ ## Install (dev)
12
+
13
+ ```bash
14
+ uv venv
15
+ uv pip install -e .[test]
16
+ ```
17
+
18
+ PyPI package name: `synapse-filecoin-sdk`
19
+ Python import: `pynapse`
20
+
21
+ ## Install (PyPI)
22
+
23
+ ```bash
24
+ pip install synapse-filecoin-sdk
25
+ ```
26
+
27
+ ## CommP / PieceCID
28
+
29
+ `pynapse` uses `stream-commp` from `go-fil-commp-hashhash` for PieceCID calculation.
30
+ Set `PYNAPSE_COMMP_HELPER` to override the helper path.
31
+
32
+ ## License
33
+
34
+ Dual-licensed under Apache-2.0 OR MIT. See `LICENSE.md`.
35
+
36
+ ## Publishing to PyPI
37
+
38
+ Publishing is automated via GitHub Actions in `.github/workflows/publish-pypi.yml`.
39
+
40
+ 1. In PyPI, create the project (or use an existing one) and configure a Trusted Publisher for this GitHub repository and workflow.
41
+ 2. In GitHub, optionally protect the `pypi` environment for manual approval.
42
+ 3. Tag a release and push the tag:
43
+
44
+ ```bash
45
+ git tag v0.1.1
46
+ git push origin v0.1.1
47
+ ```
48
+
49
+ The workflow builds the package, runs `twine check`, and publishes to PyPI via OIDC (no API token required).