CoCalc Python API Client
This is a Python package that provides an API client for CoCalc, enabling programmatic access to CoCalc's features including project management, Jupyter execution, file operations, messaging, and organization management.
Installation
Quick Start
Features
Hub Client (Account-Level Operations)
The Hub class provides access to account-level operations:
System: Server ping, user search, account name resolution
Projects: Project management (create, start, stop, add/remove collaborators)
Jupyter: Execute code using Jupyter kernels in any project or anonymously
Database: Direct PostgreSQL database queries for advanced operations
Messages: Send and receive messages between users
Organizations: Manage organizations, users, and temporary access tokens
Sync: Access file edit history and synchronization features
Project Client (Project-Specific Operations)
The Project class provides project-specific operations:
System: Execute shell commands and Jupyter code within a specific project
MCP Server
The CoCalc API includes a Model Context Protocol (MCP) server that allows LLMs (like Claude) to interact with CoCalc projects through a standardized protocol.
For detailed setup instructions and usage guide, see src/cocalc_api/mcp/README.md.
Authentication
The client supports two types of API keys:
Account API Keys: Provide full access to all hub functionality
Project API Keys: Limited to project-specific operations
Get your API key from CoCalc Account Settings under "API Keys".
Architecture
Package Structure
Design Patterns
Decorator-based Methods: Uses
@api_method()decorator to automatically convert method calls to API requestsTypedDict Responses: All API responses use TypedDict for type safety
Error Handling: Centralized error handling via
handle_error()utilityHTTP Client: Uses
httpxfor HTTP requests with authenticationNested Namespaces: API organized into logical namespaces (system, projects, jupyter, etc.)
Development
Requirements
Python 3.9+
uv package manager
Setup
Code Quality
This project uses multiple tools for code quality:
YAPF: Python code formatter
Ruff: Fast Python linter
MyPy: Static type checking
Pyright: Additional static type checking
MkDocs: Documentation generation
Documentation Standards
All docstrings follow the Google Style Guide for Python docstrings. This includes:
Clear one-line summary
Detailed description when needed
Properly formatted
Args:,Returns:,Raises:, andExamples:sectionsType information consistent with function signatures
Consistent capitalization and punctuation
Example:
License
MIT License. See the LICENSE file for details.