|
| 1 | +# SOLAPI-PYTHON KNOWLEDGE BASE |
| 2 | + |
| 3 | +**Generated:** 2026-01-21 |
| 4 | +**Commit:** b77fdd9 |
| 5 | +**Branch:** main |
| 6 | + |
| 7 | +## OVERVIEW |
| 8 | + |
| 9 | +Python SDK for SOLAPI messaging platform. Sends SMS/LMS/MMS/Kakao/Naver/RCS messages in Korea. Thin wrapper around REST API using httpx + Pydantic v2. |
| 10 | + |
| 11 | +## STRUCTURE |
| 12 | + |
| 13 | +``` |
| 14 | +solapi-python/ |
| 15 | +├── solapi/ # Main package (single export: SolapiMessageService) |
| 16 | +│ ├── services/ # message_service.py - all API operations |
| 17 | +│ ├── model/ # Pydantic models (see solapi/model/AGENTS.md) |
| 18 | +│ ├── lib/ # authenticator.py, fetcher.py |
| 19 | +│ └── error/ # MessageNotReceivedError only |
| 20 | +├── tests/ # pytest integration tests |
| 21 | +├── examples/ # Feature-based usage examples |
| 22 | +└── debug/ # Dev test scripts (not part of package) |
| 23 | +``` |
| 24 | + |
| 25 | +## WHERE TO LOOK |
| 26 | + |
| 27 | +| Task | Location | Notes | |
| 28 | +|------|----------|-------| |
| 29 | +| Send messages | `solapi/services/message_service.py` | All 10 API methods in single class | |
| 30 | +| Request models | `solapi/model/request/` | Pydantic BaseModel with validators | |
| 31 | +| Response models | `solapi/model/response/` | Separate from request models | |
| 32 | +| Kakao/Naver/RCS | `solapi/model/{kakao,naver,rcs}/` | Domain-specific models | |
| 33 | +| Authentication | `solapi/lib/authenticator.py` | HMAC-SHA256 signature | |
| 34 | +| HTTP client | `solapi/lib/fetcher.py` | httpx with 3 retries | |
| 35 | +| Test fixtures | `tests/conftest.py` | env-based credentials | |
| 36 | +| Usage examples | `examples/simple/` | Copy-paste ready | |
| 37 | + |
| 38 | +## CONVENTIONS |
| 39 | + |
| 40 | +### Pydantic Everywhere |
| 41 | +- ALL models extend `BaseModel` |
| 42 | +- Field aliases: `Field(alias="camelCase")` for API compatibility |
| 43 | +- Validators: `@field_validator` for normalization (e.g., phone numbers) |
| 44 | + |
| 45 | +### Model Organization (Domain-Driven) |
| 46 | +``` |
| 47 | +model/ |
| 48 | +├── request/ # Outbound API payloads |
| 49 | +├── response/ # Inbound API responses |
| 50 | +├── kakao/ # Kakao-specific (option, button) |
| 51 | +├── naver/ # Naver-specific |
| 52 | +├── rcs/ # RCS-specific |
| 53 | +└── webhook/ # Delivery reports |
| 54 | +``` |
| 55 | + |
| 56 | +### Naming |
| 57 | +- Files: `snake_case.py` |
| 58 | +- Classes: `PascalCase` |
| 59 | +- Request suffix: `*Request` (e.g., `SendMessageRequest`) |
| 60 | +- Response suffix: `*Response` (e.g., `SendMessageResponse`) |
| 61 | + |
| 62 | +### Code Style (Ruff) |
| 63 | +- Line length: 88 |
| 64 | +- Quote style: double |
| 65 | +- Import sorting: isort (I rule) |
| 66 | +- Target: Python 3.9+ |
| 67 | + |
| 68 | +### Tidy First Principles |
| 69 | +- Never mix refactoring and feature changes in the same commit |
| 70 | +- Tidy related code before making behavioral changes |
| 71 | +- Tidying: guard clauses, dead code removal, rename, extract conditionals |
| 72 | +- Separate tidying commits from feature commits |
| 73 | + |
| 74 | +## ANTI-PATTERNS (THIS PROJECT) |
| 75 | + |
| 76 | +### NEVER |
| 77 | +- Add CLI/console scripts - this is library-only |
| 78 | +- Create multiple service classes - all goes in `SolapiMessageService` |
| 79 | +- Mix request/response models - they're deliberately separate |
| 80 | +- Use dataclasses or TypedDict for API models - Pydantic only |
| 81 | +- Hardcode credentials - use env vars |
| 82 | + |
| 83 | +### VERSION SYNC REQUIRED |
| 84 | +```python |
| 85 | +# solapi/model/request/__init__.py |
| 86 | +VERSION = "python/5.0.3" # MUST update on every release! |
| 87 | +``` |
| 88 | +Also update `pyproject.toml` version. |
| 89 | + |
| 90 | +## UNIQUE PATTERNS |
| 91 | + |
| 92 | +### Single Service Class |
| 93 | +```python |
| 94 | +# All API methods in one class (318 lines) |
| 95 | +class SolapiMessageService: |
| 96 | + def send(...) # SMS/LMS/MMS/Kakao/Naver/RCS |
| 97 | + def upload_file(...) # Storage |
| 98 | + def get_balance(...) # Account |
| 99 | + def get_groups(...) # Message groups |
| 100 | + def get_messages(...) # Message history |
| 101 | + def cancel_scheduled_message(...) |
| 102 | +``` |
| 103 | + |
| 104 | +### Minimal Error Handling |
| 105 | +- Only `MessageNotReceivedError` exists |
| 106 | +- API errors raised as generic `Exception` with errorCode, errorMessage |
| 107 | + |
| 108 | +### Authentication Flow |
| 109 | +``` |
| 110 | +SolapiMessageService.__init__(api_key, api_secret) |
| 111 | + → Authenticator.get_auth_info() |
| 112 | + → HMAC-SHA256 signature |
| 113 | + → Authorization header |
| 114 | +``` |
| 115 | + |
| 116 | +## COMMANDS |
| 117 | + |
| 118 | +```bash |
| 119 | +# Install |
| 120 | +pip install solapi |
| 121 | + |
| 122 | +# Dev setup |
| 123 | +pip install -e ".[dev]" |
| 124 | + |
| 125 | +# Lint & format |
| 126 | +ruff check --fix . |
| 127 | +ruff format . |
| 128 | + |
| 129 | +# Test (requires env vars) |
| 130 | +export SOLAPI_API_KEY="..." |
| 131 | +export SOLAPI_API_SECRET="..." |
| 132 | +export SOLAPI_SENDER="..." |
| 133 | +export SOLAPI_RECIPIENT="..." |
| 134 | +pytest |
| 135 | + |
| 136 | +# Build |
| 137 | +python -m build |
| 138 | +``` |
| 139 | + |
| 140 | +## ENV VARS (Testing) |
| 141 | + |
| 142 | +| Variable | Purpose | |
| 143 | +|----------|---------| |
| 144 | +| `SOLAPI_API_KEY` | API authentication | |
| 145 | +| `SOLAPI_API_SECRET` | API authentication | |
| 146 | +| `SOLAPI_SENDER` | Registered sender number | |
| 147 | +| `SOLAPI_RECIPIENT` | Test recipient number | |
| 148 | +| `SOLAPI_KAKAO_PF_ID` | Kakao business channel | |
| 149 | +| `SOLAPI_KAKAO_TEMPLATE_ID` | Kakao template | |
| 150 | + |
| 151 | +## NOTES |
| 152 | + |
| 153 | +- No CI/CD pipeline - testing/linting is local only |
| 154 | +- uv workspace includes Django webhook example |
| 155 | +- Tests are integration tests (hit real API) |
| 156 | +- Korean comments in some files (i18n TODO exists) |
0 commit comments