Skip to content

Commit fda2f5e

Browse files
committed
Rewrite CLAUDE.md
1 parent 1516214 commit fda2f5e

File tree

1 file changed

+48
-33
lines changed

1 file changed

+48
-33
lines changed

CLAUDE.md

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

5+
## Code Generation
6+
7+
Most of the SDK is **auto-generated** by `oagen` (an internal OpenAPI code generator). Generated files begin with `# This file is auto-generated by oagen. Do not edit.` Hand-maintained code is fenced with `@oagen-ignore-start` / `@oagen-ignore-end` markers (e.g., `session.py`, `passwordless.py`, `vault.py`).
8+
59
## Development Commands
610

711
### Installation and Setup
@@ -16,7 +20,7 @@ uv sync --locked --dev # Install package in development mode with dev dependenci
1620
uv run ruff format . # Format code
1721
uv run ruff format --check . # Check formatting without making changes
1822
uv run ruff check . # Lint code
19-
uv run mypy # Type checking
23+
uv run pyright # Type checking
2024
```
2125

2226
### Testing
@@ -69,50 +73,61 @@ bash scripts/build_and_upload_dist.sh # Build and upload to PyPI
6973

7074
The SDK provides both synchronous and asynchronous clients:
7175

72-
- `WorkOSClient` (sync) and `AsyncWorkOSClient` (async) are the main entry points
73-
- Both inherit from `BaseClient` which handles configuration and module initialization
74-
- Each feature area (SSO, Directory Sync, etc.) has dedicated module classes
75-
- HTTP clients (`SyncHTTPClient`/`AsyncHTTPClient`) handle the actual API communication
76+
- `WorkOS` (sync) and `AsyncWorkOS` (async) are the main entry points (exported from `workos/__init__.py`)
77+
- Both inherit from `_BaseWorkOS` (in `workos/_client.py`) which handles configuration, HTTP transport, retry logic, and error mapping
78+
- Each feature area (SSO, Organizations, etc.) is exposed as a `@functools.cached_property` on the client for lazy loading
79+
- Complex feature areas use namespace classes (e.g., `UserManagementNamespace`, `OrganizationsNamespace`) to group sub-resources
80+
- Backward-compatible aliases exist: `WorkOSClient = WorkOS`, `AsyncWorkOSClient = AsyncWorkOS`
81+
- HTTP transport uses `httpx` directly; there is no separate HTTP client abstraction layer
7682

7783
### Module Structure
7884

79-
Each WorkOS feature has its own module following this pattern:
85+
Each feature module follows this layout:
86+
87+
```
88+
src/workos/{module_name}/
89+
__init__.py # Re-exports from _resource and models
90+
_resource.py # Sync and Async resource classes (e.g., SSO + AsyncSSO)
91+
models/
92+
__init__.py # Re-exports all model classes
93+
{model}.py # Individual dataclass model files
94+
```
8095

81-
- **Module class** (e.g., `SSO`) - main API interface
82-
- **Types directory** (e.g., `workos/types/sso/`) - Pydantic models for API objects
83-
- **Tests** (e.g., `tests/test_sso.py`) - comprehensive test coverage
96+
Resource classes take a `WorkOS` or `AsyncWorkOS` client reference and call `self._client.request()` or `self._client.request_page()` for paginated endpoints.
8497

8598
### Type System
8699

87-
- All models inherit from `WorkOSModel` (extends Pydantic `BaseModel`)
88-
- Strict typing with mypy enforcement (`strict = True` in mypy.ini)
89-
- Support for both sync and async operations via `SyncOrAsync` typing
100+
- All models use `@dataclass(slots=True)`**not** Pydantic
101+
- Each model implements `from_dict(cls, data) -> Self` for deserialization and `to_dict() -> Dict` for serialization
102+
- The `Deserializable` protocol in `workos/_types.py` defines the `from_dict` contract
103+
- `RequestOptions` (a `TypedDict`) allows per-call overrides for headers, timeout, retries, etc.
104+
- Type checking uses **pyright** (configured in `pyrightconfig.json`)
90105

91-
### Testing Framework
106+
### Pagination
92107

93-
- Uses pytest with custom fixtures for mocking HTTP clients
94-
- `@pytest.mark.sync_and_async()` decorator runs tests for both sync/async variants
95-
- Comprehensive fixtures in `conftest.py` for HTTP mocking and pagination testing
96-
- Test utilities in `tests/utils/` for common patterns
108+
- `SyncPage[T]` and `AsyncPage[T]` dataclasses in `workos/_pagination.py` represent paginated results
109+
- Cursor-based: `before`/`after` properties, `has_more()` check
110+
- `auto_paging_iter()` transparently fetches subsequent pages
111+
- Backward-compatible alias: `WorkOSListResource = SyncPage`
97112

98-
### HTTP Client Abstraction
113+
### Error Handling
99114

100-
- Base HTTP client (`_BaseHTTPClient`) with sync/async implementations
101-
- Request helper utilities for consistent API interaction patterns
102-
- Built-in pagination support with `WorkOSListResource` type
103-
- Automatic retry and error handling
115+
All exceptions live in `workos/_errors.py` and inherit from `WorkOSError`:
104116

105-
### Key Patterns
117+
- `BadRequestError` (400), `AuthenticationError` (401), `ForbiddenError` (403), `NotFoundError` (404), `ConflictError` (409), `UnprocessableEntityError` (422), `RateLimitExceededError` (429), `ServerError` (5xx)
118+
- `ConfigurationError`, `WorkOSConnectionError`, `WorkOSTimeoutError` for non-HTTP errors
119+
- `STATUS_CODE_TO_ERROR` dict maps status codes to exception classes
120+
121+
### Testing Framework
106122

107-
- **Dual client support**: Every module supports both sync and async operations
108-
- **Type safety**: Extensive use of Pydantic models and strict mypy checking
109-
- **Pagination**: Consistent cursor-based pagination across list endpoints
110-
- **Error handling**: Custom exception classes in `workos/exceptions.py`
111-
- **Configuration**: Environment variable support (`WORKOS_API_KEY`, `WORKOS_CLIENT_ID`)
123+
- Uses **pytest** with **pytest-httpx** for HTTP mocking (provides the `httpx_mock` fixture)
124+
- Separate test classes for sync (`TestSSO`) and async (`TestAsyncSSO`) variants
125+
- Async tests use `@pytest.mark.asyncio`
126+
- JSON fixtures in `tests/fixtures/`, loaded via `load_fixture()` from `tests/generated_helpers.py`
127+
- Client fixtures `workos` and `async_workos` defined in `tests/conftest.py`
112128

113-
When adding new features:
129+
### Configuration
114130

115-
1. Create module class with both sync/async HTTP client support
116-
2. Add Pydantic models in appropriate `types/` subdirectory
117-
3. Implement comprehensive tests using the sync_and_async marker
118-
4. Follow existing patterns for pagination, error handling, and type annotations
131+
- Environment variable support: `WORKOS_API_KEY`, `WORKOS_CLIENT_ID`
132+
- Retry logic: exponential backoff with jitter, retries on 429/5xx, respects `Retry-After` headers
133+
- Default timeout: 30 seconds

0 commit comments

Comments
 (0)