kite-x402-wrapper 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 (31) hide show
  1. kite_x402_wrapper-0.1.0/.dockerignore +16 -0
  2. kite_x402_wrapper-0.1.0/.env.example +29 -0
  3. kite_x402_wrapper-0.1.0/.github/workflows/ci.yml +50 -0
  4. kite_x402_wrapper-0.1.0/.github/workflows/publish.yml +25 -0
  5. kite_x402_wrapper-0.1.0/.gitignore +17 -0
  6. kite_x402_wrapper-0.1.0/CHANGELOG.md +12 -0
  7. kite_x402_wrapper-0.1.0/CONTRIBUTING.md +22 -0
  8. kite_x402_wrapper-0.1.0/Dockerfile +19 -0
  9. kite_x402_wrapper-0.1.0/LICENSE +201 -0
  10. kite_x402_wrapper-0.1.0/PKG-INFO +155 -0
  11. kite_x402_wrapper-0.1.0/README.md +118 -0
  12. kite_x402_wrapper-0.1.0/SECURITY.md +27 -0
  13. kite_x402_wrapper-0.1.0/examples/open_meteo/README.md +26 -0
  14. kite_x402_wrapper-0.1.0/examples/open_meteo/main.py +5 -0
  15. kite_x402_wrapper-0.1.0/pyproject.toml +77 -0
  16. kite_x402_wrapper-0.1.0/src/kite_x402_wrapper/__init__.py +16 -0
  17. kite_x402_wrapper-0.1.0/src/kite_x402_wrapper/app.py +98 -0
  18. kite_x402_wrapper-0.1.0/src/kite_x402_wrapper/asgi.py +5 -0
  19. kite_x402_wrapper-0.1.0/src/kite_x402_wrapper/cli.py +21 -0
  20. kite_x402_wrapper-0.1.0/src/kite_x402_wrapper/config.py +163 -0
  21. kite_x402_wrapper-0.1.0/src/kite_x402_wrapper/networks.py +68 -0
  22. kite_x402_wrapper-0.1.0/src/kite_x402_wrapper/payment.py +59 -0
  23. kite_x402_wrapper-0.1.0/src/kite_x402_wrapper/proxy.py +107 -0
  24. kite_x402_wrapper-0.1.0/src/kite_x402_wrapper/py.typed +1 -0
  25. kite_x402_wrapper-0.1.0/tests/__init__.py +1 -0
  26. kite_x402_wrapper-0.1.0/tests/conftest.py +113 -0
  27. kite_x402_wrapper-0.1.0/tests/test_config.py +67 -0
  28. kite_x402_wrapper-0.1.0/tests/test_networks.py +38 -0
  29. kite_x402_wrapper-0.1.0/tests/test_payment_flow.py +193 -0
  30. kite_x402_wrapper-0.1.0/tests/test_proxy.py +98 -0
  31. kite_x402_wrapper-0.1.0/uv.lock +4148 -0
@@ -0,0 +1,16 @@
1
+ .git
2
+ .github
3
+ .venv
4
+ .env
5
+ .env.*
6
+ dist
7
+ build
8
+ *.egg-info
9
+ .pytest_cache
10
+ .mypy_cache
11
+ .ruff_cache
12
+ .coverage
13
+ htmlcov
14
+ __pycache__
15
+ *.pyc
16
+ tests
@@ -0,0 +1,29 @@
1
+ # 收款钱包的公开 EVM 地址(20 字节、以 0x 开头)。这里只填地址,绝不能填私钥。
2
+ PAY_TO=0xYourKiteWalletAddress
3
+
4
+ # 结算网络:mainnet 使用 Kite 主网 USDC.e;testnet 使用 Kite 测试网 pieUSD。
5
+ # 建议先使用 testnet,只有准备好正式收款时才切换到 mainnet。
6
+ KITE_NETWORK=testnet
7
+
8
+ # 被代理的上游 API 的固定 HTTPS/HTTP 域名,只能填写 origin,不能带路径、查询参数或片段。
9
+ # 例如请求 /v1/forecast 时,会转发到 UPSTREAM_URL/forecast。
10
+ # Open-Meteo 示例使用 https://api.open-meteo.com。
11
+ UPSTREAM_URL=https://api.open-meteo.com
12
+
13
+ # 上游 API 需要的认证请求头名称;不需要认证时保持默认值即可。
14
+ UPSTREAM_AUTH_HEADER=Authorization
15
+
16
+ # 上游认证请求头的值,例如 Bearer <token>。不需要认证时留空;不要提交真实密钥。
17
+ UPSTREAM_AUTH_VALUE=
18
+
19
+ # 每次成功请求的美元计价,必须是大于 0 且最多 6 位小数的十进制数字。
20
+ PRICE_USD=0.001
21
+
22
+ # 写入 x402 付款要求中的服务描述,方便付款方识别服务用途。
23
+ SERVICE_DESCRIPTION=Paid API wrapped for the Kite network
24
+
25
+ # Wrapper 本地监听端口,默认 8080。
26
+ PORT=8080
27
+
28
+ # x402 facilitator 服务地址,必须使用 HTTPS,并保留 /v2 后缀。
29
+ FACILITATOR_URL=https://facilitator.pieverse.io/v2
@@ -0,0 +1,50 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
18
+ steps:
19
+ - uses: actions/checkout@v7
20
+ - uses: actions/setup-python@v7
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+ - run: python -m pip install uv
24
+ - run: uv sync --frozen --extra dev
25
+ - run: uv run ruff check .
26
+ - run: uv run ruff format --check .
27
+ - run: uv run mypy
28
+ - run: uv run pytest --cov=kite_x402_wrapper --cov-report=term-missing
29
+
30
+ package:
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v7
34
+ - uses: actions/setup-python@v7
35
+ with:
36
+ python-version: "3.13"
37
+ - run: python -m pip install uv
38
+ - run: uv sync --frozen --extra dev
39
+ - run: uv build
40
+ - run: uv run twine check dist/*
41
+ - uses: actions/upload-artifact@v7
42
+ with:
43
+ name: python-distributions
44
+ path: dist/
45
+
46
+ container:
47
+ runs-on: ubuntu-latest
48
+ steps:
49
+ - uses: actions/checkout@v7
50
+ - run: docker build -t kite-x402-wrapper:ci .
@@ -0,0 +1,25 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ publish:
12
+ runs-on: ubuntu-latest
13
+ environment:
14
+ name: pypi
15
+ url: https://pypi.org/project/kite-x402-wrapper/
16
+ permissions:
17
+ id-token: write
18
+ steps:
19
+ - uses: actions/checkout@v7
20
+ - uses: actions/setup-python@v7
21
+ with:
22
+ python-version: "3.13"
23
+ - run: python -m pip install build
24
+ - run: python -m build
25
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,17 @@
1
+ .env
2
+ .env.*
3
+ !.env.example
4
+ .venv/
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .pytest_cache/
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+ .coverage
12
+ htmlcov/
13
+ __pycache__/
14
+ *.py[cod]
15
+ .DS_Store
16
+
17
+ .kite-passport/
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ ## 0.1.0 - 2026-09-19
6
+
7
+ - Add a reusable Python and FastAPI x402 reverse proxy for Kite.
8
+ - Support Kite mainnet USDC.e and testnet pieUSD settlement requirements.
9
+ - Keep `/healthz` free and protect every HTTP method below `/v1/*`.
10
+ - Settle only after a successful upstream response.
11
+ - Add isolated tests for payment ordering, failure paths, configuration, and proxy safety.
12
+ - Add Docker, CI, Python package, and trusted-publishing configuration.
@@ -0,0 +1,22 @@
1
+ # Contributing
2
+
3
+ Use Python 3.10 or newer and install the locked development environment:
4
+
5
+ ```bash
6
+ uv sync --extra dev
7
+ ```
8
+
9
+ Before opening a pull request, run:
10
+
11
+ ```bash
12
+ uv run ruff check .
13
+ uv run ruff format --check .
14
+ uv run mypy
15
+ uv run pytest --cov=kite_x402_wrapper
16
+ uv build
17
+ uv run twine check dist/*
18
+ ```
19
+
20
+ Changes to payment behavior must preserve `verify -> upstream -> settle`, and
21
+ must include a test proving that error responses do not settle. Never commit
22
+ real credentials or fabricated paid-call evidence.
@@ -0,0 +1,19 @@
1
+ FROM python:3.12-slim AS runtime
2
+
3
+ ENV PYTHONDONTWRITEBYTECODE=1 \
4
+ PYTHONUNBUFFERED=1 \
5
+ PIP_DISABLE_PIP_VERSION_CHECK=1
6
+
7
+ WORKDIR /app
8
+
9
+ COPY pyproject.toml README.md LICENSE ./
10
+ COPY src ./src
11
+
12
+ RUN pip install --no-cache-dir . \
13
+ && addgroup --system wrapper \
14
+ && adduser --system --ingroup wrapper --no-create-home wrapper
15
+
16
+ USER wrapper
17
+ EXPOSE 8080
18
+
19
+ CMD ["kite-x402-wrapper"]
@@ -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,155 @@
1
+ Metadata-Version: 2.5
2
+ Name: kite-x402-wrapper
3
+ Version: 0.1.0
4
+ Summary: FastAPI reverse proxy with x402 payments settled on Kite
5
+ Project-URL: Homepage, https://github.com/Tools-touch/KiteAI-X402-Wrapper
6
+ Project-URL: Repository, https://github.com/Tools-touch/KiteAI-X402-Wrapper
7
+ Project-URL: Issues, https://github.com/Tools-touch/KiteAI-X402-Wrapper/issues
8
+ Author: Tools-touch
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: fastapi,kite,payments,reverse-proxy,x402
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Framework :: FastAPI
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: fastapi<1,>=0.115
23
+ Requires-Dist: httpx<1,>=0.28.1
24
+ Requires-Dist: python-dotenv<2,>=1.1
25
+ Requires-Dist: uvicorn[standard]<1,>=0.40
26
+ Requires-Dist: x402[evm,fastapi]<3,>=2.23
27
+ Provides-Extra: dev
28
+ Requires-Dist: build<2,>=1.3; extra == 'dev'
29
+ Requires-Dist: mypy<2,>=1.18; extra == 'dev'
30
+ Requires-Dist: pytest-asyncio<2,>=1.2; extra == 'dev'
31
+ Requires-Dist: pytest-cov<8,>=7; extra == 'dev'
32
+ Requires-Dist: pytest<9,>=8.4; extra == 'dev'
33
+ Requires-Dist: respx<1,>=0.22; extra == 'dev'
34
+ Requires-Dist: ruff<1,>=0.13; extra == 'dev'
35
+ Requires-Dist: twine<8,>=7; extra == 'dev'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # Kite x402 Wrapper for Python
39
+
40
+ Wrap an HTTP API with x402 payments settled on Kite, using Python, FastAPI,
41
+ and the official `x402` SDK. Every request under `/v1/*` is payment protected;
42
+ `/healthz` remains free.
43
+
44
+ The wrapper preserves the critical order:
45
+
46
+ ```text
47
+ verify payment -> call upstream -> settle only when upstream status is below 400
48
+ ```
49
+
50
+ ## Install
51
+
52
+ Python 3.10 or newer is required.
53
+
54
+ The `0.1.0` PyPI release is prepared but is not published yet. Until the
55
+ release is published, use the repository installation below.
56
+
57
+ ```bash
58
+ git clone https://github.com/Tools-touch/KiteAI-X402-Wrapper.git
59
+ cd KiteAI-X402-Wrapper
60
+ uv sync --extra dev
61
+ cp .env.example .env
62
+ kite-x402-wrapper
63
+ ```
64
+
65
+ After the PyPI release is published, the installed-package form is:
66
+
67
+ ```bash
68
+ python -m pip install kite-x402-wrapper
69
+ cp .env.example .env
70
+ kite-x402-wrapper
71
+ ```
72
+
73
+ For development from this repository:
74
+
75
+ ```bash
76
+ uv sync --extra dev
77
+ cp .env.example .env
78
+ uv run kite-x402-wrapper
79
+ ```
80
+
81
+ Then request a paid route:
82
+
83
+ ```bash
84
+ curl -i "http://localhost:8080/v1/v1/forecast?latitude=52.52&longitude=13.41&current=temperature_2m"
85
+ ```
86
+
87
+ An unpaid request returns HTTP 402 with a `PAYMENT-REQUIRED` header. The
88
+ wrapper strips the first `/v1` prefix before proxying, so the example above
89
+ reaches `https://api.open-meteo.com/v1/forecast`.
90
+
91
+ ## Configuration
92
+
93
+ | Variable | Default | Purpose |
94
+ |---|---|---|
95
+ | `PAY_TO` | required | Public EVM address receiving payments |
96
+ | `KITE_NETWORK` | `mainnet` | `mainnet` or `testnet` |
97
+ | `UPSTREAM_URL` | required | Fixed upstream HTTP(S) origin |
98
+ | `UPSTREAM_AUTH_HEADER` | `Authorization` | Optional upstream credential header |
99
+ | `UPSTREAM_AUTH_VALUE` | empty | Optional credential value, never returned to callers |
100
+ | `PRICE_USD` | `0.001` | Positive decimal USD price, at most 6 fractional digits |
101
+ | `SERVICE_DESCRIPTION` | generic description | Text included in the 402 requirements |
102
+ | `FACILITATOR_URL` | Pieverse `/v2` endpoint | HTTPS x402 facilitator base URL |
103
+ | `PORT` | `8080` | Listening port |
104
+
105
+ Start on Kite testnet. The wrapper uses pieUSD on `eip155:2368`; mainnet uses
106
+ USDC.e on `eip155:2366`. The package never needs a wallet private key.
107
+
108
+ ## Use as a library
109
+
110
+ ```python
111
+ from kite_x402_wrapper import Settings, create_app
112
+
113
+ settings = Settings.from_env()
114
+ app = create_app(settings)
115
+ ```
116
+
117
+ The application factory accepts an HTTPX client and payment components as
118
+ optional injected dependencies. Tests can therefore verify proxy and
119
+ settlement behavior without real funds or external services.
120
+
121
+ ## Safety properties
122
+
123
+ - A missing or invalid payment never reaches the upstream.
124
+ - Upstream responses with status 400 or higher are not settled.
125
+ - Upstream connection failures return 502 and are not settled.
126
+ - Payment headers are removed before proxying.
127
+ - Upstream credentials replace caller-provided values and are never returned.
128
+ - The proxy target stays on the configured upstream origin.
129
+ - Amount conversion uses `Decimal`, never binary floating point.
130
+
131
+ Because settlement happens after the handler finishes, responses are buffered
132
+ in memory by the official x402 FastAPI middleware. This template is intended
133
+ for ordinary API payloads, not unbounded downloads or streaming endpoints.
134
+
135
+ ## Quality checks
136
+
137
+ ```bash
138
+ uv run ruff check .
139
+ uv run ruff format --check .
140
+ uv run mypy
141
+ uv run pytest --cov=kite_x402_wrapper
142
+ uv build
143
+ uv run twine check dist/*
144
+ ```
145
+
146
+ ## Public deployment and paid acceptance
147
+
148
+ Kite Passport calls services from its own servers. Real paid testing requires
149
+ a public HTTPS origin; localhost and browser-gated tunnels are not sufficient.
150
+ Use a small, short-lived Passport sandbox session and verify the returned
151
+ `PAYMENT-RESPONSE` transaction reference. Never fabricate paid-call evidence.
152
+
153
+ ## License
154
+
155
+ Apache-2.0.
@@ -0,0 +1,118 @@
1
+ # Kite x402 Wrapper for Python
2
+
3
+ Wrap an HTTP API with x402 payments settled on Kite, using Python, FastAPI,
4
+ and the official `x402` SDK. Every request under `/v1/*` is payment protected;
5
+ `/healthz` remains free.
6
+
7
+ The wrapper preserves the critical order:
8
+
9
+ ```text
10
+ verify payment -> call upstream -> settle only when upstream status is below 400
11
+ ```
12
+
13
+ ## Install
14
+
15
+ Python 3.10 or newer is required.
16
+
17
+ The `0.1.0` PyPI release is prepared but is not published yet. Until the
18
+ release is published, use the repository installation below.
19
+
20
+ ```bash
21
+ git clone https://github.com/Tools-touch/KiteAI-X402-Wrapper.git
22
+ cd KiteAI-X402-Wrapper
23
+ uv sync --extra dev
24
+ cp .env.example .env
25
+ kite-x402-wrapper
26
+ ```
27
+
28
+ After the PyPI release is published, the installed-package form is:
29
+
30
+ ```bash
31
+ python -m pip install kite-x402-wrapper
32
+ cp .env.example .env
33
+ kite-x402-wrapper
34
+ ```
35
+
36
+ For development from this repository:
37
+
38
+ ```bash
39
+ uv sync --extra dev
40
+ cp .env.example .env
41
+ uv run kite-x402-wrapper
42
+ ```
43
+
44
+ Then request a paid route:
45
+
46
+ ```bash
47
+ curl -i "http://localhost:8080/v1/v1/forecast?latitude=52.52&longitude=13.41&current=temperature_2m"
48
+ ```
49
+
50
+ An unpaid request returns HTTP 402 with a `PAYMENT-REQUIRED` header. The
51
+ wrapper strips the first `/v1` prefix before proxying, so the example above
52
+ reaches `https://api.open-meteo.com/v1/forecast`.
53
+
54
+ ## Configuration
55
+
56
+ | Variable | Default | Purpose |
57
+ |---|---|---|
58
+ | `PAY_TO` | required | Public EVM address receiving payments |
59
+ | `KITE_NETWORK` | `mainnet` | `mainnet` or `testnet` |
60
+ | `UPSTREAM_URL` | required | Fixed upstream HTTP(S) origin |
61
+ | `UPSTREAM_AUTH_HEADER` | `Authorization` | Optional upstream credential header |
62
+ | `UPSTREAM_AUTH_VALUE` | empty | Optional credential value, never returned to callers |
63
+ | `PRICE_USD` | `0.001` | Positive decimal USD price, at most 6 fractional digits |
64
+ | `SERVICE_DESCRIPTION` | generic description | Text included in the 402 requirements |
65
+ | `FACILITATOR_URL` | Pieverse `/v2` endpoint | HTTPS x402 facilitator base URL |
66
+ | `PORT` | `8080` | Listening port |
67
+
68
+ Start on Kite testnet. The wrapper uses pieUSD on `eip155:2368`; mainnet uses
69
+ USDC.e on `eip155:2366`. The package never needs a wallet private key.
70
+
71
+ ## Use as a library
72
+
73
+ ```python
74
+ from kite_x402_wrapper import Settings, create_app
75
+
76
+ settings = Settings.from_env()
77
+ app = create_app(settings)
78
+ ```
79
+
80
+ The application factory accepts an HTTPX client and payment components as
81
+ optional injected dependencies. Tests can therefore verify proxy and
82
+ settlement behavior without real funds or external services.
83
+
84
+ ## Safety properties
85
+
86
+ - A missing or invalid payment never reaches the upstream.
87
+ - Upstream responses with status 400 or higher are not settled.
88
+ - Upstream connection failures return 502 and are not settled.
89
+ - Payment headers are removed before proxying.
90
+ - Upstream credentials replace caller-provided values and are never returned.
91
+ - The proxy target stays on the configured upstream origin.
92
+ - Amount conversion uses `Decimal`, never binary floating point.
93
+
94
+ Because settlement happens after the handler finishes, responses are buffered
95
+ in memory by the official x402 FastAPI middleware. This template is intended
96
+ for ordinary API payloads, not unbounded downloads or streaming endpoints.
97
+
98
+ ## Quality checks
99
+
100
+ ```bash
101
+ uv run ruff check .
102
+ uv run ruff format --check .
103
+ uv run mypy
104
+ uv run pytest --cov=kite_x402_wrapper
105
+ uv build
106
+ uv run twine check dist/*
107
+ ```
108
+
109
+ ## Public deployment and paid acceptance
110
+
111
+ Kite Passport calls services from its own servers. Real paid testing requires
112
+ a public HTTPS origin; localhost and browser-gated tunnels are not sufficient.
113
+ Use a small, short-lived Passport sandbox session and verify the returned
114
+ `PAYMENT-RESPONSE` transaction reference. Never fabricate paid-call evidence.
115
+
116
+ ## License
117
+
118
+ Apache-2.0.