Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
581abad
Phase L: emit discriminated unions in Python codegen + drop hand-writ…
SteveSandersonMS May 22, 2026
56c52a3
Phase A: SessionConfig/ResumeSessionConfig renames
SteveSandersonMS May 22, 2026
c252a04
Phase B: RuntimeConnection discriminated config + CopilotClientOptions
SteveSandersonMS May 22, 2026
f037503
Phase B fixup: re-export TelemetryConfig from copilot package
SteveSandersonMS May 22, 2026
156029e
Phase B fixup: regenerate codegen, fix scenario create_session calls
SteveSandersonMS May 22, 2026
30f2d6b
Phase B fixup: run nightly rustfmt on regenerated Rust types
SteveSandersonMS May 22, 2026
9885b92
Phase B fixup: address CI e2e failures from runtime port + Kind/Type …
SteveSandersonMS May 22, 2026
0ea0bc7
Phase C: streaming/MCP/shape cleanups + disable quicktype combineClasses
SteveSandersonMS May 22, 2026
9d63384
Phase D + E: lifecycle polymorphic union + datetime timestamps
SteveSandersonMS May 22, 2026
24cafde
Phase F: internals cleanup + expand public API surface
SteveSandersonMS May 22, 2026
7531aca
Phase G: snake_case fix-up on public dataclass fields
SteveSandersonMS May 22, 2026
b23e8dc
Phase H: extract SessionConfigBase TypedDict
SteveSandersonMS May 22, 2026
b80af48
Phase I: update README + docs for new Python SDK API
SteveSandersonMS May 22, 2026
2c6bedd
Phase F/G fixup: fix new ty errors
SteveSandersonMS May 22, 2026
15a466a
E2E test fixups for renamed APIs
SteveSandersonMS May 22, 2026
b57bab8
Rename RuntimeConnection factories to for_stdio/for_tcp/for_uri
SteveSandersonMS May 22, 2026
91981ea
Address CodeQL findings: overload bodies + match-to-if-chain
SteveSandersonMS May 22, 2026
53bd275
Rename GetStatusResponse.protocolVersion -> protocol_version
SteveSandersonMS May 22, 2026
9786c53
Move on_list_models into options, drop auto_start + get_state
SteveSandersonMS May 22, 2026
5676e4f
Flatten CopilotClient options + drop unused SessionConfig TypedDicts
SteveSandersonMS May 22, 2026
886c12d
Fix missing ** spread on _make_options in propagate-options test
SteveSandersonMS May 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ asyncio.run(main())
- ✅ Full JSON-RPC protocol support
- ✅ stdio and TCP transports
- ✅ Real-time streaming events
- ✅ Session history with `get_messages()`
- ✅ Session history with `get_events()`
- ✅ Type hints throughout
- ✅ Async/await native
- ✅ Async context manager support for automatic resource cleanup
Expand All @@ -113,7 +113,7 @@ asyncio.run(main())
### CopilotClient

```python
from copilot import CopilotClient, SubprocessConfig
from copilot import CopilotClient
from copilot.session import PermissionHandler

async with CopilotClient() as client:
Expand All @@ -133,40 +133,44 @@ async with CopilotClient() as client:
> **Note:** For manual lifecycle management, see [Manual Resource Management](#manual-resource-management) above.

```python
from copilot import CopilotClient, ExternalServerConfig
from copilot import CopilotClient, CopilotClientOptions, RuntimeConnection

# Connect to an existing CLI server
client = CopilotClient(ExternalServerConfig(url="localhost:3000"))
client = CopilotClient(
CopilotClientOptions(connection=RuntimeConnection.uri("localhost:3000"))
)
```

**CopilotClient Constructor:**

```python
CopilotClient(
config=None, # SubprocessConfig | ExternalServerConfig | None
options=None, # CopilotClientOptions | None
*,
auto_start=True, # auto-start server on first use
auto_start=True, # auto-start server on first use
on_list_models=None, # custom handler for list_models()
)
```

**SubprocessConfig** — spawn a local CLI process:
**CopilotClientOptions** — configure the client:

- `cli_path` (str | None): Path to CLI executable (default: `COPILOT_CLI_PATH` env var, or bundled binary)
- `cli_args` (list[str]): Extra arguments for the CLI executable
- `cwd` (str | None): Working directory for CLI process (default: current dir)
- `use_stdio` (bool): Use stdio transport instead of TCP (default: True)
- `port` (int): Server port for TCP mode (default: 0 for random)
- `log_level` (str): Log level (default: "info")
- `env` (dict | None): Environment variables for the CLI process
- `connection` (RuntimeConnection | None): How to reach the runtime. Use
`RuntimeConnection.stdio(...)`, `RuntimeConnection.tcp(...)`, or
`RuntimeConnection.uri(...)`. Defaults to a stdio connection with the bundled binary.
- `working_directory` (str | None): Working directory for the CLI process (default: current dir).
- `log_level` (str): Log level (default: "info").
- `env` (dict | None): Environment variables for the CLI process.
- `github_token` (str | None): GitHub token for authentication. When provided, takes priority over other auth methods.
- `copilot_home` (str | None): Base directory for Copilot data (session state, config, etc.). Sets `COPILOT_HOME` on the spawned CLI process. When `None`, the CLI defaults to `~/.copilot`. Useful in restricted environments where only specific directories are writable. Ignored when using `ExternalServerConfig`.
- `base_directory` (str | None): Base directory for Copilot data (session state, config, etc.). Sets `COPILOT_HOME` on the spawned CLI process. When `None`, the CLI defaults to `~/.copilot`. Useful in restricted environments where only specific directories are writable. Ignored when using a `UriRuntimeConnection`.
- `use_logged_in_user` (bool | None): Whether to use logged-in user for authentication (default: True, but False when `github_token` is provided).
- `telemetry` (dict | None): OpenTelemetry configuration for the CLI process. Providing this enables telemetry — no separate flag needed. See [Telemetry](#telemetry) below.
- `enable_remote_sessions` (bool): Enable remote/cloud session support (default: False).

**ExternalServerConfig** — connect to an existing CLI server:
**RuntimeConnection variants:**

- `url` (str): Server URL (e.g., `"localhost:8080"`, `"http://127.0.0.1:9000"`, or just `"8080"`).
- `RuntimeConnection.stdio(path=None, args=None)` — spawn a local CLI process and talk over stdio.
- `RuntimeConnection.tcp(port=0, connection_token=None, path=None, args=None)` — spawn a local CLI in TCP mode.
- `RuntimeConnection.uri(url, connection_token=None)` — connect to an existing CLI server (e.g. `"localhost:8080"`).

**`CopilotClient.create_session()`:**

Expand Down Expand Up @@ -197,10 +201,10 @@ await client.set_foreground_session_id("session-123")
def on_lifecycle(event):
print(f"{event.type}: {event.sessionId}")

unsubscribe = client.on(on_lifecycle)
unsubscribe = client.on_lifecycle(on_lifecycle)

# Subscribe to specific event type
unsubscribe = client.on("session.foreground", lambda e: print(f"Foreground: {e.sessionId}"))
unsubscribe = client.on_lifecycle("session.foreground", lambda e: print(f"Foreground: {e.sessionId}"))

# Later, to stop receiving events:
unsubscribe()
Expand Down Expand Up @@ -531,9 +535,9 @@ async with await client.create_session(
The SDK supports OpenTelemetry for distributed tracing. Provide a `telemetry` config to enable trace export and automatic W3C Trace Context propagation.

```python
from copilot import CopilotClient, SubprocessConfig
from copilot import CopilotClient, CopilotClientOptions

client = CopilotClient(SubprocessConfig(
client = CopilotClient(CopilotClientOptions(
telemetry={
"otlp_endpoint": "http://localhost:4318",
},
Expand Down
18 changes: 14 additions & 4 deletions python/copilot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
"""

from .client import (
ChildProcessRuntimeConnection,
CloudSessionOptions,
CloudSessionRepository,
CopilotClient,
ExternalServerConfig,
CopilotClientOptions,
ModelCapabilitiesOverride,
ModelLimitsOverride,
ModelSupportsOverride,
ModelVisionLimitsOverride,
RemoteSessionMode,
SubprocessConfig,
RuntimeConnection,
StdioRuntimeConnection,
TcpRuntimeConnection,
TelemetryConfig,
UriRuntimeConnection,
)
from .session import (
AutoModeSwitchHandler,
Expand Down Expand Up @@ -62,10 +67,12 @@
"AutoModeSwitchHandler",
"AutoModeSwitchRequest",
"AutoModeSwitchResponse",
"ChildProcessRuntimeConnection",
"CommandDefinition",
"CloudSessionOptions",
"CloudSessionRepository",
"CopilotClient",
"CopilotClientOptions",
"CopilotSession",
"CreateSessionFsHandler",
"ElicitationHandler",
Expand All @@ -75,14 +82,14 @@
"ExitPlanModeHandler",
"ExitPlanModeRequest",
"ExitPlanModeResult",
"ExternalServerConfig",
"InputOptions",
"ModelCapabilitiesOverride",
"ModelLimitsOverride",
"ModelSupportsOverride",
"ModelVisionLimitsOverride",
"ProviderConfig",
"RemoteSessionMode",
"RuntimeConnection",
"SessionCapabilities",
"SessionFsCapabilities",
"SessionFsConfig",
Expand All @@ -93,11 +100,14 @@
"create_session_fs_adapter",
"SessionUiApi",
"SessionUiCapabilities",
"SubprocessConfig",
"StdioRuntimeConnection",
"TcpRuntimeConnection",
"TelemetryConfig",
"Tool",
"ToolBinaryResult",
"ToolInvocation",
"ToolResult",
"UriRuntimeConnection",
"convert_mcp_call_tool_result",
"define_tool",
]
Loading
Loading