How to Install the GitHub Copilot SDK for Python: Complete Setup Guide
Install the GitHub Copilot SDK for Python by running pip install github-copilot-sdk in a Python ≥3.8 environment, then import CopilotClient from the copilot package to begin making requests.
The GitHub Copilot SDK for Python is officially distributed through PyPI under the package name github-copilot-sdk. As implemented in the github/copilot-sdk repository, this SDK bundles the Copilot CLI runtime and manages its lifecycle automatically, enabling direct Python-native access to Copilot completions and agentic capabilities without manual binary management.
Prerequisites
Before installing, ensure your environment meets the baseline requirements.
- Python version 3.8 or higher. The SDK relies on modern
asyncioand typing features introduced in Python 3.8. pippackage manager (version 20.0+ recommended for reliable dependency resolution).
Verify your Python version:
python --version
Installation Steps
Step 1: Install from PyPI
Run the installation command to pull the latest stable release. This command automatically downloads the SDK and its dependencies, including logic in python/copilot/_cli_download.py that handles bundling the Copilot CLI binary for your platform.
pip install github-copilot-sdk
Step 2: Verify the Installation
Confirm the package is correctly installed by checking the version string exposed in python/copilot/__init__.py:
python -c "import copilot; print(copilot.__version__)"
If installed correctly, this prints the SDK version number without import errors.
Authentication Configuration
The SDK supports multiple authentication mechanisms. By default, it uses tokens stored by the Copilot CLI (copilot login), but you can override this behavior.
Using Environment Variables
Set one of the following environment variables to authenticate without the CLI:
COPILOT_GITHUB_TOKENGH_TOKENGITHUB_TOKEN
export GITHUB_TOKEN="ghp_xxxxxxxxxxxx"
python your_script.py
Using a BYOK Provider
For Bring-Your-Own-Key (BYOK) scenarios, configure a custom provider via the BYOKProvider class. This is useful when integrating with alternative model endpoints:
import os
from copilot import CopilotClient, BYOKProvider
os.environ["OPENAI_API_KEY"] = "sk-..."
byok = BYOKProvider(
provider="openai",
model="gpt-4o-mini",
api_key=os.getenv("OPENAI_API_KEY"),
)
client = CopilotClient(auth=byok)
Detailed authentication flows are documented in docs/auth/README.md within the repository.
First SDK Usage
Once installed, create a client instance. The CopilotClient class (exposed in python/copilot/__init__.py) automatically launches the bundled Copilot CLI in the background and manages JSON-RPC communication via the transport layer implemented in python/copilot/_jsonrpc.py.
from copilot import CopilotClient
client = CopilotClient()
response = client.completions.create(
prompt="Write a function that returns the factorial of n.",
max_tokens=100,
)
print(response.choices[0].text)
The client handles streaming results, tool invocation, and lifecycle management without additional setup code.
Internal Architecture
Understanding the key source files helps troubleshoot installation issues:
python/copilot/_cli_download.py: Manages downloading and caching the Copilot CLI binary for environments where it is not pre-installed.python/copilot/_jsonrpc.py: Implements the JSON-RPC transport layer that the client uses to communicate with the Copilot CLI process.python/copilot/_telemetry.py: Manages optional telemetry collection (can be disabled via client options).
Summary
- PyPI Package: Install
github-copilot-sdkviapipin Python ≥3.8 environments. - Automatic CLI Management: The SDK bundles and manages the Copilot CLI runtime; no separate binary installation is required.
- Flexible Auth: Supports CLI tokens, environment variables (
GITHUB_TOKEN,GH_TOKEN), or BYOK providers. - Entry Point: Use
CopilotClientfrom thecopilotpackage to begin making API calls immediately after installation.
Frequently Asked Questions
What Python versions are supported by the GitHub Copilot SDK?
The SDK requires Python 3.8 or higher. This requirement is enforced because the SDK uses modern asyncio patterns and type hinting features that are not available in earlier Python versions.
Do I need to install the GitHub Copilot CLI separately?
No. The SDK bundles the Copilot CLI runtime and automatically handles its installation and lifecycle. The logic in python/copilot/_cli_download.py downloads the appropriate binary for your platform the first time you instantiate CopilotClient.
Can I use the SDK in an air-gapped environment?
Yes, but you must configure a BYOK (Bring-Your-Own-Key) provider rather than relying on the default GitHub Copilot service. Configure this via the BYOKProvider class and provide your own model endpoint credentials, as the default mode requires internet access to GitHub's Copilot API.
How do I uninstall the GitHub Copilot SDK?
Run the standard pip uninstall command:
pip uninstall github-copilot-sdk
This removes the Python package and the cached CLI binary downloaded by _cli_download.py, though it will not affect global Copilot CLI installations made separately by the user.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →