This document provides guidance for AI agents (like GitHub Copilot, ChatGPT, Cursor, etc.) working on this codebase.
vtube-python (vtpy) is a Python library for interfacing with VTube Studio's WebSocket API. VTube Studio is a desktop application that allows users to control Live2D avatars using face tracking.
- Python 3.8+: The library supports Python 3.8 and above
- WebSockets: Communication with VTube Studio uses WebSocket protocol
- Async/Await: The library uses asyncio for asynchronous operations
- VTube Studio API: Based on the official API documentation at https://github.com/DenchiSoft/VTubeStudio
- Async-First: All API calls should be asynchronous using
async/await - Type Hints: Use type hints throughout the codebase for better IDE support
- Error Handling: Provide clear, actionable error messages
- Documentation: Include docstrings for all public classes and methods
- Testing: Write tests for all new features
- Follow PEP 8 guidelines
- Use Black for code formatting (line length: 100)
- Use Ruff for linting
- Use type hints with
typingmodule - Prefer
f-stringsfor string formatting
async def api_method(self, param: str) -> ResponseType:
"""Method description.
Args:
param: Parameter description
Returns:
Response description
Raises:
VTubeStudioError: Error description
"""
request = {
"apiName": "VTubeStudioPublicAPI",
"apiVersion": "1.0",
"requestID": self._generate_request_id(),
"messageType": "RequestType",
"data": {
"param": param
}
}
response = await self._send_request(request)
return ResponseType.from_dict(response["data"])from vtpy.exceptions import VTubeStudioError
if not response.get("data"):
raise VTubeStudioError(f"Invalid response: {response}")- Place tests in the
tests/directory - Use pytest with pytest-asyncio for async tests
- Mock WebSocket connections in tests
- Aim for >80% code coverage
- Check the VTube Studio API documentation for the endpoint
- Create a corresponding method in the appropriate class
- Add type hints and docstrings
- Write tests
- Update documentation if needed
- Follow the existing code patterns