Skip to main content

An unofficial Python API wrapper for Microsoft Copilot

Project description

🤖 Copilot API

PyPI version Python License: HelpingAI GitHub stars Downloads Downloads/Month Downloads/Week Last Commit Code style: black GitHub issues

🚀 A powerful, unofficial Python API wrapper for Microsoft Copilot with CLI support

InstallationFeaturesQuick StartCLI UsageExamplesContributingSupport

⭐ Stargazers

Stargazers repo roster for @OE-LUCIFER/copilot-api

📦 Installation

# Using pip
pip install copilot-api

# From source
git clone https://github.com/OE-LUCIFER/copilot-api.git
cd copilot-api
pip install -e .

🎯 Key Features

  • 🤖 Microsoft Copilot Integration - Direct access to Microsoft Copilot's capabilities
  • 🔄 Streaming Support - Real-time response streaming for better interactivity
  • 🛡️ Robust Error Handling - Comprehensive exception handling with custom error types
  • 🔌 Flexible Configuration - Support for proxies, timeouts, and custom settings
  • 🎨 Rich CLI Interface - Interactive terminal experience with syntax highlighting
  • 📦 Lightweight & Fast - Minimal dependencies with efficient implementation

✨ Features

Core Features

  • 🔄 Stream Chat Completions - Real-time streaming responses
  • 💬 Conversation Management - Maintain context across messages
  • 🔒 Proxy Support - Configure custom proxy settings
  • ⚙️ Customizable - Flexible timeout and configuration options

CLI Features

  • 🎨 Rich Text Interface - Beautiful terminal UI with syntax highlighting
  • 📝 Interactive Chat - Full-featured chat interface in your terminal
  • 💾 Session Management - Save and load conversation sessions
  • 🎯 Multiple Commands - Dedicated commands for different functionalities
  • 🔍 Help System - Built-in help and documentation

Developer Features

  • 🛠️ Type Hints - Full type annotation support
  • 📚 Rich Documentation - Comprehensive API documentation
  • 🧪 Exception Handling - Detailed error messages and handling
  • 🔌 Extensible - Easy to extend and customize
  • 🎮 Multiple Interfaces - Use as library or CLI tool

🔧 Technical Details

Core Components

  • copilot.py - Main Copilot client implementation
  • cli.py - Command-line interface implementation
  • exceptions.py - Custom exception definitions
  • utils.py - Helper functions and utilities

Error Handling

The library includes custom exceptions for better error management:

from copilot_api.exceptions import CopilotError, AuthenticationError, APIError

try:
    response = copilot.create_completion(messages=messages)
except AuthenticationError:
    print("Authentication failed. Please check your credentials.")
except APIError as e:
    print(f"API error occurred: {e}")

🚀 Quick Start

Python Library Usage

from copilot_api import Copilot

# Initialize Copilot
copilot = Copilot()

# Basic chat example
messages = [
    {"role": "system", "content": "You are a helpful AI assistant."},
    {"role": "user", "content": "Hello!"}
]

# Stream responses
for response in copilot.create_completion(
    model="Copilot",
    messages=messages,
    stream=True
):
    if isinstance(response, str):
        print(response, end='', flush=True)

🖥️ CLI Usage

Interactive Chat

# Start interactive chat
copilot-cli

# Start chat with specific model
copilot-cli --model Copilot

# Save conversation
copilot-cli --save chat_history.json

# Load previous conversation
copilot-cli --load chat_history.json

Alternative Usage

# Using Python module directly
python -m copilot_api.cli chat

# Or using the main command
copilot chat

CLI Commands

  • /help - Show help message
  • /clear - Clear current conversation
  • /save <filename> - Save conversation
  • /load <filename> - Load conversation
  • /exit - Exit the CLI

📚 Examples

💬 Managing Conversations

from copilot_api import save_conversation, load_conversation

# Save conversation
save_conversation("chat_history.json", messages)

# Load conversation
messages = load_conversation("chat_history.json")

🛠️ Advanced Usage

Proxy Configuration

copilot = Copilot(
    proxy="http://your-proxy-server:port"
)

Custom Timeout Settings

copilot = Copilot(
    timeout=30  # seconds
)

Advanced Configuration

from copilot_api import Copilot

# Initialize with custom configuration
copilot = Copilot(
    timeout=30,
    proxy="http://proxy:port",
    max_retries=3,
    verify_ssl=True
)

# Custom headers and parameters
response = copilot.create_completion(
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True,
    temperature=0.7,
    max_tokens=150
)

CLI Features

The CLI tool (copilot-cli) supports various commands and options:

# Start with custom configuration
copilot-cli --timeout 30 --no-stream

# Export conversation
copilot-cli --export chat.json

# Import and continue conversation
copilot-cli --import chat.json

Available CLI commands:

  • /system <message> - Set system message
  • /model <name> - Change model
  • /retry - Retry last message
  • /tokens - Show token count
  • /version - Show version info

🔍 Debugging

Enable debug mode for detailed logging:

import logging
logging.basicConfig(level=logging.DEBUG)

copilot = Copilot(debug=True)

🧪 Testing

Run the test suite:

# Install test dependencies
pip install -e ".[test]"

# Run tests with coverage
pytest --cov=copilot_api tests/

📋 Requirements

  • Python 3.7+
  • Core Dependencies:
    • requests>=2.25.0
    • websockets>=10.0
    • aiohttp>=3.8.0
    • python-dotenv>=0.19.0
    • tls-client>=0.2.0
    • beautifulsoup4>=4.9.3
  • CLI Dependencies:
    • click>=8.0.0
    • rich>=10.0.0
    • prompt-toolkit>=3.0.0

🤝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

# Clone the repository
git clone https://github.com/OE-LUCIFER/copilot-api.git

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

📝 License

This project is licensed under the HelpingAI License - see the LICENSE file for details.

The HelpingAI License is a proprietary license that grants specific rights while protecting HelpingAI's intellectual property. Please read the license carefully before using this software.

🌟 Support

📊 Project Stats

Alt

📈 Star History

Star History Chart


Built with ❤️ by OEvortex

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

copilot_api-1.0.0.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

copilot_api-1.0.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file copilot_api-1.0.0.tar.gz.

File metadata

  • Download URL: copilot_api-1.0.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for copilot_api-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8838366c5101240922a7bb17a40e8912944d41cbe9733830744b32e5d93d2bb6
MD5 d655b94acd7e25bf17d8b741916059f9
BLAKE2b-256 d8bba20b013ed3d5fba5ef067d07fa9a9b6cc8eb8fbf88c7d648d7592b63bf40

See more details on using hashes here.

File details

Details for the file copilot_api-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: copilot_api-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for copilot_api-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bff850f6b8ce4933cee4867f3316e4f79800c12aec933311782870e08846334b
MD5 6f7c7ee6dff846de639afcdc0434b27d
BLAKE2b-256 a2b2f8ffe5140d515de4c83563912b9fdc37aca4a913f7ba1d489d52211cd3f7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page