Comprehensive development rules for building Python applications with DeepSeek API integration, covering project structure, type hints, testing, and async patterns.
## DeepSeek Python Development Rules
### Project Structure
```
project/
src/
deepseek_client.py # API wrapper with retry logic
models.py # Pydantic models for request/response
prompts/ # Prompt templates as .txt or .j2 files
utils.py # Token counting, text processing
tests/
test_client.py
test_prompts.py
fixtures/ # Sample API responses for testing
.env # API keys (gitignored)
pyproject.toml
```
### Code Standards
- Python 3.10+ with type hints on all functions
- Use Pydantic v2 for request/response models
- Use httpx for async HTTP calls (not requests)
- Use tenacity for retry logic
- Format with ruff, type-check with mypy
### API Client Pattern
- Create a singleton client with connection pooling
- Use async/await for all API calls
- Implement proper timeout handling (connect: 5s, read: 120s)
- Parse streaming responses with async generators
- Cache identical prompts with functools.lru_cache or Redis
### Prompt Management
- Store prompts as separate template files, not inline strings
- Use Jinja2 templating for dynamic prompt construction
- Version prompts alongside code
- Log prompt templates (not filled values) for debugging
- A/B test prompt variants with feature flags
### Testing
- Mock API calls in unit tests (use respx or pytest-httpx)
- Create fixtures from real API responses
- Test edge cases: empty responses, malformed JSON, timeouts
- Integration tests against the real API in CI (with budget limits)
- Measure and track prompt quality metrics over timeSystem rules for designing inter-service communication in microservices architectures with DeepSeek Coder, covering sync/async patterns, error handling, and resilience.
System rules for generating content in multiple languages with DeepSeek V3, covering translation quality, cultural adaptation, locale-specific formatting, and quality assurance.
System rules for safe code refactoring with DeepSeek R1, requiring test coverage verification, incremental changes, and behavior preservation checks.
System rules for using DeepSeek V3 to generate clear, maintainable technical documentation including API docs, architecture docs, and onboarding guides.
System rules for DeepSeek Coder to generate optimized database queries, with requirements for EXPLAIN analysis, indexing recommendations, and performance targets.
System rules for using DeepSeek V3 to generate infrastructure code, CI/CD pipelines, and operational runbooks with security and reliability best practices.