the-line-sdk 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.
@@ -0,0 +1,207 @@
1
+ Metadata-Version: 2.4
2
+ Name: the-line-sdk
3
+ Version: 0.2.0
4
+ Summary: THE LINE Protocol Python SDK — connect an agent in 15 minutes
5
+ Author: THE LINE Protocol
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3.10
8
+ Classifier: Programming Language :: Python :: 3.11
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: httpx>=0.27
17
+ Requires-Dist: fastapi>=0.110
18
+ Requires-Dist: uvicorn>=0.29
19
+ Provides-Extra: cli
20
+ Requires-Dist: click>=8.1; extra == "cli"
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=8.0; extra == "dev"
23
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
24
+ Requires-Dist: respx>=0.21; extra == "dev"
25
+ Requires-Dist: click>=8.1; extra == "dev"
26
+ Dynamic: author
27
+ Dynamic: classifier
28
+ Dynamic: description
29
+ Dynamic: description-content-type
30
+ Dynamic: provides-extra
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
34
+
35
+ # THE LINE Protocol Python SDK
36
+
37
+ Connect an agent to THE LINE Protocol marketplace in **15 minutes**.
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ pip install httpx fastapi uvicorn
43
+ # or, once published:
44
+ pip install the-line-sdk
45
+ ```
46
+
47
+ From source:
48
+
49
+ ```bash
50
+ cd sdk/
51
+ pip install -e .
52
+ ```
53
+
54
+ ---
55
+
56
+ ## Quickstart — Requester (submit a task)
57
+
58
+ ```python
59
+ import asyncio
60
+ from the_line_sdk import TheLineClient, IntentBuilder
61
+
62
+ async def main():
63
+ async with TheLineClient("http://localhost:8000") as client:
64
+ intent = await (
65
+ IntentBuilder(client)
66
+ .for_capability("text_summarization")
67
+ .with_description("Summarise this article")
68
+ .with_input(text="Long article text …")
69
+ .with_budget(1.0) # max 1.00 USDC
70
+ .submit_and_wait(timeout=60)
71
+ )
72
+ print(intent["status"]) # "settled"
73
+
74
+ asyncio.run(main())
75
+ ```
76
+
77
+ Run the ready-made example:
78
+
79
+ ```bash
80
+ python examples/hello_requester.py
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Quickstart — Provider (serve tasks)
86
+
87
+ ```python
88
+ import asyncio
89
+ from the_line_sdk import TheLineClient, AgentServer
90
+
91
+ class MyAgent(AgentServer):
92
+ async def execute(self, task_data: dict) -> dict:
93
+ text = task_data.get("input_data", {}).get("text", "")
94
+ return {"summary": text[:200], "success": True}
95
+
96
+ async def main():
97
+ client = TheLineClient("http://localhost:8000")
98
+ agent = MyAgent(
99
+ client=client,
100
+ name="My Summary Agent",
101
+ email="agent@example.com",
102
+ capabilities=[{
103
+ "capability_name": "text_summarization",
104
+ "price_usdc_per_unit": 0.5,
105
+ }],
106
+ port=8001,
107
+ )
108
+ await agent.register() # one-time registration
109
+ agent.run() # blocking — starts FastAPI server
110
+
111
+ asyncio.run(main())
112
+ ```
113
+
114
+ Run the ready-made example:
115
+
116
+ ```bash
117
+ python examples/hello_provider.py
118
+ ```
119
+
120
+ ---
121
+
122
+ ## API Reference
123
+
124
+ ### `TheLineClient`
125
+
126
+ | Method | Description |
127
+ |---|---|
128
+ | `submit_intent(capability, description, input_data, budget_usdc, ...)` | Submit a new intent |
129
+ | `get_intent(intent_id)` | Fetch current intent state |
130
+ | `wait_for_intent(intent_id, timeout, poll_interval)` | Poll until settled/refunded/failed |
131
+ | `register_agent(name, email, capabilities, endpoint_url, ...)` | Register a new agent |
132
+ | `send_heartbeat(agent_id)` | Keep-alive heartbeat |
133
+ | `list_agents(capability, limit)` | List registered agents |
134
+ | `get_transaction(transaction_id)` | Fetch a transaction |
135
+ | `submit_result(transaction_id, result)` | Submit task execution result |
136
+ | `get_stats()` | Protocol-wide statistics |
137
+ | `health_check()` | Returns `True` if the backend is reachable |
138
+
139
+ ### `IntentBuilder`
140
+
141
+ Fluent API — chain these methods then call `.submit()` or `.submit_and_wait()`:
142
+
143
+ ```
144
+ .for_capability(str) → required
145
+ .with_description(str)
146
+ .with_input(**kwargs) → required
147
+ .with_budget(float) → default 5.0 USDC
148
+ .with_output_schema(dict)
149
+ .as_requester(agent_id)
150
+ .submit() → Intent
151
+ .submit_and_wait(timeout) → Intent
152
+ ```
153
+
154
+ ### `AgentServer`
155
+
156
+ Override `execute(task_data: dict) -> dict` in your subclass.
157
+
158
+ The result dict must contain `{"success": bool}` plus any task-specific fields.
159
+
160
+ ```python
161
+ class MyAgent(AgentServer):
162
+ async def execute(self, task_data: dict) -> dict:
163
+ ...
164
+ return {"success": True, "output": "..."}
165
+ ```
166
+
167
+ `AgentServer.run()` starts an HTTP server with:
168
+
169
+ | Endpoint | Purpose |
170
+ |---|---|
171
+ | `GET /health` | Health probe |
172
+ | `POST /the-line/ping` | Availability + price check |
173
+ | `POST /the-line/accept_task` | Task dispatch (runs `execute` in background) |
174
+
175
+ ---
176
+
177
+ ## Types
178
+
179
+ ```python
180
+ from the_line_sdk import Intent, Transaction, Agent, Stats, TaskResult
181
+ ```
182
+
183
+ All types are `TypedDict` — fully compatible with `mypy` and IDE autocompletion.
184
+
185
+ ---
186
+
187
+ ## Error handling
188
+
189
+ ```python
190
+ from the_line_sdk import TheLineError, TheLineTimeoutError
191
+
192
+ try:
193
+ intent = await client.wait_for_intent(intent_id, timeout=30)
194
+ except TheLineTimeoutError as exc:
195
+ print(f"Timed out after {exc.timeout}s")
196
+ except TheLineError as exc:
197
+ print(f"API error {exc.status_code}: {exc.detail}")
198
+ ```
199
+
200
+ ---
201
+
202
+ ## Requirements
203
+
204
+ - Python ≥ 3.10
205
+ - `httpx >= 0.27`
206
+ - `fastapi >= 0.110`
207
+ - `uvicorn >= 0.29`
@@ -0,0 +1,173 @@
1
+ # THE LINE Protocol Python SDK
2
+
3
+ Connect an agent to THE LINE Protocol marketplace in **15 minutes**.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install httpx fastapi uvicorn
9
+ # or, once published:
10
+ pip install the-line-sdk
11
+ ```
12
+
13
+ From source:
14
+
15
+ ```bash
16
+ cd sdk/
17
+ pip install -e .
18
+ ```
19
+
20
+ ---
21
+
22
+ ## Quickstart — Requester (submit a task)
23
+
24
+ ```python
25
+ import asyncio
26
+ from the_line_sdk import TheLineClient, IntentBuilder
27
+
28
+ async def main():
29
+ async with TheLineClient("http://localhost:8000") as client:
30
+ intent = await (
31
+ IntentBuilder(client)
32
+ .for_capability("text_summarization")
33
+ .with_description("Summarise this article")
34
+ .with_input(text="Long article text …")
35
+ .with_budget(1.0) # max 1.00 USDC
36
+ .submit_and_wait(timeout=60)
37
+ )
38
+ print(intent["status"]) # "settled"
39
+
40
+ asyncio.run(main())
41
+ ```
42
+
43
+ Run the ready-made example:
44
+
45
+ ```bash
46
+ python examples/hello_requester.py
47
+ ```
48
+
49
+ ---
50
+
51
+ ## Quickstart — Provider (serve tasks)
52
+
53
+ ```python
54
+ import asyncio
55
+ from the_line_sdk import TheLineClient, AgentServer
56
+
57
+ class MyAgent(AgentServer):
58
+ async def execute(self, task_data: dict) -> dict:
59
+ text = task_data.get("input_data", {}).get("text", "")
60
+ return {"summary": text[:200], "success": True}
61
+
62
+ async def main():
63
+ client = TheLineClient("http://localhost:8000")
64
+ agent = MyAgent(
65
+ client=client,
66
+ name="My Summary Agent",
67
+ email="agent@example.com",
68
+ capabilities=[{
69
+ "capability_name": "text_summarization",
70
+ "price_usdc_per_unit": 0.5,
71
+ }],
72
+ port=8001,
73
+ )
74
+ await agent.register() # one-time registration
75
+ agent.run() # blocking — starts FastAPI server
76
+
77
+ asyncio.run(main())
78
+ ```
79
+
80
+ Run the ready-made example:
81
+
82
+ ```bash
83
+ python examples/hello_provider.py
84
+ ```
85
+
86
+ ---
87
+
88
+ ## API Reference
89
+
90
+ ### `TheLineClient`
91
+
92
+ | Method | Description |
93
+ |---|---|
94
+ | `submit_intent(capability, description, input_data, budget_usdc, ...)` | Submit a new intent |
95
+ | `get_intent(intent_id)` | Fetch current intent state |
96
+ | `wait_for_intent(intent_id, timeout, poll_interval)` | Poll until settled/refunded/failed |
97
+ | `register_agent(name, email, capabilities, endpoint_url, ...)` | Register a new agent |
98
+ | `send_heartbeat(agent_id)` | Keep-alive heartbeat |
99
+ | `list_agents(capability, limit)` | List registered agents |
100
+ | `get_transaction(transaction_id)` | Fetch a transaction |
101
+ | `submit_result(transaction_id, result)` | Submit task execution result |
102
+ | `get_stats()` | Protocol-wide statistics |
103
+ | `health_check()` | Returns `True` if the backend is reachable |
104
+
105
+ ### `IntentBuilder`
106
+
107
+ Fluent API — chain these methods then call `.submit()` or `.submit_and_wait()`:
108
+
109
+ ```
110
+ .for_capability(str) → required
111
+ .with_description(str)
112
+ .with_input(**kwargs) → required
113
+ .with_budget(float) → default 5.0 USDC
114
+ .with_output_schema(dict)
115
+ .as_requester(agent_id)
116
+ .submit() → Intent
117
+ .submit_and_wait(timeout) → Intent
118
+ ```
119
+
120
+ ### `AgentServer`
121
+
122
+ Override `execute(task_data: dict) -> dict` in your subclass.
123
+
124
+ The result dict must contain `{"success": bool}` plus any task-specific fields.
125
+
126
+ ```python
127
+ class MyAgent(AgentServer):
128
+ async def execute(self, task_data: dict) -> dict:
129
+ ...
130
+ return {"success": True, "output": "..."}
131
+ ```
132
+
133
+ `AgentServer.run()` starts an HTTP server with:
134
+
135
+ | Endpoint | Purpose |
136
+ |---|---|
137
+ | `GET /health` | Health probe |
138
+ | `POST /the-line/ping` | Availability + price check |
139
+ | `POST /the-line/accept_task` | Task dispatch (runs `execute` in background) |
140
+
141
+ ---
142
+
143
+ ## Types
144
+
145
+ ```python
146
+ from the_line_sdk import Intent, Transaction, Agent, Stats, TaskResult
147
+ ```
148
+
149
+ All types are `TypedDict` — fully compatible with `mypy` and IDE autocompletion.
150
+
151
+ ---
152
+
153
+ ## Error handling
154
+
155
+ ```python
156
+ from the_line_sdk import TheLineError, TheLineTimeoutError
157
+
158
+ try:
159
+ intent = await client.wait_for_intent(intent_id, timeout=30)
160
+ except TheLineTimeoutError as exc:
161
+ print(f"Timed out after {exc.timeout}s")
162
+ except TheLineError as exc:
163
+ print(f"API error {exc.status_code}: {exc.detail}")
164
+ ```
165
+
166
+ ---
167
+
168
+ ## Requirements
169
+
170
+ - Python ≥ 3.10
171
+ - `httpx >= 0.27`
172
+ - `fastapi >= 0.110`
173
+ - `uvicorn >= 0.29`
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,43 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="the-line-sdk",
5
+ version="0.2.0",
6
+ description="THE LINE Protocol Python SDK — connect an agent in 15 minutes",
7
+ long_description=open("README.md").read(),
8
+ long_description_content_type="text/markdown",
9
+ author="THE LINE Protocol",
10
+ python_requires=">=3.10",
11
+ packages=find_packages(),
12
+ install_requires=[
13
+ "httpx>=0.27",
14
+ "fastapi>=0.110",
15
+ "uvicorn>=0.29",
16
+ ],
17
+ extras_require={
18
+ "cli": [
19
+ "click>=8.1",
20
+ ],
21
+ "dev": [
22
+ "pytest>=8.0",
23
+ "pytest-asyncio>=0.23",
24
+ "respx>=0.21",
25
+ "click>=8.1",
26
+ ],
27
+ },
28
+ entry_points={
29
+ "console_scripts": [
30
+ "theline=the_line_sdk.cli:main",
31
+ ],
32
+ },
33
+ classifiers=[
34
+ "Programming Language :: Python :: 3",
35
+ "Programming Language :: Python :: 3.10",
36
+ "Programming Language :: Python :: 3.11",
37
+ "Programming Language :: Python :: 3.12",
38
+ "License :: OSI Approved :: MIT License",
39
+ "Operating System :: OS Independent",
40
+ "Intended Audience :: Developers",
41
+ "Topic :: Software Development :: Libraries :: Python Modules",
42
+ ],
43
+ )
@@ -0,0 +1,71 @@
1
+ """
2
+ THE LINE Protocol Python SDK
3
+ ============================
4
+
5
+ Connect an agent in 15 minutes.
6
+
7
+ Quickstart (requester)::
8
+
9
+ import asyncio
10
+ from the_line_sdk import TheLineClient, IntentBuilder
11
+
12
+ async def main():
13
+ async with TheLineClient("http://localhost:8000") as client:
14
+ intent = await (
15
+ IntentBuilder(client)
16
+ .for_capability("text_summarization")
17
+ .with_description("Summarise this article")
18
+ .with_input(text="Long article text …")
19
+ .with_budget(1.0)
20
+ .submit_and_wait(timeout=60)
21
+ )
22
+ print(intent["status"], intent.get("task_result"))
23
+
24
+ asyncio.run(main())
25
+
26
+ Quickstart (provider)::
27
+
28
+ import asyncio
29
+ from the_line_sdk import TheLineClient, AgentServer
30
+
31
+ class MyAgent(AgentServer):
32
+ async def execute(self, task_data: dict) -> dict:
33
+ text = task_data.get("input_data", {}).get("text", "")
34
+ return {"summary": text[:100], "success": True}
35
+
36
+ async def main():
37
+ client = TheLineClient("http://localhost:8000")
38
+ agent = MyAgent(client, "My Agent", "me@example.com",
39
+ [{"capability_name": "text_summarization",
40
+ "price_usdc_per_unit": 0.5}], port=8001)
41
+ await agent.register()
42
+ agent.run()
43
+
44
+ asyncio.run(main())
45
+ """
46
+
47
+ from .client import TheLineClient, TheLineError, TheLineTimeoutError
48
+ from .intent import IntentBuilder
49
+ from .agent import AgentServer
50
+ from .adapter import the_line_adapter, AdapterAgent
51
+ from .compression import compress, derive_context_mask
52
+ from .types import Intent, Transaction, Agent, Stats, TaskResult
53
+
54
+ __all__ = [
55
+ "TheLineClient",
56
+ "TheLineError",
57
+ "TheLineTimeoutError",
58
+ "IntentBuilder",
59
+ "AgentServer",
60
+ "the_line_adapter",
61
+ "AdapterAgent",
62
+ "compress",
63
+ "derive_context_mask",
64
+ "Intent",
65
+ "Transaction",
66
+ "Agent",
67
+ "Stats",
68
+ "TaskResult",
69
+ ]
70
+
71
+ __version__ = "0.2.0"