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 timeWorkflows from the Neura Market marketplace related to this DeepSeek resource