|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +### Installation and Setup |
| 8 | +```bash |
| 9 | +pip install -e .[dev] # Install package in development mode with dev dependencies |
| 10 | +``` |
| 11 | + |
| 12 | +### Code Quality |
| 13 | +```bash |
| 14 | +black . # Format code |
| 15 | +black --check . # Check formatting without making changes |
| 16 | +flake8 . # Lint code |
| 17 | +mypy # Type checking |
| 18 | +``` |
| 19 | + |
| 20 | +### Testing |
| 21 | +```bash |
| 22 | +python -m pytest # Run all tests |
| 23 | +python -m pytest tests/test_sso.py # Run specific test file |
| 24 | +python -m pytest -k "test_name" # Run tests matching pattern |
| 25 | +python -m pytest --cov=workos # Run tests with coverage |
| 26 | +``` |
| 27 | + |
| 28 | +### Build and Distribution |
| 29 | +```bash |
| 30 | +python setup.py sdist bdist_wheel # Build distribution packages |
| 31 | +bash scripts/build_and_upload_dist.sh # Build and upload to PyPI |
| 32 | +``` |
| 33 | + |
| 34 | +## Architecture Overview |
| 35 | + |
| 36 | +### Client Architecture |
| 37 | +The SDK provides both synchronous and asynchronous clients: |
| 38 | +- `WorkOSClient` (sync) and `AsyncWorkOSClient` (async) are the main entry points |
| 39 | +- Both inherit from `BaseClient` which handles configuration and module initialization |
| 40 | +- Each feature area (SSO, Directory Sync, etc.) has dedicated module classes |
| 41 | +- HTTP clients (`SyncHTTPClient`/`AsyncHTTPClient`) handle the actual API communication |
| 42 | + |
| 43 | +### Module Structure |
| 44 | +Each WorkOS feature has its own module following this pattern: |
| 45 | +- **Module class** (e.g., `SSO`) - main API interface |
| 46 | +- **Types directory** (e.g., `workos/types/sso/`) - Pydantic models for API objects |
| 47 | +- **Tests** (e.g., `tests/test_sso.py`) - comprehensive test coverage |
| 48 | + |
| 49 | +### Type System |
| 50 | +- All models inherit from `WorkOSModel` (extends Pydantic `BaseModel`) |
| 51 | +- Strict typing with mypy enforcement (`strict = True` in mypy.ini) |
| 52 | +- Support for both sync and async operations via `SyncOrAsync` typing |
| 53 | + |
| 54 | +### Testing Framework |
| 55 | +- Uses pytest with custom fixtures for mocking HTTP clients |
| 56 | +- `@pytest.mark.sync_and_async()` decorator runs tests for both sync/async variants |
| 57 | +- Comprehensive fixtures in `conftest.py` for HTTP mocking and pagination testing |
| 58 | +- Test utilities in `tests/utils/` for common patterns |
| 59 | + |
| 60 | +### HTTP Client Abstraction |
| 61 | +- Base HTTP client (`_BaseHTTPClient`) with sync/async implementations |
| 62 | +- Request helper utilities for consistent API interaction patterns |
| 63 | +- Built-in pagination support with `WorkOSListResource` type |
| 64 | +- Automatic retry and error handling |
| 65 | + |
| 66 | +### Key Patterns |
| 67 | +- **Dual client support**: Every module supports both sync and async operations |
| 68 | +- **Type safety**: Extensive use of Pydantic models and strict mypy checking |
| 69 | +- **Pagination**: Consistent cursor-based pagination across list endpoints |
| 70 | +- **Error handling**: Custom exception classes in `workos/exceptions.py` |
| 71 | +- **Configuration**: Environment variable support (`WORKOS_API_KEY`, `WORKOS_CLIENT_ID`) |
| 72 | + |
| 73 | +When adding new features: |
| 74 | +1. Create module class with both sync/async HTTP client support |
| 75 | +2. Add Pydantic models in appropriate `types/` subdirectory |
| 76 | +3. Implement comprehensive tests using the sync_and_async marker |
| 77 | +4. Follow existing patterns for pagination, error handling, and type annotations |
0 commit comments