iicp-client 0.2.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.
- iicp_client-0.2.0/.github/workflows/ci.yml +85 -0
- iicp_client-0.2.0/.gitignore +11 -0
- iicp_client-0.2.0/CONTRIBUTING.md +16 -0
- iicp_client-0.2.0/Dockerfile +13 -0
- iicp_client-0.2.0/LICENSE +180 -0
- iicp_client-0.2.0/PKG-INFO +179 -0
- iicp_client-0.2.0/README.md +147 -0
- iicp_client-0.2.0/examples/.gitkeep +0 -0
- iicp_client-0.2.0/pyproject.toml +59 -0
- iicp_client-0.2.0/src/iicp_client/__init__.py +35 -0
- iicp_client-0.2.0/src/iicp_client/_http.py +112 -0
- iicp_client-0.2.0/src/iicp_client/client.py +248 -0
- iicp_client-0.2.0/src/iicp_client/errors.py +44 -0
- iicp_client-0.2.0/src/iicp_client/node.py +404 -0
- iicp_client-0.2.0/src/iicp_client/types.py +118 -0
- iicp_client-0.2.0/tests/__init__.py +0 -0
- iicp_client-0.2.0/tests/test_client.py +278 -0
- iicp_client-0.2.0/tests/test_serve.py +331 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
concurrency:
|
|
11
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
12
|
+
cancel-in-progress: true
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
lint:
|
|
16
|
+
name: Lint (Ruff)
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: astral-sh/ruff-action@v1
|
|
21
|
+
with:
|
|
22
|
+
args: "check src tests"
|
|
23
|
+
|
|
24
|
+
test:
|
|
25
|
+
name: Tests (pytest)
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
strategy:
|
|
28
|
+
matrix:
|
|
29
|
+
python-version: ["3.11", "3.12"]
|
|
30
|
+
steps:
|
|
31
|
+
- uses: actions/checkout@v4
|
|
32
|
+
- uses: actions/setup-python@v5
|
|
33
|
+
with:
|
|
34
|
+
python-version: ${{ matrix.python-version }}
|
|
35
|
+
cache: pip
|
|
36
|
+
cache-dependency-path: pyproject.toml
|
|
37
|
+
- name: Install dependencies
|
|
38
|
+
run: pip install -e ".[dev]" --quiet
|
|
39
|
+
- name: Run tests
|
|
40
|
+
run: pytest tests/ -v --tb=short
|
|
41
|
+
|
|
42
|
+
typecheck:
|
|
43
|
+
name: Type Check (mypy)
|
|
44
|
+
runs-on: ubuntu-latest
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/checkout@v4
|
|
47
|
+
- uses: actions/setup-python@v5
|
|
48
|
+
with:
|
|
49
|
+
python-version: "3.11"
|
|
50
|
+
cache: pip
|
|
51
|
+
cache-dependency-path: pyproject.toml
|
|
52
|
+
- name: Install dependencies + mypy
|
|
53
|
+
run: pip install -e ".[dev]" mypy --quiet
|
|
54
|
+
- name: Type check
|
|
55
|
+
run: mypy src/iicp_client --ignore-missing-imports
|
|
56
|
+
|
|
57
|
+
security:
|
|
58
|
+
name: Dependency Security Audit
|
|
59
|
+
runs-on: ubuntu-latest
|
|
60
|
+
steps:
|
|
61
|
+
- uses: actions/checkout@v4
|
|
62
|
+
- uses: actions/setup-python@v5
|
|
63
|
+
with:
|
|
64
|
+
python-version: "3.11"
|
|
65
|
+
- name: Audit dependencies
|
|
66
|
+
run: pip install pip-audit --quiet && pip-audit --requirement <(pip install -e . --dry-run 2>&1 | grep "^Would install" | sed 's/Would install //' | tr ' ' '\n' | sed 's/==/==/') || true
|
|
67
|
+
|
|
68
|
+
conformance-marks:
|
|
69
|
+
name: Conformance Mark Coverage
|
|
70
|
+
runs-on: ubuntu-latest
|
|
71
|
+
steps:
|
|
72
|
+
- uses: actions/checkout@v4
|
|
73
|
+
- name: Verify all test files reference SDK conformance marks
|
|
74
|
+
run: |
|
|
75
|
+
FAIL=0
|
|
76
|
+
for f in tests/test_*.py; do
|
|
77
|
+
if ! grep -q "SDK-0[1-9]\|SDK-1[0-9]\|ADR-016" "$f"; then
|
|
78
|
+
echo "MISSING conformance mark: $f"
|
|
79
|
+
FAIL=1
|
|
80
|
+
fi
|
|
81
|
+
done
|
|
82
|
+
if [ "$FAIL" -eq 0 ]; then
|
|
83
|
+
echo "All test files reference SDK conformance marks"
|
|
84
|
+
fi
|
|
85
|
+
exit $FAIL
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Issues and discussions for the IICP client SDK are tracked in the main IICP issue tracker:
|
|
4
|
+
|
|
5
|
+
**https://github.com/RobLe3/IICP/issues**
|
|
6
|
+
|
|
7
|
+
This repository will accept pull requests once functional code lands (v0.1.0, IICP spec v1.5 stable).
|
|
8
|
+
Until then, use the issue tracker above to:
|
|
9
|
+
|
|
10
|
+
- Report protocol bugs or ambiguities
|
|
11
|
+
- Propose SDK API design decisions
|
|
12
|
+
- Discuss integration patterns
|
|
13
|
+
|
|
14
|
+
## License
|
|
15
|
+
|
|
16
|
+
By contributing, you agree your contributions are licensed under Apache-2.0.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
FROM python:3.11-slim AS build
|
|
2
|
+
WORKDIR /app
|
|
3
|
+
COPY pyproject.toml README.md LICENSE ./
|
|
4
|
+
COPY src ./src
|
|
5
|
+
RUN pip install --no-cache-dir ".[metrics]"
|
|
6
|
+
|
|
7
|
+
FROM python:3.11-slim AS runtime
|
|
8
|
+
WORKDIR /app
|
|
9
|
+
COPY --from=build /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
|
|
10
|
+
COPY --from=build /app/src /app/src
|
|
11
|
+
ENV PYTHONPATH=/app/src
|
|
12
|
+
EXPOSE 8020
|
|
13
|
+
CMD ["python", "-c", "import asyncio; from iicp_client import IicpNode, NodeConfig; node = IicpNode(NodeConfig(node_id='docker-node', endpoint='http://localhost:8020', intent='urn:iicp:intent:llm:chat:v1')); asyncio.run(node.serve(lambda t: __import__(\"asyncio\").coroutine(lambda: {\"result\": {}})()))"]
|
|
@@ -0,0 +1,180 @@
|
|
|
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 made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other transformations
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and its Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or otherwise designated in writing by the copyright owner as
|
|
57
|
+
"Not a Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and incorporated
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or in combination with the Work to which such
|
|
78
|
+
Contribution(s) was submitted. If You institute patent litigation
|
|
79
|
+
against any entity (including a cross-claim or counterclaim in a
|
|
80
|
+
lawsuit) alleging that the Work or a Contribution incorporated within
|
|
81
|
+
the Work constitutes direct or contributory patent infringement, then
|
|
82
|
+
any patent licenses granted to You under this License for that Work
|
|
83
|
+
shall terminate as of the date such litigation is filed.
|
|
84
|
+
|
|
85
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
86
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
87
|
+
modifications, and in Source or Object form, provided that You
|
|
88
|
+
meet the following conditions:
|
|
89
|
+
|
|
90
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
91
|
+
Works a copy of this License; and
|
|
92
|
+
|
|
93
|
+
(b) You must cause any modified files to carry prominent notices
|
|
94
|
+
stating that You changed the files; and
|
|
95
|
+
|
|
96
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
97
|
+
that You distribute, all copyright, patent, trademark, and
|
|
98
|
+
attribution notices from the Source form of the Work,
|
|
99
|
+
excluding those notices that do not pertain to any part of
|
|
100
|
+
the Derivative Works; and
|
|
101
|
+
|
|
102
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
103
|
+
distribution, You must include a readable copy of the
|
|
104
|
+
attribution notices contained within such NOTICE file, in
|
|
105
|
+
at least one of the following places: within a NOTICE text
|
|
106
|
+
file distributed as part of the Derivative Works; within
|
|
107
|
+
the Source form or documentation, if provided along with the
|
|
108
|
+
Derivative Works; or, within a display generated by the
|
|
109
|
+
Derivative Works, if and wherever such third-party notices
|
|
110
|
+
normally appear. The contents of the NOTICE file are for
|
|
111
|
+
informational purposes only and do not modify the License.
|
|
112
|
+
You may add Your own attribution notices within Derivative
|
|
113
|
+
Works that You distribute, alongside or as an addendum to
|
|
114
|
+
the NOTICE text from the Work, provided that such additional
|
|
115
|
+
attribution notices cannot be construed as modifying the License.
|
|
116
|
+
|
|
117
|
+
You may add Your own license statement for Your modifications and
|
|
118
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
119
|
+
publish, distribute, sublicense, and/or sell copies of the Work,
|
|
120
|
+
and to permit persons to whom the Work is furnished to do so, subject
|
|
121
|
+
to Your separate additional terms and conditions.
|
|
122
|
+
|
|
123
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
124
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
125
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
126
|
+
this License, without any additional terms or conditions.
|
|
127
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
128
|
+
the terms of any separate license agreement you may have executed
|
|
129
|
+
with Licensor regarding such Contributions.
|
|
130
|
+
|
|
131
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
132
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
133
|
+
except as required for reasonable and customary use in describing the
|
|
134
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
135
|
+
|
|
136
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
137
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
138
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
139
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
140
|
+
implied, including, without limitation, any conditions of title,
|
|
141
|
+
non-infringement, merchantability, or fitness for a particular
|
|
142
|
+
purpose. You are solely responsible for determining the
|
|
143
|
+
appropriateness of using or reproducing the Work and assume any
|
|
144
|
+
risks associated with Your exercise of permissions under this License.
|
|
145
|
+
|
|
146
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
147
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
148
|
+
unless required by applicable law (such as deliberate and grossly
|
|
149
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
150
|
+
liable to You for damages, including any direct, indirect, special,
|
|
151
|
+
incidental, or exemplary damages of any character arising as a
|
|
152
|
+
result of this License or out of the use or inability to use the
|
|
153
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
154
|
+
work stoppage, computer failure or malfunction, or all other
|
|
155
|
+
commercial damages or losses), even if such Contributor has been
|
|
156
|
+
advised of the possibility of such damages.
|
|
157
|
+
|
|
158
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
159
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
160
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
161
|
+
or other liability obligations and/or rights consistent with this
|
|
162
|
+
License. However, in accepting such obligations, You may offer only
|
|
163
|
+
conditions fully consistent with this License to any recipient of
|
|
164
|
+
the Work.
|
|
165
|
+
|
|
166
|
+
END OF TERMS AND CONDITIONS
|
|
167
|
+
|
|
168
|
+
Copyright 2026 Rob Lemumin
|
|
169
|
+
|
|
170
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
171
|
+
you may not use this file except in compliance with the License.
|
|
172
|
+
You may obtain a copy of the License at
|
|
173
|
+
|
|
174
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
175
|
+
|
|
176
|
+
Unless required by applicable law or agreed to in writing, software
|
|
177
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
178
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
179
|
+
See the License for the specific language governing permissions and
|
|
180
|
+
limitations under the License.
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iicp-client
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Official Python client SDK for the IICP protocol
|
|
5
|
+
Project-URL: Homepage, https://iicp.network
|
|
6
|
+
Project-URL: Repository, https://github.com/RobLe3/iicp-client-python
|
|
7
|
+
Project-URL: Documentation, https://iicp.network/docs
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/RobLe3/iicp-client-python/issues
|
|
9
|
+
Author-email: IICP Contributors <claude@roblemumin.com>
|
|
10
|
+
License: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai-agents,iicp,llm,protocol,sdk
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: httpx>=0.27
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: prometheus-client>=0.20; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
27
|
+
Requires-Dist: respx>=0.21; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.8; extra == 'dev'
|
|
29
|
+
Provides-Extra: metrics
|
|
30
|
+
Requires-Dist: prometheus-client>=0.20; extra == 'metrics'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# iicp-client · Python SDK
|
|
34
|
+
|
|
35
|
+
[](https://github.com/RobLe3/iicp-client-python/actions/workflows/ci.yml)
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
[](https://iicp.network/spec)
|
|
38
|
+
[](https://pypi.org/project/iicp-client/)
|
|
39
|
+
|
|
40
|
+
Official Python client library for the [IICP protocol](https://iicp.network) — route AI agent tasks by intent across a self-organising mesh of provider nodes. No central broker. No hardcoded endpoints.
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
urn:iicp:intent:llm:chat:v1 → discover → select → submit
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install iicp-client
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Requires **Python ≥ 3.11** and [`httpx`](https://www.python-httpx.org/).
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Quickstart
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import asyncio
|
|
62
|
+
from iicp_client import IicpClient, ChatMessage
|
|
63
|
+
|
|
64
|
+
async def main():
|
|
65
|
+
client = IicpClient()
|
|
66
|
+
|
|
67
|
+
# chat_async discovers, selects best node, and submits in one call
|
|
68
|
+
response = await client.chat_async(
|
|
69
|
+
messages=[ChatMessage(role="user", content="Hello from IICP!")],
|
|
70
|
+
)
|
|
71
|
+
print(response.choices[0].message.content)
|
|
72
|
+
|
|
73
|
+
asyncio.run(main())
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Synchronous wrapper for scripts and notebooks:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from iicp_client import IicpClient, ChatMessage
|
|
80
|
+
|
|
81
|
+
client = IicpClient()
|
|
82
|
+
response = client.chat([ChatMessage(role="user", content="Hello from IICP!")])
|
|
83
|
+
print(response.choices[0].message.content)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Configuration
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from iicp_client import ClientConfig
|
|
92
|
+
|
|
93
|
+
config = ClientConfig(
|
|
94
|
+
directory_url = "https://iicp.network", # IICP directory
|
|
95
|
+
timeout_ms = 30_000, # max 120 000 (SDK-04)
|
|
96
|
+
region = "eu-central", # prefer nodes in region
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
| Field | Default | Description |
|
|
101
|
+
|-------|---------|-------------|
|
|
102
|
+
| `directory_url` | `"https://iicp.network"` | IICP directory endpoint |
|
|
103
|
+
| `timeout_ms` | `30000` | Request timeout — max 120 000 ms |
|
|
104
|
+
| `region` | `None` | Preferred node region |
|
|
105
|
+
| `max_retries` | `3` | Retry count for transient errors |
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Discover options
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from iicp_client import DiscoverOptions
|
|
113
|
+
|
|
114
|
+
node_list = await client.discover_async(
|
|
115
|
+
"urn:iicp:intent:llm:chat:v1",
|
|
116
|
+
DiscoverOptions(
|
|
117
|
+
region = "eu-central",
|
|
118
|
+
model = "phi3:mini",
|
|
119
|
+
min_reputation = 0.7,
|
|
120
|
+
limit = 5,
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
nodes = node_list.nodes # list of Node objects
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Error handling
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from iicp_client import IicpClient, IicpError, ChatMessage
|
|
132
|
+
|
|
133
|
+
client = IicpClient()
|
|
134
|
+
try:
|
|
135
|
+
response = client.chat([ChatMessage(role="user", content="hi")])
|
|
136
|
+
except IicpError as e:
|
|
137
|
+
print(f"[{e.code}] {e.message} (HTTP {e.http_status})")
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Error codes match the [IICP error reference](https://iicp.network/docs/error-reference) — e.g. `task_timeout`, `capacity_exceeded`, `no_nodes_available`.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## SDK conformance
|
|
145
|
+
|
|
146
|
+
| Rule | Description | Status |
|
|
147
|
+
|------|-------------|--------|
|
|
148
|
+
| SDK-01 | discover → select → submit pipeline with node retry | ✓ |
|
|
149
|
+
| SDK-02 | `task_id` auto-generated (UUID v4) | ✓ |
|
|
150
|
+
| SDK-03 | Intent URN pattern validation | ✓ |
|
|
151
|
+
| SDK-04 | `timeout_ms` capped at 120 000 ms | ✓ |
|
|
152
|
+
| SDK-05 | Retry on 429 / 503 with exponential back-off | ✓ |
|
|
153
|
+
| SDK-06 | W3C `traceparent` propagation | ✓ |
|
|
154
|
+
|
|
155
|
+
Conformance tier: `iicp:sdk:v1` (spec S.14) · [Request a badge](https://iicp.network/conformance)
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Development
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
pip install -e ".[dev]" # install with dev deps
|
|
163
|
+
pytest tests/ -v # run 28 unit tests
|
|
164
|
+
ruff check src tests # lint
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Links
|
|
170
|
+
|
|
171
|
+
- [Protocol spec](https://iicp.network/spec) — full IICP specification
|
|
172
|
+
- [Node setup guide](https://iicp.network/docs/node-setup) — run your own node
|
|
173
|
+
- [Error reference](https://iicp.network/docs/error-reference) — all error codes
|
|
174
|
+
- [iicp-client-typescript](https://github.com/RobLe3/iicp-client-typescript) — TypeScript SDK
|
|
175
|
+
- [iicp-client-rust](https://github.com/RobLe3/iicp-client-rust) — Rust SDK
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
Apache 2.0 · [iicp.network](https://iicp.network)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# iicp-client · Python SDK
|
|
2
|
+
|
|
3
|
+
[](https://github.com/RobLe3/iicp-client-python/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](https://iicp.network/spec)
|
|
6
|
+
[](https://pypi.org/project/iicp-client/)
|
|
7
|
+
|
|
8
|
+
Official Python client library for the [IICP protocol](https://iicp.network) — route AI agent tasks by intent across a self-organising mesh of provider nodes. No central broker. No hardcoded endpoints.
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
urn:iicp:intent:llm:chat:v1 → discover → select → submit
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install iicp-client
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Requires **Python ≥ 3.11** and [`httpx`](https://www.python-httpx.org/).
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Quickstart
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import asyncio
|
|
30
|
+
from iicp_client import IicpClient, ChatMessage
|
|
31
|
+
|
|
32
|
+
async def main():
|
|
33
|
+
client = IicpClient()
|
|
34
|
+
|
|
35
|
+
# chat_async discovers, selects best node, and submits in one call
|
|
36
|
+
response = await client.chat_async(
|
|
37
|
+
messages=[ChatMessage(role="user", content="Hello from IICP!")],
|
|
38
|
+
)
|
|
39
|
+
print(response.choices[0].message.content)
|
|
40
|
+
|
|
41
|
+
asyncio.run(main())
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Synchronous wrapper for scripts and notebooks:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from iicp_client import IicpClient, ChatMessage
|
|
48
|
+
|
|
49
|
+
client = IicpClient()
|
|
50
|
+
response = client.chat([ChatMessage(role="user", content="Hello from IICP!")])
|
|
51
|
+
print(response.choices[0].message.content)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Configuration
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from iicp_client import ClientConfig
|
|
60
|
+
|
|
61
|
+
config = ClientConfig(
|
|
62
|
+
directory_url = "https://iicp.network", # IICP directory
|
|
63
|
+
timeout_ms = 30_000, # max 120 000 (SDK-04)
|
|
64
|
+
region = "eu-central", # prefer nodes in region
|
|
65
|
+
)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Field | Default | Description |
|
|
69
|
+
|-------|---------|-------------|
|
|
70
|
+
| `directory_url` | `"https://iicp.network"` | IICP directory endpoint |
|
|
71
|
+
| `timeout_ms` | `30000` | Request timeout — max 120 000 ms |
|
|
72
|
+
| `region` | `None` | Preferred node region |
|
|
73
|
+
| `max_retries` | `3` | Retry count for transient errors |
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Discover options
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from iicp_client import DiscoverOptions
|
|
81
|
+
|
|
82
|
+
node_list = await client.discover_async(
|
|
83
|
+
"urn:iicp:intent:llm:chat:v1",
|
|
84
|
+
DiscoverOptions(
|
|
85
|
+
region = "eu-central",
|
|
86
|
+
model = "phi3:mini",
|
|
87
|
+
min_reputation = 0.7,
|
|
88
|
+
limit = 5,
|
|
89
|
+
)
|
|
90
|
+
)
|
|
91
|
+
nodes = node_list.nodes # list of Node objects
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Error handling
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from iicp_client import IicpClient, IicpError, ChatMessage
|
|
100
|
+
|
|
101
|
+
client = IicpClient()
|
|
102
|
+
try:
|
|
103
|
+
response = client.chat([ChatMessage(role="user", content="hi")])
|
|
104
|
+
except IicpError as e:
|
|
105
|
+
print(f"[{e.code}] {e.message} (HTTP {e.http_status})")
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Error codes match the [IICP error reference](https://iicp.network/docs/error-reference) — e.g. `task_timeout`, `capacity_exceeded`, `no_nodes_available`.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## SDK conformance
|
|
113
|
+
|
|
114
|
+
| Rule | Description | Status |
|
|
115
|
+
|------|-------------|--------|
|
|
116
|
+
| SDK-01 | discover → select → submit pipeline with node retry | ✓ |
|
|
117
|
+
| SDK-02 | `task_id` auto-generated (UUID v4) | ✓ |
|
|
118
|
+
| SDK-03 | Intent URN pattern validation | ✓ |
|
|
119
|
+
| SDK-04 | `timeout_ms` capped at 120 000 ms | ✓ |
|
|
120
|
+
| SDK-05 | Retry on 429 / 503 with exponential back-off | ✓ |
|
|
121
|
+
| SDK-06 | W3C `traceparent` propagation | ✓ |
|
|
122
|
+
|
|
123
|
+
Conformance tier: `iicp:sdk:v1` (spec S.14) · [Request a badge](https://iicp.network/conformance)
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pip install -e ".[dev]" # install with dev deps
|
|
131
|
+
pytest tests/ -v # run 28 unit tests
|
|
132
|
+
ruff check src tests # lint
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Links
|
|
138
|
+
|
|
139
|
+
- [Protocol spec](https://iicp.network/spec) — full IICP specification
|
|
140
|
+
- [Node setup guide](https://iicp.network/docs/node-setup) — run your own node
|
|
141
|
+
- [Error reference](https://iicp.network/docs/error-reference) — all error codes
|
|
142
|
+
- [iicp-client-typescript](https://github.com/RobLe3/iicp-client-typescript) — TypeScript SDK
|
|
143
|
+
- [iicp-client-rust](https://github.com/RobLe3/iicp-client-rust) — Rust SDK
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
Apache 2.0 · [iicp.network](https://iicp.network)
|
|
File without changes
|