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