xache 5.0.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.
- xache-5.0.0/PKG-INFO +337 -0
- xache-5.0.0/README.md +293 -0
- xache-5.0.0/pyproject.toml +68 -0
- xache-5.0.0/setup.cfg +4 -0
- xache-5.0.0/setup.py +54 -0
- xache-5.0.0/xache/__init__.py +142 -0
- xache-5.0.0/xache/client.py +331 -0
- xache-5.0.0/xache/crypto/__init__.py +17 -0
- xache-5.0.0/xache/crypto/signing.py +244 -0
- xache-5.0.0/xache/crypto/wallet.py +240 -0
- xache-5.0.0/xache/errors.py +184 -0
- xache-5.0.0/xache/payment/__init__.py +5 -0
- xache-5.0.0/xache/payment/handler.py +244 -0
- xache-5.0.0/xache/services/__init__.py +29 -0
- xache-5.0.0/xache/services/budget.py +285 -0
- xache-5.0.0/xache/services/collective.py +174 -0
- xache-5.0.0/xache/services/extraction.py +173 -0
- xache-5.0.0/xache/services/facilitator.py +296 -0
- xache-5.0.0/xache/services/identity.py +415 -0
- xache-5.0.0/xache/services/memory.py +401 -0
- xache-5.0.0/xache/services/owner.py +293 -0
- xache-5.0.0/xache/services/receipts.py +202 -0
- xache-5.0.0/xache/services/reputation.py +274 -0
- xache-5.0.0/xache/services/royalty.py +290 -0
- xache-5.0.0/xache/services/sessions.py +268 -0
- xache-5.0.0/xache/services/workspaces.py +447 -0
- xache-5.0.0/xache/types.py +399 -0
- xache-5.0.0/xache/utils/__init__.py +5 -0
- xache-5.0.0/xache/utils/cache.py +214 -0
- xache-5.0.0/xache/utils/http.py +209 -0
- xache-5.0.0/xache/utils/retry.py +101 -0
- xache-5.0.0/xache.egg-info/PKG-INFO +337 -0
- xache-5.0.0/xache.egg-info/SOURCES.txt +34 -0
- xache-5.0.0/xache.egg-info/dependency_links.txt +1 -0
- xache-5.0.0/xache.egg-info/requires.txt +18 -0
- xache-5.0.0/xache.egg-info/top_level.txt +1 -0
xache-5.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xache
|
|
3
|
+
Version: 5.0.0
|
|
4
|
+
Summary: Official Python SDK for Xache Protocol
|
|
5
|
+
Home-page: https://github.com/xache-ai/xache-protocol
|
|
6
|
+
Author: Xache Protocol
|
|
7
|
+
Author-email: Xache Protocol <dev@xache.xyz>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://xache.xyz
|
|
10
|
+
Project-URL: Documentation, https://docs.xache.xyz
|
|
11
|
+
Project-URL: Repository, https://github.com/oliveskin/xache
|
|
12
|
+
Project-URL: Bug Reports, https://github.com/oliveskin/xache/issues
|
|
13
|
+
Keywords: xache,ai,agent,memory,blockchain,decentralized
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
26
|
+
Requires-Dist: typing-extensions>=4.0.0
|
|
27
|
+
Requires-Dist: mnemonic>=0.20
|
|
28
|
+
Requires-Dist: eth-account>=0.10.0
|
|
29
|
+
Requires-Dist: bip-utils>=2.9.0
|
|
30
|
+
Requires-Dist: PyNaCl>=1.5.0
|
|
31
|
+
Requires-Dist: base58>=2.1.1
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pylint>=2.17.0; extra == "dev"
|
|
39
|
+
Provides-Extra: encryption
|
|
40
|
+
Requires-Dist: PyNaCl>=1.5.0; extra == "encryption"
|
|
41
|
+
Dynamic: author
|
|
42
|
+
Dynamic: home-page
|
|
43
|
+
Dynamic: requires-python
|
|
44
|
+
|
|
45
|
+
# Xache Protocol Python SDK
|
|
46
|
+
|
|
47
|
+
Official Python SDK for [Xache Protocol](https://xache.ai) - decentralized agent memory and collective intelligence marketplace.
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
✅ **Async/Await** - Full asyncio support for concurrent operations
|
|
52
|
+
✅ **Type Hints** - Complete type annotations for better IDE support
|
|
53
|
+
✅ **Authentication** - Automatic request signing per protocol spec
|
|
54
|
+
✅ **Payment Flow** - Built-in 402 payment handling (manual or Coinbase Commerce)
|
|
55
|
+
✅ **Encryption** - Client-side encryption for memory storage
|
|
56
|
+
✅ **Error Handling** - Typed exceptions with automatic retry logic
|
|
57
|
+
✅ **Budget Management** - Track and control spending limits
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install xache
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
With encryption support:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install xache[encryption]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Quick Start
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import asyncio
|
|
75
|
+
from xache import XacheClient
|
|
76
|
+
|
|
77
|
+
async def main():
|
|
78
|
+
# Initialize client
|
|
79
|
+
async with XacheClient(
|
|
80
|
+
api_url="https://api.xache.xyz",
|
|
81
|
+
did="did:agent:evm:0xYourWalletAddress",
|
|
82
|
+
private_key="0x...",
|
|
83
|
+
) as client:
|
|
84
|
+
# Register identity
|
|
85
|
+
identity = await client.identity.register(
|
|
86
|
+
wallet_address="0xYourWalletAddress",
|
|
87
|
+
key_type="evm",
|
|
88
|
+
chain="base",
|
|
89
|
+
)
|
|
90
|
+
print(f"DID: {identity.did}")
|
|
91
|
+
|
|
92
|
+
asyncio.run(main())
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Usage Examples
|
|
96
|
+
|
|
97
|
+
### Memory Storage
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
# Store encrypted memory (automatic encryption + 402 payment)
|
|
101
|
+
memory = await client.memory.store(
|
|
102
|
+
data={
|
|
103
|
+
"context": "user preferences",
|
|
104
|
+
"theme": "dark",
|
|
105
|
+
"language": "en",
|
|
106
|
+
},
|
|
107
|
+
storage_tier="hot",
|
|
108
|
+
)
|
|
109
|
+
print(f"Memory ID: {memory.memory_id}")
|
|
110
|
+
|
|
111
|
+
# Retrieve memory (automatic decryption + 402 payment)
|
|
112
|
+
retrieved = await client.memory.retrieve(memory_id=memory.memory_id)
|
|
113
|
+
print(f"Data: {retrieved.data}")
|
|
114
|
+
|
|
115
|
+
# Delete memory (free)
|
|
116
|
+
await client.memory.delete(memory.memory_id)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Collective Intelligence
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
# Contribute a heuristic (automatic 402 payment)
|
|
123
|
+
heuristic = await client.collective.contribute(
|
|
124
|
+
pattern="Use async/await for cleaner async code in Python",
|
|
125
|
+
domain="python",
|
|
126
|
+
tags=["async", "best-practices", "readability"],
|
|
127
|
+
context_type="code-review",
|
|
128
|
+
)
|
|
129
|
+
print(f"Heuristic ID: {heuristic.heuristic_id}")
|
|
130
|
+
|
|
131
|
+
# Query collective (automatic 402 payment)
|
|
132
|
+
results = await client.collective.query(
|
|
133
|
+
query_text="How to optimize database queries in Python",
|
|
134
|
+
domain="python",
|
|
135
|
+
limit=10,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
for match in results.matches:
|
|
139
|
+
print(f"Pattern: {match.pattern}")
|
|
140
|
+
print(f"Score: {match.relevance_score}")
|
|
141
|
+
print(f"Royalty: ${match.royalty_amount}")
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Budget Management
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
# Check budget status
|
|
148
|
+
budget = await client.budget.get_status()
|
|
149
|
+
print(f"Limit: ${budget.limit_cents / 100}")
|
|
150
|
+
print(f"Spent: ${budget.spent_cents / 100}")
|
|
151
|
+
print(f"Remaining: ${budget.remaining_cents / 100}")
|
|
152
|
+
print(f"Usage: {budget.percentage_used:.1f}%")
|
|
153
|
+
|
|
154
|
+
# Update budget limit
|
|
155
|
+
await client.budget.update_limit(5000) # $50/month
|
|
156
|
+
|
|
157
|
+
# Check if you can afford an operation
|
|
158
|
+
can_afford = await client.budget.can_afford(100) # 100 cents = $1
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Receipts & Analytics
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
# List receipts
|
|
165
|
+
result = await client.receipts.list(limit=20, offset=0)
|
|
166
|
+
for receipt in result["receipts"]:
|
|
167
|
+
print(f"{receipt.operation}: ${receipt.amount_usd}")
|
|
168
|
+
|
|
169
|
+
# Get Merkle proof for verification
|
|
170
|
+
proof = await client.receipts.get_proof("receipt_abc123")
|
|
171
|
+
print(f"Merkle Root: {proof.merkle_root}")
|
|
172
|
+
|
|
173
|
+
# Get usage analytics
|
|
174
|
+
analytics = await client.receipts.get_analytics(
|
|
175
|
+
start_date="2024-01-01",
|
|
176
|
+
end_date="2024-01-31",
|
|
177
|
+
)
|
|
178
|
+
print(f"Total spent: ${analytics.total_spent}")
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Configuration
|
|
182
|
+
|
|
183
|
+
### Basic Configuration
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
client = XacheClient(
|
|
187
|
+
api_url="https://api.xache.xyz",
|
|
188
|
+
did="did:agent:evm:0xYourWalletAddress",
|
|
189
|
+
private_key="0x...",
|
|
190
|
+
timeout=30, # Optional: request timeout in seconds
|
|
191
|
+
debug=False, # Optional: enable debug logging
|
|
192
|
+
)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Payment Configuration
|
|
196
|
+
|
|
197
|
+
#### Manual Payment (Default)
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
client = XacheClient(
|
|
201
|
+
# ... basic config
|
|
202
|
+
payment_provider={
|
|
203
|
+
"type": "manual",
|
|
204
|
+
},
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
# When payment is required, SDK will prompt you in console
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### Coinbase Commerce
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
client = XacheClient(
|
|
214
|
+
# ... basic config
|
|
215
|
+
payment_provider={
|
|
216
|
+
"type": "coinbase-commerce",
|
|
217
|
+
"api_key": "YOUR_COINBASE_API_KEY",
|
|
218
|
+
},
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
# Payments will be handled automatically via Coinbase Commerce
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Error Handling
|
|
225
|
+
|
|
226
|
+
The SDK provides typed errors for all API error codes:
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
from xache import (
|
|
230
|
+
XacheError,
|
|
231
|
+
UnauthenticatedError,
|
|
232
|
+
PaymentRequiredError,
|
|
233
|
+
RateLimitedError,
|
|
234
|
+
BudgetExceededError,
|
|
235
|
+
InvalidInputError,
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
try:
|
|
239
|
+
await client.memory.store(data=data, storage_tier="hot")
|
|
240
|
+
except PaymentRequiredError as e:
|
|
241
|
+
print(f"Payment required: ${e.amount}")
|
|
242
|
+
print(f"Challenge ID: {e.challenge_id}")
|
|
243
|
+
except RateLimitedError as e:
|
|
244
|
+
print(f"Rate limited. Retry at: {e.reset_at}")
|
|
245
|
+
except BudgetExceededError as e:
|
|
246
|
+
print("Budget exceeded")
|
|
247
|
+
except InvalidInputError as e:
|
|
248
|
+
print(f"Invalid input: {e.message}")
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Context Manager
|
|
252
|
+
|
|
253
|
+
Always use the client as an async context manager to ensure proper cleanup:
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
async with XacheClient(...) as client:
|
|
257
|
+
# Your code here
|
|
258
|
+
pass
|
|
259
|
+
# HTTP session automatically closed
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Or manually manage the lifecycle:
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
client = XacheClient(...)
|
|
266
|
+
try:
|
|
267
|
+
# Your code here
|
|
268
|
+
pass
|
|
269
|
+
finally:
|
|
270
|
+
await client.close()
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## API Reference
|
|
274
|
+
|
|
275
|
+
### XacheClient
|
|
276
|
+
|
|
277
|
+
Main client class for interacting with Xache Protocol.
|
|
278
|
+
|
|
279
|
+
#### Properties
|
|
280
|
+
|
|
281
|
+
- `client.identity` - Identity registration
|
|
282
|
+
- `client.memory` - Memory storage and retrieval
|
|
283
|
+
- `client.collective` - Collective intelligence marketplace
|
|
284
|
+
- `client.budget` - Budget management
|
|
285
|
+
- `client.receipts` - Receipt access and analytics
|
|
286
|
+
|
|
287
|
+
### Types
|
|
288
|
+
|
|
289
|
+
All request/response types are available:
|
|
290
|
+
|
|
291
|
+
```python
|
|
292
|
+
from xache import (
|
|
293
|
+
RegisterIdentityRequest,
|
|
294
|
+
RegisterIdentityResponse,
|
|
295
|
+
StoreMemoryRequest,
|
|
296
|
+
StoreMemoryResponse,
|
|
297
|
+
QueryCollectiveRequest,
|
|
298
|
+
BudgetStatus,
|
|
299
|
+
Receipt,
|
|
300
|
+
)
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Development
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
# Install with dev dependencies
|
|
307
|
+
pip install -e ".[dev]"
|
|
308
|
+
|
|
309
|
+
# Run tests
|
|
310
|
+
pytest
|
|
311
|
+
|
|
312
|
+
# Run type checking
|
|
313
|
+
mypy xache
|
|
314
|
+
|
|
315
|
+
# Format code
|
|
316
|
+
black xache
|
|
317
|
+
|
|
318
|
+
# Lint
|
|
319
|
+
pylint xache
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Requirements
|
|
323
|
+
|
|
324
|
+
- Python 3.8+
|
|
325
|
+
- aiohttp
|
|
326
|
+
- typing-extensions
|
|
327
|
+
|
|
328
|
+
## License
|
|
329
|
+
|
|
330
|
+
MIT
|
|
331
|
+
|
|
332
|
+
## Links
|
|
333
|
+
|
|
334
|
+
- [Documentation](https://docs.xache.ai)
|
|
335
|
+
- [Protocol Specification](https://github.com/xache-ai/xache-protocol)
|
|
336
|
+
- [API Reference](https://api.xache.xyz/docs)
|
|
337
|
+
- [Discord](https://discord.gg/xache)
|
xache-5.0.0/README.md
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
# Xache Protocol Python SDK
|
|
2
|
+
|
|
3
|
+
Official Python SDK for [Xache Protocol](https://xache.ai) - decentralized agent memory and collective intelligence marketplace.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
✅ **Async/Await** - Full asyncio support for concurrent operations
|
|
8
|
+
✅ **Type Hints** - Complete type annotations for better IDE support
|
|
9
|
+
✅ **Authentication** - Automatic request signing per protocol spec
|
|
10
|
+
✅ **Payment Flow** - Built-in 402 payment handling (manual or Coinbase Commerce)
|
|
11
|
+
✅ **Encryption** - Client-side encryption for memory storage
|
|
12
|
+
✅ **Error Handling** - Typed exceptions with automatic retry logic
|
|
13
|
+
✅ **Budget Management** - Track and control spending limits
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install xache
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
With encryption support:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install xache[encryption]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import asyncio
|
|
31
|
+
from xache import XacheClient
|
|
32
|
+
|
|
33
|
+
async def main():
|
|
34
|
+
# Initialize client
|
|
35
|
+
async with XacheClient(
|
|
36
|
+
api_url="https://api.xache.xyz",
|
|
37
|
+
did="did:agent:evm:0xYourWalletAddress",
|
|
38
|
+
private_key="0x...",
|
|
39
|
+
) as client:
|
|
40
|
+
# Register identity
|
|
41
|
+
identity = await client.identity.register(
|
|
42
|
+
wallet_address="0xYourWalletAddress",
|
|
43
|
+
key_type="evm",
|
|
44
|
+
chain="base",
|
|
45
|
+
)
|
|
46
|
+
print(f"DID: {identity.did}")
|
|
47
|
+
|
|
48
|
+
asyncio.run(main())
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage Examples
|
|
52
|
+
|
|
53
|
+
### Memory Storage
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
# Store encrypted memory (automatic encryption + 402 payment)
|
|
57
|
+
memory = await client.memory.store(
|
|
58
|
+
data={
|
|
59
|
+
"context": "user preferences",
|
|
60
|
+
"theme": "dark",
|
|
61
|
+
"language": "en",
|
|
62
|
+
},
|
|
63
|
+
storage_tier="hot",
|
|
64
|
+
)
|
|
65
|
+
print(f"Memory ID: {memory.memory_id}")
|
|
66
|
+
|
|
67
|
+
# Retrieve memory (automatic decryption + 402 payment)
|
|
68
|
+
retrieved = await client.memory.retrieve(memory_id=memory.memory_id)
|
|
69
|
+
print(f"Data: {retrieved.data}")
|
|
70
|
+
|
|
71
|
+
# Delete memory (free)
|
|
72
|
+
await client.memory.delete(memory.memory_id)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Collective Intelligence
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
# Contribute a heuristic (automatic 402 payment)
|
|
79
|
+
heuristic = await client.collective.contribute(
|
|
80
|
+
pattern="Use async/await for cleaner async code in Python",
|
|
81
|
+
domain="python",
|
|
82
|
+
tags=["async", "best-practices", "readability"],
|
|
83
|
+
context_type="code-review",
|
|
84
|
+
)
|
|
85
|
+
print(f"Heuristic ID: {heuristic.heuristic_id}")
|
|
86
|
+
|
|
87
|
+
# Query collective (automatic 402 payment)
|
|
88
|
+
results = await client.collective.query(
|
|
89
|
+
query_text="How to optimize database queries in Python",
|
|
90
|
+
domain="python",
|
|
91
|
+
limit=10,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
for match in results.matches:
|
|
95
|
+
print(f"Pattern: {match.pattern}")
|
|
96
|
+
print(f"Score: {match.relevance_score}")
|
|
97
|
+
print(f"Royalty: ${match.royalty_amount}")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Budget Management
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
# Check budget status
|
|
104
|
+
budget = await client.budget.get_status()
|
|
105
|
+
print(f"Limit: ${budget.limit_cents / 100}")
|
|
106
|
+
print(f"Spent: ${budget.spent_cents / 100}")
|
|
107
|
+
print(f"Remaining: ${budget.remaining_cents / 100}")
|
|
108
|
+
print(f"Usage: {budget.percentage_used:.1f}%")
|
|
109
|
+
|
|
110
|
+
# Update budget limit
|
|
111
|
+
await client.budget.update_limit(5000) # $50/month
|
|
112
|
+
|
|
113
|
+
# Check if you can afford an operation
|
|
114
|
+
can_afford = await client.budget.can_afford(100) # 100 cents = $1
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Receipts & Analytics
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
# List receipts
|
|
121
|
+
result = await client.receipts.list(limit=20, offset=0)
|
|
122
|
+
for receipt in result["receipts"]:
|
|
123
|
+
print(f"{receipt.operation}: ${receipt.amount_usd}")
|
|
124
|
+
|
|
125
|
+
# Get Merkle proof for verification
|
|
126
|
+
proof = await client.receipts.get_proof("receipt_abc123")
|
|
127
|
+
print(f"Merkle Root: {proof.merkle_root}")
|
|
128
|
+
|
|
129
|
+
# Get usage analytics
|
|
130
|
+
analytics = await client.receipts.get_analytics(
|
|
131
|
+
start_date="2024-01-01",
|
|
132
|
+
end_date="2024-01-31",
|
|
133
|
+
)
|
|
134
|
+
print(f"Total spent: ${analytics.total_spent}")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Configuration
|
|
138
|
+
|
|
139
|
+
### Basic Configuration
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
client = XacheClient(
|
|
143
|
+
api_url="https://api.xache.xyz",
|
|
144
|
+
did="did:agent:evm:0xYourWalletAddress",
|
|
145
|
+
private_key="0x...",
|
|
146
|
+
timeout=30, # Optional: request timeout in seconds
|
|
147
|
+
debug=False, # Optional: enable debug logging
|
|
148
|
+
)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Payment Configuration
|
|
152
|
+
|
|
153
|
+
#### Manual Payment (Default)
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
client = XacheClient(
|
|
157
|
+
# ... basic config
|
|
158
|
+
payment_provider={
|
|
159
|
+
"type": "manual",
|
|
160
|
+
},
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
# When payment is required, SDK will prompt you in console
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### Coinbase Commerce
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
client = XacheClient(
|
|
170
|
+
# ... basic config
|
|
171
|
+
payment_provider={
|
|
172
|
+
"type": "coinbase-commerce",
|
|
173
|
+
"api_key": "YOUR_COINBASE_API_KEY",
|
|
174
|
+
},
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
# Payments will be handled automatically via Coinbase Commerce
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Error Handling
|
|
181
|
+
|
|
182
|
+
The SDK provides typed errors for all API error codes:
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
from xache import (
|
|
186
|
+
XacheError,
|
|
187
|
+
UnauthenticatedError,
|
|
188
|
+
PaymentRequiredError,
|
|
189
|
+
RateLimitedError,
|
|
190
|
+
BudgetExceededError,
|
|
191
|
+
InvalidInputError,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
try:
|
|
195
|
+
await client.memory.store(data=data, storage_tier="hot")
|
|
196
|
+
except PaymentRequiredError as e:
|
|
197
|
+
print(f"Payment required: ${e.amount}")
|
|
198
|
+
print(f"Challenge ID: {e.challenge_id}")
|
|
199
|
+
except RateLimitedError as e:
|
|
200
|
+
print(f"Rate limited. Retry at: {e.reset_at}")
|
|
201
|
+
except BudgetExceededError as e:
|
|
202
|
+
print("Budget exceeded")
|
|
203
|
+
except InvalidInputError as e:
|
|
204
|
+
print(f"Invalid input: {e.message}")
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Context Manager
|
|
208
|
+
|
|
209
|
+
Always use the client as an async context manager to ensure proper cleanup:
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
async with XacheClient(...) as client:
|
|
213
|
+
# Your code here
|
|
214
|
+
pass
|
|
215
|
+
# HTTP session automatically closed
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Or manually manage the lifecycle:
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
client = XacheClient(...)
|
|
222
|
+
try:
|
|
223
|
+
# Your code here
|
|
224
|
+
pass
|
|
225
|
+
finally:
|
|
226
|
+
await client.close()
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## API Reference
|
|
230
|
+
|
|
231
|
+
### XacheClient
|
|
232
|
+
|
|
233
|
+
Main client class for interacting with Xache Protocol.
|
|
234
|
+
|
|
235
|
+
#### Properties
|
|
236
|
+
|
|
237
|
+
- `client.identity` - Identity registration
|
|
238
|
+
- `client.memory` - Memory storage and retrieval
|
|
239
|
+
- `client.collective` - Collective intelligence marketplace
|
|
240
|
+
- `client.budget` - Budget management
|
|
241
|
+
- `client.receipts` - Receipt access and analytics
|
|
242
|
+
|
|
243
|
+
### Types
|
|
244
|
+
|
|
245
|
+
All request/response types are available:
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
from xache import (
|
|
249
|
+
RegisterIdentityRequest,
|
|
250
|
+
RegisterIdentityResponse,
|
|
251
|
+
StoreMemoryRequest,
|
|
252
|
+
StoreMemoryResponse,
|
|
253
|
+
QueryCollectiveRequest,
|
|
254
|
+
BudgetStatus,
|
|
255
|
+
Receipt,
|
|
256
|
+
)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Development
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
# Install with dev dependencies
|
|
263
|
+
pip install -e ".[dev]"
|
|
264
|
+
|
|
265
|
+
# Run tests
|
|
266
|
+
pytest
|
|
267
|
+
|
|
268
|
+
# Run type checking
|
|
269
|
+
mypy xache
|
|
270
|
+
|
|
271
|
+
# Format code
|
|
272
|
+
black xache
|
|
273
|
+
|
|
274
|
+
# Lint
|
|
275
|
+
pylint xache
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Requirements
|
|
279
|
+
|
|
280
|
+
- Python 3.8+
|
|
281
|
+
- aiohttp
|
|
282
|
+
- typing-extensions
|
|
283
|
+
|
|
284
|
+
## License
|
|
285
|
+
|
|
286
|
+
MIT
|
|
287
|
+
|
|
288
|
+
## Links
|
|
289
|
+
|
|
290
|
+
- [Documentation](https://docs.xache.ai)
|
|
291
|
+
- [Protocol Specification](https://github.com/xache-ai/xache-protocol)
|
|
292
|
+
- [API Reference](https://api.xache.xyz/docs)
|
|
293
|
+
- [Discord](https://discord.gg/xache)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "xache"
|
|
7
|
+
version = "5.0.0"
|
|
8
|
+
description = "Official Python SDK for Xache Protocol"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Xache Protocol", email = "dev@xache.xyz"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["xache", "ai", "agent", "memory", "blockchain", "decentralized"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.8",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"aiohttp>=3.9.0",
|
|
29
|
+
"typing-extensions>=4.0.0",
|
|
30
|
+
"mnemonic>=0.20",
|
|
31
|
+
"eth-account>=0.10.0",
|
|
32
|
+
"bip-utils>=2.9.0",
|
|
33
|
+
"PyNaCl>=1.5.0",
|
|
34
|
+
"base58>=2.1.1",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.optional-dependencies]
|
|
38
|
+
dev = [
|
|
39
|
+
"pytest>=7.0.0",
|
|
40
|
+
"pytest-asyncio>=0.21.0",
|
|
41
|
+
"pytest-cov>=4.0.0",
|
|
42
|
+
"black>=23.0.0",
|
|
43
|
+
"mypy>=1.0.0",
|
|
44
|
+
"pylint>=2.17.0",
|
|
45
|
+
]
|
|
46
|
+
encryption = [
|
|
47
|
+
"PyNaCl>=1.5.0",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[project.urls]
|
|
51
|
+
Homepage = "https://xache.xyz"
|
|
52
|
+
Documentation = "https://docs.xache.xyz"
|
|
53
|
+
Repository = "https://github.com/oliveskin/xache"
|
|
54
|
+
"Bug Reports" = "https://github.com/oliveskin/xache/issues"
|
|
55
|
+
|
|
56
|
+
[tool.pytest.ini_options]
|
|
57
|
+
asyncio_mode = "auto"
|
|
58
|
+
testpaths = ["tests"]
|
|
59
|
+
|
|
60
|
+
[tool.mypy]
|
|
61
|
+
python_version = "3.8"
|
|
62
|
+
warn_return_any = true
|
|
63
|
+
warn_unused_configs = true
|
|
64
|
+
disallow_untyped_defs = true
|
|
65
|
+
|
|
66
|
+
[tool.black]
|
|
67
|
+
line-length = 100
|
|
68
|
+
target-version = ['py38', 'py39', 'py310', 'py311']
|
xache-5.0.0/setup.cfg
ADDED