-
Notifications
You must be signed in to change notification settings - Fork 25
Add Python SDK support for WorkOS Pipes #507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR adds Python SDK support for WorkOS Pipes by introducing a new Pipes module that enables retrieval of OAuth access tokens for third-party providers associated with AuthKit users.
Implementation Overview
The implementation follows the established SDK architecture patterns:
- Module Structure: Created
PipesandAsyncPipesclasses implementing thePipesModuleprotocol, consistent with other SDK modules - Type System: Defined Pydantic models in
workos/types/pipes/includingAccessToken,GetAccessTokenSuccessResponse, andGetAccessTokenFailureResponsewith proper use of Literal types for discriminated unions - Client Integration: Integrated into both
SyncClientandAsyncClientwith lazy initialization pattern - API Endpoint: Calls
POST /data-integrations/{provider}/tokenwith user_id and optional organization_id
Key Features
- Dual Response Handling: The module intelligently handles both success and failure responses by checking the
activefield and validating against the appropriate Pydantic model - Optional Parameters: Supports optional
organization_idparameter for scoping token requests - Comprehensive Testing: Includes 6 test cases covering sync/async variants, success/failure scenarios, and parameter handling
Code Quality
- ✅ Follows SDK architectural patterns consistently
- ✅ Proper type annotations with Protocol definitions
- ✅ No logging of sensitive access_token data
- ✅ Comprehensive test coverage with both sync and async tests
- ✅ Clean separation of concerns between module, types, and tests
- ✅ Proper integration with BaseClient protocol
The implementation is production-ready and maintains consistency with the existing codebase.
Confidence Score: 5/5
- This PR is safe to merge - it's a well-structured addition that follows all SDK patterns with no security concerns
- Score of 5 reflects a clean, well-tested implementation: follows established SDK patterns perfectly, includes comprehensive test coverage for both sync and async variants, properly handles success/failure cases, integrates cleanly into existing client architecture, and contains no security vulnerabilities or code quality issues
- No files require special attention - all changes are well-structured and follow existing patterns
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| workos/pipes.py | 5/5 | New Pipes module implementing get_access_token for both sync and async clients. Follows SDK patterns correctly with proper type annotations and Protocol definition. |
| workos/types/pipes/pipes.py | 5/5 | Pydantic models for access tokens and responses with proper Literal types. Clean type definitions with optional expiry handling. |
| tests/test_pipes.py | 5/5 | Comprehensive test coverage for both sync and async variants, covering success/failure cases and optional parameters. |
| workos/client.py | 5/5 | Integrated Pipes module into SyncClient with lazy initialization pattern. |
| workos/async_client.py | 5/5 | Integrated AsyncPipes module into AsyncClient with lazy initialization pattern. |
Sequence Diagram
sequenceDiagram
participant Client as Client/AsyncClient
participant Pipes as Pipes/AsyncPipes
participant HTTP as SyncHTTPClient/AsyncHTTPClient
participant API as WorkOS API
Client->>Pipes: get_access_token(provider, user_id, organization_id?)
activate Pipes
Pipes->>Pipes: Build json_data dict with user_id
alt organization_id provided
Pipes->>Pipes: Add organization_id to json_data
end
Pipes->>HTTP: request("data-integrations/{provider}/token", POST, json_data)
activate HTTP
HTTP->>API: POST /data-integrations/{provider}/token
activate API
alt Success - Token Retrieved
API-->>HTTP: {"active": true, "access_token": {...}}
HTTP-->>Pipes: response dict
Pipes->>Pipes: Check response.get("active") is True
Pipes->>Pipes: model_validate as GetAccessTokenSuccessResponse
Pipes-->>Client: GetAccessTokenSuccessResponse
else Failure - Not Installed or Needs Reauth
API-->>HTTP: {"active": false, "error": "not_installed|needs_reauthorization"}
HTTP-->>Pipes: response dict
Pipes->>Pipes: Check response.get("active") is True (False)
Pipes->>Pipes: model_validate as GetAccessTokenFailureResponse
Pipes-->>Client: GetAccessTokenFailureResponse
else HTTP Error (4xx/5xx)
API-->>HTTP: Error response
HTTP->>HTTP: Raise WorkOS Exception
HTTP-->>Pipes: Exception
Pipes-->>Client: Exception
end
deactivate API
deactivate HTTP
deactivate Pipes
1002334 to
60b59ef
Compare
Description
This adds the ability for the Python SDK to get WorkOS Pipes tokens associated with an AuthKit user.
Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.