Skip to content

Commit c9b998b

Browse files
brettcannonCopilotCopilot
authored
Update Python docs to align with current code (github#943)
* Update Python docs to align with current code * Update docs/getting-started.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Review comment fixes * refactor: replace if-elif with match-case for event handling in README example --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f5516e2 commit c9b998b

21 files changed

+193
-171
lines changed

docs/auth/byok.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Azure AI Foundry (formerly Azure OpenAI) is a common BYOK deployment target for
2323
```python
2424
import asyncio
2525
import os
26-
from copilot import CopilotClient, PermissionHandler
26+
from copilot import CopilotClient
27+
from copilot.session import PermissionHandler
2728

2829
FOUNDRY_MODEL_URL = "https://your-resource.openai.azure.com/openai/v1/"
2930
# Set FOUNDRY_API_KEY environment variable

docs/features/custom-agents.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,7 @@ def handle_event(event):
414414

415415
unsubscribe = session.on(handle_event)
416416

417-
response = await session.send_and_wait({
418-
"prompt": "Research how authentication works in this codebase"
419-
})
417+
response = await session.send_and_wait("Research how authentication works in this codebase")
420418
```
421419

422420
</details>

docs/features/image-input.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,15 @@ await session.send({
258258

259259
```python
260260
from copilot import CopilotClient
261-
from copilot.types import PermissionRequestResult
261+
from copilot.session import PermissionRequestResult
262262

263263
client = CopilotClient()
264264
await client.start()
265265

266-
session = await client.create_session({
267-
"model": "gpt-4.1",
268-
"on_permission_request": lambda req, inv: PermissionRequestResult(kind="approved"),
269-
})
266+
session = await client.create_session(
267+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
268+
model="gpt-4.1",
269+
)
270270

271271
base64_image_data = "..." # your base64-encoded image
272272
await session.send(

docs/features/mcp.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ const session = await client.createSession({
5959

6060
```python
6161
import asyncio
62-
from copilot import CopilotClient, PermissionHandler
62+
from copilot import CopilotClient
63+
from copilot.session import PermissionHandler
6364

6465
async def main():
6566
client = CopilotClient()
@@ -85,9 +86,7 @@ async def main():
8586
},
8687
})
8788

88-
response = await session.send_and_wait({
89-
"prompt": "List my recent GitHub notifications"
90-
})
89+
response = await session.send_and_wait("List my recent GitHub notifications")
9190
print(response.data.content)
9291

9392
await client.stop()

docs/features/session-persistence.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ await session.sendAndWait({ prompt: "Analyze my codebase" });
4646
### Python
4747

4848
```python
49-
from copilot import CopilotClient, PermissionHandler
49+
from copilot import CopilotClient
50+
from copilot.session import PermissionHandler
5051

5152
client = CopilotClient()
5253
await client.start()
@@ -55,7 +56,7 @@ await client.start()
5556
session = await client.create_session(on_permission_request=PermissionHandler.approve_all, model="gpt-5.2-codex", session_id="user-123-task-456")
5657

5758
# Do some work...
58-
await session.send_and_wait({"prompt": "Analyze my codebase"})
59+
await session.send_and_wait("Analyze my codebase")
5960

6061
# Session state is automatically persisted
6162
```
@@ -160,7 +161,7 @@ await session.sendAndWait({ prompt: "What did we discuss earlier?" });
160161
session = await client.resume_session("user-123-task-456", on_permission_request=PermissionHandler.approve_all)
161162

162163
# Continue where you left off
163-
await session.send_and_wait({"prompt": "What did we discuss earlier?"})
164+
await session.send_and_wait("What did we discuss earlier?")
164165
```
165166

166167
### Go
@@ -413,7 +414,7 @@ Each SDK also provides idiomatic automatic cleanup patterns:
413414
| Language | Pattern | Example |
414415
|----------|---------|---------|
415416
| **TypeScript** | `Symbol.asyncDispose` | `await using session = await client.createSession(config);` |
416-
| **Python** | `async with` context manager | `async with await client.create_session(config) as session:` |
417+
| **Python** | `async with` context manager | `async with await client.create_session(on_permission_request=handler) as session:` |
417418
| **C#** | `IAsyncDisposable` | `await using var session = await client.CreateSessionAsync(config);` |
418419
| **Go** | `defer` | `defer session.Disconnect()` |
419420

docs/features/skills.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async def main():
5959
)
6060

6161
# Copilot now has access to skills in those directories
62-
await session.send_and_wait({"prompt": "Review this code for security issues"})
62+
await session.send_and_wait("Review this code for security issues")
6363

6464
await client.stop()
6565
```
@@ -160,7 +160,7 @@ const session = await client.createSession({
160160
<summary><strong>Python</strong></summary>
161161

162162
```python
163-
from copilot import PermissionHandler
163+
from copilot.session import PermissionHandler
164164

165165
session = await client.create_session(
166166
on_permission_request=PermissionHandler.approve_all,

docs/getting-started.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ async def main():
137137
await client.start()
138138

139139
session = await client.create_session(on_permission_request=PermissionHandler.approve_all, model="gpt-4.1")
140-
response = await session.send_and_wait({"prompt": "What is 2 + 2?"})
141-
142-
response = await session.send_and_wait({"prompt": "What is 2 + 2?"})
140+
response = await session.send_and_wait("What is 2 + 2?")
143141
print(response.data.content)
144142

145143
await client.stop()
@@ -296,7 +294,7 @@ async def main():
296294

297295
session.on(handle_event)
298296

299-
await session.send_and_wait({"prompt": "Tell me a short joke"})
297+
await session.send_and_wait("Tell me a short joke")
300298

301299
await client.stop()
302300

@@ -430,10 +428,11 @@ unsubscribeIdle();
430428
```python
431429
from copilot import CopilotClient
432430
from copilot.generated.session_events import SessionEvent, SessionEventType
431+
from copilot.session import PermissionRequestResult
433432

434433
client = CopilotClient()
435434

436-
session = client.create_session(on_permission_request=lambda req, inv: {"kind": "approved"})
435+
session = await client.create_session(on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"))
437436

438437
# Subscribe to all events
439438
unsubscribe = session.on(lambda event: print(f"Event: {event.type}"))
@@ -688,9 +687,7 @@ async def main():
688687

689688
session.on(handle_event)
690689

691-
await session.send_and_wait({
692-
"prompt": "What's the weather like in Seattle and Tokyo?"
693-
})
690+
await session.send_and_wait("What's the weather like in Seattle and Tokyo?")
694691

695692
await client.stop()
696693

@@ -965,7 +962,7 @@ async def main():
965962
break
966963

967964
sys.stdout.write("Assistant: ")
968-
await session.send_and_wait({"prompt": user_input})
965+
await session.send_and_wait(user_input)
969966
print("\n")
970967

971968
await client.stop()

docs/hooks/error-handling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const session = await client.createSession({
146146
<summary><strong>Python</strong></summary>
147147

148148
```python
149-
from copilot import PermissionHandler
149+
from copilot.session import PermissionHandler
150150

151151
async def on_error_occurred(input_data, invocation):
152152
print(f"[{invocation['session_id']}] Error: {input_data['error']}")

docs/hooks/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ const session = await client.createSession({
5353
<summary><strong>Python</strong></summary>
5454

5555
```python
56-
from copilot import CopilotClient, PermissionHandler
56+
from copilot import CopilotClient
57+
from copilot.session import PermissionHandler
5758

5859
async def main():
5960
client = CopilotClient()

docs/hooks/post-tool-use.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const session = await client.createSession({
145145
<summary><strong>Python</strong></summary>
146146

147147
```python
148-
from copilot import PermissionHandler
148+
from copilot.session import PermissionHandler
149149

150150
async def on_post_tool_use(input_data, invocation):
151151
print(f"[{invocation['session_id']}] Tool: {input_data['toolName']}")

0 commit comments

Comments
 (0)