decdn 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.
- decdn-0.1.0/LICENSE-APACHE +201 -0
- decdn-0.1.0/LICENSE-MIT +19 -0
- decdn-0.1.0/PKG-INFO +349 -0
- decdn-0.1.0/README.md +326 -0
- decdn-0.1.0/pyproject.toml +91 -0
- decdn-0.1.0/pyproject.toml.orig +75 -0
- decdn-0.1.0/src/decdn/__init__.py +129 -0
- decdn-0.1.0/src/decdn/_core.py +324 -0
- decdn-0.1.0/src/decdn/_hex.py +23 -0
- decdn-0.1.0/src/decdn/_http.py +88 -0
- decdn-0.1.0/src/decdn/_mime.py +68 -0
- decdn-0.1.0/src/decdn/_verify.py +119 -0
- decdn-0.1.0/src/decdn/_version.py +1 -0
- decdn-0.1.0/src/decdn/base32.py +54 -0
- decdn-0.1.0/src/decdn/capability.py +109 -0
- decdn-0.1.0/src/decdn/client.py +425 -0
- decdn-0.1.0/src/decdn/errors.py +74 -0
- decdn-0.1.0/src/decdn/hashing.py +28 -0
- decdn-0.1.0/src/decdn/local.py +32 -0
- decdn-0.1.0/src/decdn/loopback.py +146 -0
- decdn-0.1.0/src/decdn/manifest.py +130 -0
- decdn-0.1.0/src/decdn/pointer.py +351 -0
- decdn-0.1.0/src/decdn/py.typed +0 -0
- decdn-0.1.0/src/decdn/response.py +221 -0
- decdn-0.1.0/src/decdn/uri.py +181 -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 exemplary 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.
|
decdn-0.1.0/LICENSE-MIT
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright 2026 deCDN Contributors
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
decdn-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: decdn
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for deCDN over a decdn gateway: verified fetches, bundles, loopback capabilities and namespace pointers.
|
|
5
|
+
Keywords: decdn,cdn,blake3,content-addressed,gateway
|
|
6
|
+
License-Expression: MIT OR Apache-2.0
|
|
7
|
+
License-File: LICENSE-APACHE
|
|
8
|
+
License-File: LICENSE-MIT
|
|
9
|
+
Classifier: Typing :: Typed
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: httpx>=0.28
|
|
15
|
+
Requires-Dist: blake3>=1.0
|
|
16
|
+
Requires-Dist: coincurve>=20
|
|
17
|
+
Requires-Dist: pycryptodome>=3.20
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Project-URL: Homepage, https://github.com/decdn/sdk-python
|
|
20
|
+
Project-URL: Repository, https://github.com/decdn/sdk-python
|
|
21
|
+
Project-URL: Issues, https://github.com/decdn/sdk-python/issues
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
<!-- markdownlint-disable-file MD033 MD041 -->
|
|
25
|
+
<p align="center">
|
|
26
|
+
<a href="https://decdn.org">
|
|
27
|
+
<picture>
|
|
28
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/decdn/decdn/main/.github/assets/wordmark-dark.svg">
|
|
29
|
+
<img alt="deCDN" src="https://raw.githubusercontent.com/decdn/decdn/main/.github/assets/wordmark-light.svg" width="150">
|
|
30
|
+
</picture>
|
|
31
|
+
</a>
|
|
32
|
+
</p>
|
|
33
|
+
|
|
34
|
+
<h1 align="center">decdn</h1>
|
|
35
|
+
|
|
36
|
+
<h3 align="center">Python client for deCDN: verified fetches, bundles, loopback capabilities and namespace pointers.</h3>
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<a href="https://github.com/decdn/sdk-python/actions/workflows/ci.yml?query=branch%3Amain"><img src="https://img.shields.io/github/actions/workflow/status/decdn/sdk-python/ci.yml?branch=main&label=CI&logo=github" alt="CI"></a>
|
|
40
|
+
<a href="https://github.com/decdn/sdk-python/actions/workflows/codeql.yml?query=branch%3Amain"><img src="https://img.shields.io/github/actions/workflow/status/decdn/sdk-python/codeql.yml?branch=main&label=CodeQL&logo=github" alt="CodeQL"></a>
|
|
41
|
+
<a href="https://pypi.org/project/decdn/"><img src="https://img.shields.io/pypi/v/decdn?logo=pypi&logoColor=white" alt="PyPI"></a>
|
|
42
|
+
<a href="https://pypi.org/project/decdn/"><img src="https://img.shields.io/pypi/pyversions/decdn?logo=python&logoColor=white" alt="Python versions"></a>
|
|
43
|
+
<a href="#compatibility"><img src="https://img.shields.io/badge/dynamic/toml?url=https%3A%2F%2Fraw.githubusercontent.com%2Fdecdn%2Fsdk-python%2Fmain%2Fpyproject.toml&query=%24.tool.decdn.gateway-floor&label=decdn%20gateway&prefix=%E2%89%A5%20v" alt="decdn gateway floor"></a>
|
|
44
|
+
<a href="#license"><img src="https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue" alt="License: MIT OR Apache-2.0"></a>
|
|
45
|
+
<a href="https://www.conventionalcommits.org"><img src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow" alt="Conventional Commits"></a>
|
|
46
|
+
<a href="https://discord.gg/vVbNswKVGX"><img src="https://img.shields.io/badge/chat-Discord-5865F2?logo=discord&logoColor=white" alt="Discord"></a>
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
<h3 align="center">
|
|
50
|
+
<a href="https://decdn.org">Website</a> ·
|
|
51
|
+
<a href="https://docs.decdn.org">Docs</a> ·
|
|
52
|
+
<a href="https://github.com/decdn/decdn/blob/main/adr/appendix-gateway.md">Gateway spec</a> ·
|
|
53
|
+
<a href="https://github.com/decdn/decdn">deCDN</a> ·
|
|
54
|
+
<a href="https://discord.gg/vVbNswKVGX">Discord</a>
|
|
55
|
+
</h3>
|
|
56
|
+
|
|
57
|
+
Python client for [deCDN](https://github.com/decdn/decdn), for Python 3.11+.
|
|
58
|
+
It speaks HTTP to a `decdn gateway`, which pays for every pull and verifies
|
|
59
|
+
it, and it hashes the bytes again with BLAKE3 wherever it holds a whole blob
|
|
60
|
+
named by its hash. No iroh, no wallet library. `Client` is synchronous and
|
|
61
|
+
`AsyncClient` is its `asyncio` twin; both take the same arguments and return
|
|
62
|
+
the same shapes.
|
|
63
|
+
|
|
64
|
+
- **Verified streaming.** A blob, or a whole bundle entry, is hashed with
|
|
65
|
+
BLAKE3 as it streams; a body that does not hash to its name raises
|
|
66
|
+
`HASH_MISMATCH` instead of ending cleanly. Ranges and rendered pages are
|
|
67
|
+
`"skipped"` ([Verification](#verification)).
|
|
68
|
+
- **Bundles.** Entries are checked against the bundle manifest, which is
|
|
69
|
+
itself verified and cached per client.
|
|
70
|
+
- **Byte ranges** of sized entries, for large files such as model weights. A
|
|
71
|
+
window does not hash to anything, so its `verified` is `"skipped"`.
|
|
72
|
+
- **Loopback gateways.** Mint delegate keys and register capabilities on a
|
|
73
|
+
local `decdn gateway`.
|
|
74
|
+
- **Namespace pointers.** Point a `PublisherRegistry` namespace at a bundle on
|
|
75
|
+
a public gateway, signing EIP-712 typed data with a private key or an
|
|
76
|
+
`eth-account`-style `sign_typed_data` signer.
|
|
77
|
+
- **Small and typed.** Fully annotated (`py.typed`); namespaces, seq, caps and
|
|
78
|
+
expiries are exact `int`s.
|
|
79
|
+
|
|
80
|
+
## Contents
|
|
81
|
+
|
|
82
|
+
- [Install](#install)
|
|
83
|
+
- [Gateways](#gateways)
|
|
84
|
+
- [Compatibility](#compatibility)
|
|
85
|
+
- [Public gateway](#public-gateway)
|
|
86
|
+
- [Loopback gateway](#loopback-gateway)
|
|
87
|
+
- [Verification](#verification)
|
|
88
|
+
- [Errors](#errors)
|
|
89
|
+
- [Namespace pointers](#namespace-pointers)
|
|
90
|
+
- [API at a glance](#api-at-a-glance)
|
|
91
|
+
- [Development](#development)
|
|
92
|
+
- [License](#license)
|
|
93
|
+
|
|
94
|
+
## Install
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
pip install decdn
|
|
98
|
+
# or
|
|
99
|
+
uv add decdn
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Gateways
|
|
103
|
+
|
|
104
|
+
The client talks to one of two kinds of gateway:
|
|
105
|
+
|
|
106
|
+
| Gateway | Where it runs | Who pays |
|
|
107
|
+
| -------------------------------------------------------- | -------------------------------------- | ------------------------------------------------- |
|
|
108
|
+
| Public (`decdn gateway --public-url https://decdn.link`) | Anywhere with network access | The operator's pool, within a daily allowance |
|
|
109
|
+
| Loopback (`decdn gateway`, `http://127.0.0.1:8484`) | The same machine, with the gateway token | The capability registered for the requesting host |
|
|
110
|
+
|
|
111
|
+
The gateway's HTTP contract is
|
|
112
|
+
[appendix-gateway](https://github.com/decdn/decdn/blob/main/adr/appendix-gateway.md);
|
|
113
|
+
bundles and their manifests are
|
|
114
|
+
[appendix-bundles](https://github.com/decdn/decdn/blob/main/adr/appendix-bundles.md).
|
|
115
|
+
|
|
116
|
+
## Compatibility
|
|
117
|
+
|
|
118
|
+
Python 3.11 or later. Python 3.14 is not yet supported: coincurve ships no 3.14 wheels; the matrix grows when it does.
|
|
119
|
+
|
|
120
|
+
Two floors in `pyproject.toml` (`[tool.decdn]`) say which `decdn gateway`
|
|
121
|
+
releases the SDK works against:
|
|
122
|
+
|
|
123
|
+
- `gateway-floor` (`0.3.0`) is the oldest gateway whose HTTP contract the SDK
|
|
124
|
+
supports, checked at release. It is the release that carries
|
|
125
|
+
[cross-origin reads](https://github.com/decdn/decdn/blob/main/adr/appendix-gateway.md#cross-origin-reads),
|
|
126
|
+
which a public gateway needs; any loopback gateway works.
|
|
127
|
+
- `harness-floor` is the first decdn release whose e2e harness runs this SDK's
|
|
128
|
+
contract suite ([CONTRIBUTING.md](CONTRIBUTING.md#the-contract-suite-fake-and-real-gateway)).
|
|
129
|
+
It is empty until that release exists: the released-gateway run starts with
|
|
130
|
+
the first decdn release that ships the Python harness.
|
|
131
|
+
|
|
132
|
+
## Public gateway
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from decdn import AsyncClient, ByteRange, Client
|
|
136
|
+
|
|
137
|
+
with Client("https://decdn.link") as client:
|
|
138
|
+
# A blob, streamed and hashed as it arrives.
|
|
139
|
+
blob = client.get("decdn:<64 hex>")
|
|
140
|
+
blob.verified # True
|
|
141
|
+
data = blob.read() # raises HASH_MISMATCH on bad bytes
|
|
142
|
+
|
|
143
|
+
# One file of a bundle, checked against the bundle's manifest.
|
|
144
|
+
page = client.get("decdn:<manifest hash>/docs/index.html")
|
|
145
|
+
text = page.text()
|
|
146
|
+
|
|
147
|
+
# A window of a sized entry: 206, not verifiable.
|
|
148
|
+
part = client.get("decdn:<manifest hash>/model.bin", range=ByteRange(offset=0, length=1 << 20))
|
|
149
|
+
part.content_range # ContentRange(offset=0, length=1048576, size=...)
|
|
150
|
+
|
|
151
|
+
# The same calls, awaited.
|
|
152
|
+
async with AsyncClient("https://decdn.link") as client:
|
|
153
|
+
blob = await client.get("decdn:<64 hex>")
|
|
154
|
+
data = await blob.read()
|
|
155
|
+
|
|
156
|
+
# Or stream it: the mismatch raises at the end of the iteration.
|
|
157
|
+
streamed = await client.get("decdn:<64 hex>")
|
|
158
|
+
async for chunk in streamed.iter_bytes():
|
|
159
|
+
...
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`ByteRange` takes an `offset` and, optionally, a `length`. A response is a context manager
|
|
163
|
+
too; leaving the block closes the connection if the body was not read.
|
|
164
|
+
|
|
165
|
+
## Loopback gateway
|
|
166
|
+
|
|
167
|
+
A loopback gateway pays with a capability a pool owner issued to one of its
|
|
168
|
+
delegate keys. Mint the delegate, have the owner assign it, and register it
|
|
169
|
+
for the host your requests name:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from decdn import AsyncClient, Client
|
|
173
|
+
from decdn.local import read_loopback_token
|
|
174
|
+
|
|
175
|
+
with Client(
|
|
176
|
+
"http://127.0.0.1:8484",
|
|
177
|
+
token=read_loopback_token(), # ~/.decdn/gateway/token
|
|
178
|
+
host="example.com", # sent as x-decdn-host
|
|
179
|
+
) as client:
|
|
180
|
+
delegate = client.loopback.delegate()
|
|
181
|
+
# The pool owner: decdn pool assign --pool <id> --signer <delegate.address> ...
|
|
182
|
+
client.loopback.register_capability(capability="dcap1:...", scope="example.com")
|
|
183
|
+
r = client.get("decdn:<64 hex>")
|
|
184
|
+
|
|
185
|
+
async with AsyncClient("http://127.0.0.1:8484", token=read_loopback_token(), host="example.com") as client:
|
|
186
|
+
delegate = await client.loopback.delegate()
|
|
187
|
+
await client.loopback.register_capability(capability="dcap1:...", scope="example.com")
|
|
188
|
+
r = await client.get("decdn:<64 hex>")
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`client.loopback.capabilities()` lists what the gateway holds. Without a
|
|
192
|
+
covering capability a request fails with `PAYMENT_REQUIRED`. A `dcap1:` token
|
|
193
|
+
decodes offline with `parse_capability`.
|
|
194
|
+
|
|
195
|
+
The SDK does not start the gateway. Run it yourself (`decdn gateway`, or the
|
|
196
|
+
`decdn/decdn` Docker image). A `localhost`, `127.0.0.1` or `::1` URL opens a
|
|
197
|
+
loopback client; a public gateway you run locally needs another host name,
|
|
198
|
+
such as `decdn.localhost`. `read_loopback_token(data_dir=None)` reads the
|
|
199
|
+
token from the gateway's data dir (`default_data_dir()`, `~/.decdn/gateway`).
|
|
200
|
+
|
|
201
|
+
## Verification
|
|
202
|
+
|
|
203
|
+
`get` takes `verify="auto" | True | False` (default `"auto"`, or the client's
|
|
204
|
+
own default from its constructor). `response.verified` says what happened:
|
|
205
|
+
|
|
206
|
+
| Request | `verified` | How |
|
|
207
|
+
| --------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
208
|
+
| A blob by hash | `True` | The whole body hashes to the URI's hash. |
|
|
209
|
+
| A bundle entry | `True` | The client reads the bundle manifest (cached per client, itself verified) and the body hashes to the entry's hash. |
|
|
210
|
+
| A page or stylesheet entry | `True` | A site rewrites HTML and CSS as it serves them, so the client fetches these by their entry hash instead. |
|
|
211
|
+
| A `range` of a bundle entry | `"skipped"` | A window does not hash to anything. A blob has no declared size, so a range on one is refused with `CONFIG`. |
|
|
212
|
+
| A bundle's index or listing | `"skipped"` | The gateway renders it. |
|
|
213
|
+
| Any, with `verify=False` | `False` | Nothing is hashed and no manifest is read. |
|
|
214
|
+
|
|
215
|
+
`verify=True` refuses a request that cannot be verified with `CONFIG`.
|
|
216
|
+
|
|
217
|
+
A verified body is hashed as it streams, and a body is consumed once: by
|
|
218
|
+
`read()` (also `text()` and `json()`) or by `iter_bytes()`, not both. A
|
|
219
|
+
mismatch raises `HASH_MISMATCH` (or `TRUNCATED` when the gateway cuts the
|
|
220
|
+
stream) from `read()`, or from the iteration at its end, and the same error
|
|
221
|
+
again on every later call. Chunks read before the end are not yet verified;
|
|
222
|
+
act on them only once the iteration finishes. Ranges are never verified.
|
|
223
|
+
|
|
224
|
+
## Errors
|
|
225
|
+
|
|
226
|
+
Every failure is a `DecdnError` with a stable `code`:
|
|
227
|
+
|
|
228
|
+
| Code | When |
|
|
229
|
+
| ----------------------- | --------------------------------------------------------------------------------------------------- |
|
|
230
|
+
| `PAYMENT_REQUIRED` | 402: the allowance is spent, the entry does not fit what is left, or no capability covers the host |
|
|
231
|
+
| `POOL_UNFUNDED` | 503: the gateway's pool cannot pay |
|
|
232
|
+
| `NOT_FOUND` | 404 |
|
|
233
|
+
| `RANGE_NOT_SATISFIABLE` | 416: the range starts past the end; `size` holds the entry's size |
|
|
234
|
+
| `UNAUTHORIZED` | 401: the loopback token is missing or wrong |
|
|
235
|
+
| `FORBIDDEN` | 403 |
|
|
236
|
+
| `BAD_URI` | A `decdn:` URI that does not parse, or 400 |
|
|
237
|
+
| `RATE_LIMITED` | 429 |
|
|
238
|
+
| `UPSTREAM` | 502: the gateway's pull failed upstream |
|
|
239
|
+
| `PAYLOAD_TOO_LARGE` | 413 |
|
|
240
|
+
| `CONFLICT` | 409: a pointer `seq` that is not newer, or a capability already registered |
|
|
241
|
+
| `UNPROCESSABLE` | 422 |
|
|
242
|
+
| `HASH_MISMATCH` | The bytes do not hash to the hash that names them |
|
|
243
|
+
| `TRUNCATED` | The body is shorter or longer than declared, or the stream failed |
|
|
244
|
+
| `MALFORMED_MANIFEST` | A bundle manifest that does not parse |
|
|
245
|
+
| `BAD_CAPABILITY` | A `dcap1:` token that does not decode |
|
|
246
|
+
| `NETWORK` | The gateway could not be reached |
|
|
247
|
+
| `CONFIG` | The client is not set up for the call, or the call cannot be honoured as asked |
|
|
248
|
+
| `HTTP` | A status the gateway contract does not name |
|
|
249
|
+
|
|
250
|
+
The error carries the details its failure has, and `None` for the rest:
|
|
251
|
+
`status`, `body`, `retry_after_secs` and `fallback_uri` (402 and 503), `size`
|
|
252
|
+
(416) and `seq` (409). The cause, when there is one, is the chained exception.
|
|
253
|
+
|
|
254
|
+
`fallback_uri` is the canonical `decdn:` URI: fetch it with a paying client of
|
|
255
|
+
your own (`decdn get <uri>`), or wait `retry_after_secs`. The SDK retries
|
|
256
|
+
nothing on its own; `get(uri, retry=True)` waits out one `Retry-After` and
|
|
257
|
+
tries once more, and `retry=30.0` does so only when the wait is at most 30
|
|
258
|
+
seconds.
|
|
259
|
+
|
|
260
|
+
## Namespace pointers
|
|
261
|
+
|
|
262
|
+
On a public gateway, the owner of a namespace on the `PublisherRegistry`
|
|
263
|
+
points it at a bundle, and `https://<ns>.<host>/` serves that bundle:
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
from decdn import AsyncClient, Client, PointerDomain
|
|
267
|
+
|
|
268
|
+
domain = PointerDomain(chain_id=421614, publisher_registry="0x...")
|
|
269
|
+
|
|
270
|
+
with Client("https://decdn.link", pointer=domain) as client:
|
|
271
|
+
result = client.pointer.set(
|
|
272
|
+
namespace=42,
|
|
273
|
+
root="decdn:<manifest hash>/",
|
|
274
|
+
signer="0x...", # a raw secp256k1 key: hex or 32 bytes
|
|
275
|
+
)
|
|
276
|
+
result.url # https://42.decdn.link/
|
|
277
|
+
|
|
278
|
+
async with AsyncClient("https://decdn.link", pointer=domain) as client:
|
|
279
|
+
result = await client.pointer.set(namespace=42, root="decdn:<manifest hash>/", signer="0x...")
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
A wallet signs instead: any object with
|
|
283
|
+
`sign_typed_data(typed_data) -> str` is a `TypedDataSigner`. For an
|
|
284
|
+
`eth-account` `LocalAccount`, whose `sign_typed_data` returns a
|
|
285
|
+
`SignedMessage`, a three-line adapter does it:
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
class AccountSigner:
|
|
289
|
+
def __init__(self, account):
|
|
290
|
+
self.account = account
|
|
291
|
+
|
|
292
|
+
def sign_typed_data(self, typed_data):
|
|
293
|
+
return "0x" + self.account.sign_typed_data(full_message=typed_data).signature.hex()
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
then `signer=AccountSigner(account)`.
|
|
297
|
+
|
|
298
|
+
The pointer is EIP-712 typed data (`pointer_typed_data` gives it to a wallet),
|
|
299
|
+
`seq` defaults to the current Unix second, and the gateway takes only a `seq`
|
|
300
|
+
above the last one it holds from the same signer. The chain id and registry
|
|
301
|
+
are the deployment the gateway verifies against.
|
|
302
|
+
|
|
303
|
+
## API at a glance
|
|
304
|
+
|
|
305
|
+
| Export | What it does |
|
|
306
|
+
| --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
307
|
+
| `Client(gateway_url, ...)`, `AsyncClient(gateway_url, ...)` | A client on a public or loopback gateway (`token`, `host`, `pointer`, `transport`, `verify`, `manifest_cache_size`, `timeout`); a context manager |
|
|
308
|
+
| `client.get(uri, range=, verify=, retry=)` | Fetches a blob, a bundle, a bundle entry or a range as a `Response` / `AsyncResponse` (`verified`, `iter_bytes`, `read`, `text`, `json`) |
|
|
309
|
+
| `client.head(uri)` | The size, hash and content type of what a URI names, without its bytes |
|
|
310
|
+
| `client.resolve(uri)` | A URI's kind, hash, bare and site URLs, and its manifest entry (reads the manifest for a bundle or entry) |
|
|
311
|
+
| `client.manifest(hash_or_uri)` | A bundle's verified manifest, cached per client |
|
|
312
|
+
| `client.site_url(uri)`, `client.namespace_url(ns)` | The site URL of a bundle or entry; the URL a namespace's pointer serves at (`https://<ns>.<host>/`). Neither makes a request |
|
|
313
|
+
| `client.loopback.delegate()` | Mints a delegate key on a loopback gateway, held for 15 minutes unless a capability claims it |
|
|
314
|
+
| `client.loopback.register_capability(capability=, scope=)`, `.capabilities()` | Registers a `dcap1:` capability for a scope (`example.com`, `*.example.com` or `*`); lists the capabilities the gateway holds (needs the token) |
|
|
315
|
+
| `client.pointer.set(namespace=, root=, seq=, signer=)` | Signs and publishes a namespace pointer on a public gateway |
|
|
316
|
+
| `pointer_typed_data`, `pointer_signing_hash`, `sign_pointer`, `recover_pointer_signer` | The pointer's EIP-712 typed data and signing hash, its signature, and the signer a signature recovers to |
|
|
317
|
+
| `parse_uri`, `format_uri` | Parse and canonically format a `decdn:` URI, following the Rust client's grammar exactly (`BAD_URI` on anything it refuses) |
|
|
318
|
+
| `hash_to_base32`, `base32_to_hash` | A hash to and from its site label |
|
|
319
|
+
| `blake3_hex`, `create_blake3` | BLAKE3, one-shot and incremental |
|
|
320
|
+
| `parse_manifest`, `parse_capability` | Decodes a v1 bundle manifest, checking its hash when given one; decodes a `dcap1:` token without checking its signature |
|
|
321
|
+
| `DecdnError` | Every failure, with a stable `code` ([Errors](#errors)) |
|
|
322
|
+
| `read_loopback_token`, `default_data_dir` | From `decdn.local`: the loopback gateway's token and data dir (`~/.decdn/gateway`) |
|
|
323
|
+
|
|
324
|
+
Namespaces, sequence numbers, caps and expiries are `int`.
|
|
325
|
+
|
|
326
|
+
## Development
|
|
327
|
+
|
|
328
|
+
```sh
|
|
329
|
+
uv sync --frozen
|
|
330
|
+
uv run ruff check . && uv run ruff format --check .
|
|
331
|
+
uv run mypy
|
|
332
|
+
uv run pytest # unit tests and the contract suite against the fake gateway
|
|
333
|
+
uv build # dist/: sdist and wheel
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
`tests/fake_gateway.py` reproduces the gateway's HTTP contract. The contract
|
|
337
|
+
suite in `tests/contract` runs against it by default, and against a real
|
|
338
|
+
gateway in decdn's CI
|
|
339
|
+
([`sdk_contract.rs`](https://github.com/decdn/decdn/blob/main/crates/e2e/src/sdk_contract.rs)),
|
|
340
|
+
so the two cannot drift apart. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
341
|
+
|
|
342
|
+
Releases are cut from signed `v*` tags ([RELEASING.md](RELEASING.md)); the
|
|
343
|
+
keys that sign them are in [`KEYS`](KEYS) (`gpg --import KEYS`, then
|
|
344
|
+
`git verify-tag vX.Y.Z`).
|
|
345
|
+
|
|
346
|
+
## License
|
|
347
|
+
|
|
348
|
+
Dual-licensed under either [MIT](LICENSE-MIT) or [Apache-2.0](LICENSE-APACHE),
|
|
349
|
+
at your option.
|