acontext 0.0.1.dev4__tar.gz → 0.0.1.dev7__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.
- acontext-0.0.1.dev7/PKG-INFO +479 -0
- acontext-0.0.1.dev7/README.md +464 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/pyproject.toml +2 -6
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/resources/async_sessions.py +7 -1
- acontext-0.0.1.dev7/src/acontext/resources/async_spaces.py +188 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/resources/sessions.py +7 -2
- acontext-0.0.1.dev7/src/acontext/resources/spaces.py +186 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/types/__init__.py +4 -1
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/types/session.py +3 -2
- acontext-0.0.1.dev7/src/acontext/types/space.py +46 -0
- acontext-0.0.1.dev4/PKG-INFO +0 -93
- acontext-0.0.1.dev4/README.md +0 -78
- acontext-0.0.1.dev4/src/acontext/resources/async_spaces.py +0 -90
- acontext-0.0.1.dev4/src/acontext/resources/spaces.py +0 -89
- acontext-0.0.1.dev4/src/acontext/types/space.py +0 -24
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/__init__.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/_constants.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/_utils.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/async_client.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/client.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/client_types.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/errors.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/messages.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/py.typed +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/resources/__init__.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/resources/async_blocks.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/resources/async_disks.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/resources/blocks.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/resources/disks.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/types/block.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/types/disk.py +0 -0
- {acontext-0.0.1.dev4 → acontext-0.0.1.dev7}/src/acontext/uploads.py +0 -0
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: acontext
|
|
3
|
+
Version: 0.0.1.dev7
|
|
4
|
+
Summary: Python SDK for the Acontext API
|
|
5
|
+
Keywords: acontext,sdk,client,api
|
|
6
|
+
Requires-Dist: httpx>=0.28.1
|
|
7
|
+
Requires-Dist: openai>=2.6.1
|
|
8
|
+
Requires-Dist: anthropic>=0.72.0
|
|
9
|
+
Requires-Dist: pydantic>=2.12.3
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Project-URL: Homepage, https://github.com/memodb-io/Acontext
|
|
12
|
+
Project-URL: Issues, https://github.com/memodb-io/Acontext/issues
|
|
13
|
+
Project-URL: Repository, https://github.com/memodb-io/Acontext
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
## acontext client for python
|
|
17
|
+
|
|
18
|
+
Python SDK for interacting with the Acontext REST API.
|
|
19
|
+
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install acontext
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
> Requires Python 3.10 or newer.
|
|
27
|
+
|
|
28
|
+
### Quickstart
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from acontext import AcontextClient
|
|
32
|
+
|
|
33
|
+
with AcontextClient(api_key="sk_project_token") as client:
|
|
34
|
+
# Create a space
|
|
35
|
+
space = client.spaces.create()
|
|
36
|
+
|
|
37
|
+
# Create a session
|
|
38
|
+
session = client.sessions.create(space_id=space.id)
|
|
39
|
+
|
|
40
|
+
# Send a message
|
|
41
|
+
from acontext.messages import build_acontext_message
|
|
42
|
+
message = build_acontext_message(role="user", parts=["Hello!"])
|
|
43
|
+
client.sessions.send_message(session.id, blob=message, format="acontext")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
See the sections below for detailed examples of all available APIs.
|
|
47
|
+
|
|
48
|
+
### Spaces API
|
|
49
|
+
|
|
50
|
+
#### List spaces
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
spaces = client.spaces.list(limit=10, time_desc=True)
|
|
54
|
+
for space in spaces.items:
|
|
55
|
+
print(f"{space.id}: {space.configs}")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### Create space
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
space = client.spaces.create(configs={"name": "My Space"})
|
|
62
|
+
print(f"Created space: {space.id}")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### Delete space
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
client.spaces.delete(space_id="space-uuid")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### Update space configs
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
client.spaces.update_configs(
|
|
75
|
+
space_id="space-uuid",
|
|
76
|
+
configs={"name": "Updated Name", "description": "New description"}
|
|
77
|
+
)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Get space configs
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
space = client.spaces.get_configs(space_id="space-uuid")
|
|
84
|
+
print(space.configs)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Sessions API
|
|
88
|
+
|
|
89
|
+
#### List sessions
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
sessions = client.sessions.list(
|
|
93
|
+
space_id="space-uuid",
|
|
94
|
+
limit=20,
|
|
95
|
+
time_desc=True
|
|
96
|
+
)
|
|
97
|
+
for session in sessions.items:
|
|
98
|
+
print(f"{session.id}: {session.space_id}")
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### Create session
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
session = client.sessions.create(
|
|
105
|
+
space_id="space-uuid",
|
|
106
|
+
configs={"mode": "chat"}
|
|
107
|
+
)
|
|
108
|
+
print(f"Created session: {session.id}")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Delete session
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
client.sessions.delete(session_id="session-uuid")
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### Update session configs
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
client.sessions.update_configs(
|
|
121
|
+
session_id="session-uuid",
|
|
122
|
+
configs={"mode": "updated-mode"}
|
|
123
|
+
)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Get session configs
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
session = client.sessions.get_configs(session_id="session-uuid")
|
|
130
|
+
print(session.configs)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### Connect session to space
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
client.sessions.connect_to_space(
|
|
137
|
+
session_id="session-uuid",
|
|
138
|
+
space_id="space-uuid"
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### Get tasks
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
tasks = client.sessions.get_tasks(
|
|
146
|
+
session_id="session-uuid",
|
|
147
|
+
limit=10,
|
|
148
|
+
time_desc=True
|
|
149
|
+
)
|
|
150
|
+
for task in tasks.items:
|
|
151
|
+
print(f"{task.id}: {task.status}")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### Get messages
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
messages = client.sessions.get_messages(
|
|
158
|
+
session_id="session-uuid",
|
|
159
|
+
limit=50,
|
|
160
|
+
format="acontext",
|
|
161
|
+
time_desc=True
|
|
162
|
+
)
|
|
163
|
+
for message in messages.items:
|
|
164
|
+
print(f"{message.role}: {message.parts}")
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### Send message (Acontext format)
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from acontext.messages import build_acontext_message
|
|
171
|
+
|
|
172
|
+
# Simple text message
|
|
173
|
+
message = build_acontext_message(role="user", parts=["Hello!"])
|
|
174
|
+
client.sessions.send_message(
|
|
175
|
+
session_id="session-uuid",
|
|
176
|
+
blob=message,
|
|
177
|
+
format="acontext"
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
# Message with file upload
|
|
181
|
+
from acontext import FileUpload
|
|
182
|
+
|
|
183
|
+
file_message = build_acontext_message(
|
|
184
|
+
role="user",
|
|
185
|
+
parts=[{"type": "file", "file_field": "document"}]
|
|
186
|
+
)
|
|
187
|
+
client.sessions.send_message(
|
|
188
|
+
session_id="session-uuid",
|
|
189
|
+
blob=file_message,
|
|
190
|
+
format="acontext",
|
|
191
|
+
file_field="document",
|
|
192
|
+
file=FileUpload(
|
|
193
|
+
filename="doc.pdf",
|
|
194
|
+
content=b"file content",
|
|
195
|
+
content_type="application/pdf"
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### Send message (OpenAI format)
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
openai_message = {
|
|
204
|
+
"role": "user",
|
|
205
|
+
"content": "Hello from OpenAI format!"
|
|
206
|
+
}
|
|
207
|
+
client.sessions.send_message(
|
|
208
|
+
session_id="session-uuid",
|
|
209
|
+
blob=openai_message,
|
|
210
|
+
format="openai"
|
|
211
|
+
)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
#### Send message (Anthropic format)
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
anthropic_message = {
|
|
218
|
+
"role": "user",
|
|
219
|
+
"content": "Hello from Anthropic format!"
|
|
220
|
+
}
|
|
221
|
+
client.sessions.send_message(
|
|
222
|
+
session_id="session-uuid",
|
|
223
|
+
blob=anthropic_message,
|
|
224
|
+
format="anthropic"
|
|
225
|
+
)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Blocks API
|
|
229
|
+
|
|
230
|
+
#### List blocks
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
blocks = client.blocks.list(
|
|
234
|
+
space_id="space-uuid",
|
|
235
|
+
parent_id="parent-uuid",
|
|
236
|
+
block_type="page"
|
|
237
|
+
)
|
|
238
|
+
for block in blocks:
|
|
239
|
+
print(f"{block.id}: {block.title}")
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
#### Create block
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
# Create a page
|
|
246
|
+
page = client.blocks.create(
|
|
247
|
+
space_id="space-uuid",
|
|
248
|
+
block_type="page",
|
|
249
|
+
title="My Page"
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
# Create a text block under the page
|
|
253
|
+
text_block = client.blocks.create(
|
|
254
|
+
space_id="space-uuid",
|
|
255
|
+
parent_id=page["id"],
|
|
256
|
+
block_type="text",
|
|
257
|
+
title="Content",
|
|
258
|
+
props={"text": "Block content here"}
|
|
259
|
+
)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
#### Delete block
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
client.blocks.delete(space_id="space-uuid", block_id="block-uuid")
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
#### Get block properties
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
block = client.blocks.get_properties(
|
|
272
|
+
space_id="space-uuid",
|
|
273
|
+
block_id="block-uuid"
|
|
274
|
+
)
|
|
275
|
+
print(f"{block.title}: {block.props}")
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
#### Update block properties
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
client.blocks.update_properties(
|
|
282
|
+
space_id="space-uuid",
|
|
283
|
+
block_id="block-uuid",
|
|
284
|
+
title="Updated Title",
|
|
285
|
+
props={"text": "Updated content"}
|
|
286
|
+
)
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
#### Move block
|
|
290
|
+
|
|
291
|
+
```python
|
|
292
|
+
# Move to a different parent
|
|
293
|
+
client.blocks.move(
|
|
294
|
+
space_id="space-uuid",
|
|
295
|
+
block_id="block-uuid",
|
|
296
|
+
parent_id="new-parent-uuid"
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
# Update sort order
|
|
300
|
+
client.blocks.move(
|
|
301
|
+
space_id="space-uuid",
|
|
302
|
+
block_id="block-uuid",
|
|
303
|
+
sort=0
|
|
304
|
+
)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
#### Update block sort
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
client.blocks.update_sort(
|
|
311
|
+
space_id="space-uuid",
|
|
312
|
+
block_id="block-uuid",
|
|
313
|
+
sort=5
|
|
314
|
+
)
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Disks API
|
|
318
|
+
|
|
319
|
+
#### List disks
|
|
320
|
+
|
|
321
|
+
```python
|
|
322
|
+
disks = client.disks.list(limit=10, time_desc=True)
|
|
323
|
+
for disk in disks.items:
|
|
324
|
+
print(f"Disk: {disk.id}")
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
#### Create disk
|
|
328
|
+
|
|
329
|
+
```python
|
|
330
|
+
disk = client.disks.create()
|
|
331
|
+
print(f"Created disk: {disk.id}")
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
#### Delete disk
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
client.disks.delete(disk_id="disk-uuid")
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### DiskArtifacts API
|
|
341
|
+
|
|
342
|
+
#### Upsert artifact
|
|
343
|
+
|
|
344
|
+
```python
|
|
345
|
+
from acontext import FileUpload
|
|
346
|
+
|
|
347
|
+
artifact = client.disks.artifacts.upsert(
|
|
348
|
+
disk_id="disk-uuid",
|
|
349
|
+
file=FileUpload(
|
|
350
|
+
filename="notes.md",
|
|
351
|
+
content=b"# Notes\nContent here",
|
|
352
|
+
content_type="text/markdown"
|
|
353
|
+
),
|
|
354
|
+
file_path="/documents/",
|
|
355
|
+
meta={"source": "api", "version": "1.0"}
|
|
356
|
+
)
|
|
357
|
+
print(f"Uploaded: {artifact.filename}")
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
#### Get artifact
|
|
361
|
+
|
|
362
|
+
```python
|
|
363
|
+
artifact = client.disks.artifacts.get(
|
|
364
|
+
disk_id="disk-uuid",
|
|
365
|
+
file_path="/documents/",
|
|
366
|
+
filename="notes.md",
|
|
367
|
+
with_public_url=True,
|
|
368
|
+
with_content=True
|
|
369
|
+
)
|
|
370
|
+
print(f"Content: {artifact.content}")
|
|
371
|
+
print(f"URL: {artifact.public_url}")
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
#### Update artifact metadata
|
|
375
|
+
|
|
376
|
+
```python
|
|
377
|
+
artifact = client.disks.artifacts.update(
|
|
378
|
+
disk_id="disk-uuid",
|
|
379
|
+
file_path="/documents/",
|
|
380
|
+
filename="notes.md",
|
|
381
|
+
meta={"source": "api", "version": "2.0", "updated": True}
|
|
382
|
+
)
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
#### Delete artifact
|
|
386
|
+
|
|
387
|
+
```python
|
|
388
|
+
client.disks.artifacts.delete(
|
|
389
|
+
disk_id="disk-uuid",
|
|
390
|
+
file_path="/documents/",
|
|
391
|
+
filename="notes.md"
|
|
392
|
+
)
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
#### List artifacts
|
|
396
|
+
|
|
397
|
+
```python
|
|
398
|
+
artifacts = client.disks.artifacts.list(
|
|
399
|
+
disk_id="disk-uuid",
|
|
400
|
+
path="/documents/"
|
|
401
|
+
)
|
|
402
|
+
for artifact in artifacts.items:
|
|
403
|
+
print(f"{artifact.filename} ({artifact.size_b} bytes)")
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### Semantic search within spaces
|
|
407
|
+
|
|
408
|
+
The SDK provides three powerful semantic search APIs for finding content within your spaces:
|
|
409
|
+
|
|
410
|
+
#### 1. Experience Search (Advanced AI-powered search)
|
|
411
|
+
|
|
412
|
+
The most sophisticated search that can operate in two modes: **fast** (quick semantic search) or **agentic** (AI-powered iterative refinement).
|
|
413
|
+
|
|
414
|
+
```python
|
|
415
|
+
from acontext import AcontextClient
|
|
416
|
+
|
|
417
|
+
client = AcontextClient(api_key="sk_project_token")
|
|
418
|
+
|
|
419
|
+
# Fast mode - quick semantic search
|
|
420
|
+
result = client.spaces.experience_search(
|
|
421
|
+
space_id="space-uuid",
|
|
422
|
+
query="How to implement authentication?",
|
|
423
|
+
limit=10,
|
|
424
|
+
mode="fast",
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
# Agentic mode - AI-powered iterative search
|
|
428
|
+
result = client.spaces.experience_search(
|
|
429
|
+
space_id="space-uuid",
|
|
430
|
+
query="What are the best practices for API security?",
|
|
431
|
+
limit=10,
|
|
432
|
+
mode="agentic",
|
|
433
|
+
max_iterations=20,
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
# Access results
|
|
437
|
+
for block in result.cited_blocks:
|
|
438
|
+
print(f"{block.title} (distance: {block.distance})")
|
|
439
|
+
|
|
440
|
+
if result.final_answer:
|
|
441
|
+
print(f"AI Answer: {result.final_answer}")
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
#### 2. Semantic Global (Search page/folder titles)
|
|
445
|
+
|
|
446
|
+
Search for pages and folders by their titles using semantic similarity (like a semantic version of `glob`):
|
|
447
|
+
|
|
448
|
+
```python
|
|
449
|
+
# Find pages about authentication
|
|
450
|
+
results = client.spaces.semantic_global(
|
|
451
|
+
space_id="space-uuid",
|
|
452
|
+
query="authentication and authorization pages",
|
|
453
|
+
limit=10,
|
|
454
|
+
threshold=1.0, # Only show results with distance < 1.0
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
for block in results:
|
|
458
|
+
print(f"{block.title} - {block.type}")
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
#### 3. Semantic Grep (Search content blocks)
|
|
462
|
+
|
|
463
|
+
Search through actual content blocks using semantic similarity (like a semantic version of `grep`):
|
|
464
|
+
|
|
465
|
+
```python
|
|
466
|
+
# Find code examples for JWT validation
|
|
467
|
+
results = client.spaces.semantic_grep(
|
|
468
|
+
space_id="space-uuid",
|
|
469
|
+
query="JWT token validation code examples",
|
|
470
|
+
limit=15,
|
|
471
|
+
threshold=0.7,
|
|
472
|
+
)
|
|
473
|
+
|
|
474
|
+
for block in results:
|
|
475
|
+
print(f"{block.title} - distance: {block.distance}")
|
|
476
|
+
print(f"Content: {block.props.get('text', '')[:100]}...")
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
See `examples/search_usage.py` for more detailed examples including async usage.
|