|
| 1 | +# Pipedream Python SDK |
| 2 | + |
| 3 | +A Python client library for the [Pipedream Connect API](https://pipedream.com/docs/connect). |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +pip install pipedream-sdk |
| 9 | +``` |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +### Using OAuth Credentials |
| 14 | + |
| 15 | +```python |
| 16 | +from pipedream_sdk import create_client, OAuthCredentials |
| 17 | + |
| 18 | +# Create client with OAuth credentials |
| 19 | +credentials = OAuthCredentials( |
| 20 | + client_id="your_client_id", |
| 21 | + client_secret="your_client_secret" |
| 22 | +) |
| 23 | + |
| 24 | +client = create_client( |
| 25 | + project_id="your_project_id", |
| 26 | + credentials=credentials, |
| 27 | + environment="development" # or "production" |
| 28 | +) |
| 29 | + |
| 30 | +# Create a Connect token for user authentication |
| 31 | +token_response = client.create_connect_token({ |
| 32 | + "external_user_id": "user123", |
| 33 | + "success_redirect_uri": "https://yourapp.com/success", |
| 34 | + "error_redirect_uri": "https://yourapp.com/error" |
| 35 | +}) |
| 36 | + |
| 37 | +print(f"Connect URL: {token_response.connect_link_url}") |
| 38 | +``` |
| 39 | + |
| 40 | +### Using Access Token |
| 41 | + |
| 42 | +```python |
| 43 | +from pipedream_sdk import create_client, AccessTokenCredentials |
| 44 | + |
| 45 | +# Create client with access token |
| 46 | +credentials = AccessTokenCredentials(access_token="your_access_token") |
| 47 | + |
| 48 | +client = create_client( |
| 49 | + project_id="your_project_id", |
| 50 | + credentials=credentials |
| 51 | +) |
| 52 | +``` |
| 53 | + |
| 54 | +## Core Features |
| 55 | + |
| 56 | +### Account Management |
| 57 | + |
| 58 | +```python |
| 59 | +# Get all connected accounts |
| 60 | +accounts = client.get_accounts() |
| 61 | + |
| 62 | +# Get accounts for a specific user |
| 63 | +accounts = client.get_accounts({ |
| 64 | + "external_user_id": "user123", |
| 65 | + "include_credentials": True |
| 66 | +}) |
| 67 | + |
| 68 | +# Get a specific account |
| 69 | +account = client.get_account_by_id("account_id", { |
| 70 | + "include_credentials": True |
| 71 | +}) |
| 72 | + |
| 73 | +# Delete an account |
| 74 | +client.delete_account("account_id") |
| 75 | + |
| 76 | +# Delete all accounts for an external user |
| 77 | +client.delete_external_user("user123") |
| 78 | +``` |
| 79 | + |
| 80 | +### App Discovery |
| 81 | + |
| 82 | +```python |
| 83 | +# Get all available apps |
| 84 | +apps = client.get_apps() |
| 85 | + |
| 86 | +# Search for apps |
| 87 | +apps = client.get_apps({ |
| 88 | + "q": "slack", |
| 89 | + "has_actions": True, |
| 90 | + "limit": 10 |
| 91 | +}) |
| 92 | + |
| 93 | +# Get a specific app |
| 94 | +app = client.get_app("slack") |
| 95 | +``` |
| 96 | + |
| 97 | +### Component Management |
| 98 | + |
| 99 | +```python |
| 100 | +from pipedream_sdk.types import ComponentType |
| 101 | + |
| 102 | +# Get all components |
| 103 | +components = client.get_components() |
| 104 | + |
| 105 | +# Get components for a specific app |
| 106 | +components = client.get_components({ |
| 107 | + "app": "slack", |
| 108 | + "component_type": ComponentType.ACTION |
| 109 | +}) |
| 110 | + |
| 111 | +# Get a specific component |
| 112 | +component = client.get_component({"key": "slack-send-message"}) |
| 113 | + |
| 114 | +# Configure a component prop |
| 115 | +config_response = client.configure_component({ |
| 116 | + "external_user_id": "user123", |
| 117 | + "component_id": "slack-send-message", |
| 118 | + "prop_name": "channel", |
| 119 | + "configured_props": {"text": "Hello world"} |
| 120 | +}) |
| 121 | +``` |
| 122 | + |
| 123 | +### Running Actions |
| 124 | + |
| 125 | +```python |
| 126 | +# Run an action |
| 127 | +result = client.run_action({ |
| 128 | + "external_user_id": "user123", |
| 129 | + "action_id": "slack-send-message", |
| 130 | + "configured_props": { |
| 131 | + "channel": "#general", |
| 132 | + "text": "Hello from Pipedream!" |
| 133 | + } |
| 134 | +}) |
| 135 | + |
| 136 | +print(f"Action result: {result.ret}") |
| 137 | +``` |
| 138 | + |
| 139 | +### Trigger Management |
| 140 | + |
| 141 | +```python |
| 142 | +# Deploy a trigger |
| 143 | +trigger = client.deploy_trigger({ |
| 144 | + "external_user_id": "user123", |
| 145 | + "trigger_id": "github-new-commit", |
| 146 | + "configured_props": { |
| 147 | + "repo": "username/repo" |
| 148 | + }, |
| 149 | + "webhook_url": "https://yourapp.com/webhook" |
| 150 | +}) |
| 151 | + |
| 152 | +# Get deployed triggers |
| 153 | +triggers = client.get_triggers({ |
| 154 | + "external_user_id": "user123" |
| 155 | +}) |
| 156 | + |
| 157 | +# Update a trigger |
| 158 | +client.update_trigger({ |
| 159 | + "id": trigger.id, |
| 160 | + "external_user_id": "user123", |
| 161 | + "active": False |
| 162 | +}) |
| 163 | + |
| 164 | +# Get trigger events |
| 165 | +events = client.get_trigger_events({ |
| 166 | + "id": trigger.id, |
| 167 | + "external_user_id": "user123", |
| 168 | + "limit": 10 |
| 169 | +}) |
| 170 | + |
| 171 | +# Delete a trigger |
| 172 | +client.delete_trigger({ |
| 173 | + "id": trigger.id, |
| 174 | + "external_user_id": "user123" |
| 175 | +}) |
| 176 | +``` |
| 177 | + |
| 178 | +### Workflow Invocation |
| 179 | + |
| 180 | +```python |
| 181 | +from pipedream_sdk.types import HTTPAuthType |
| 182 | + |
| 183 | +# Invoke a workflow |
| 184 | +response = client.invoke_workflow( |
| 185 | + "https://your-workflow-url.m.pipedream.net", |
| 186 | + data={"message": "Hello"}, |
| 187 | + auth_type=HTTPAuthType.NONE |
| 188 | +) |
| 189 | + |
| 190 | +# Invoke a workflow for a specific user |
| 191 | +response = client.invoke_workflow_for_external_user( |
| 192 | + "https://your-workflow-url.m.pipedream.net", |
| 193 | + external_user_id="user123", |
| 194 | + data={"message": "Hello"} |
| 195 | +) |
| 196 | +``` |
| 197 | + |
| 198 | +### Proxy API |
| 199 | + |
| 200 | +```python |
| 201 | +# Make a proxy request on behalf of a user |
| 202 | +response = client.make_proxy_request( |
| 203 | + proxy_opts={ |
| 204 | + "search_params": { |
| 205 | + "external_user_id": "user123", |
| 206 | + "account_id": "account_456" |
| 207 | + } |
| 208 | + }, |
| 209 | + target_request={ |
| 210 | + "url": "https://api.github.com/user/repos", |
| 211 | + "options": { |
| 212 | + "method": "GET", |
| 213 | + "headers": {"Accept": "application/json"} |
| 214 | + } |
| 215 | + } |
| 216 | +) |
| 217 | +``` |
| 218 | + |
| 219 | +## Error Handling |
| 220 | + |
| 221 | +The SDK raises exceptions for API errors: |
| 222 | + |
| 223 | +```python |
| 224 | +try: |
| 225 | + account = client.get_account_by_id("invalid_id") |
| 226 | +except Exception as e: |
| 227 | + print(f"API Error: {e}") |
| 228 | +``` |
| 229 | + |
| 230 | +## Development |
| 231 | + |
| 232 | +### Setup |
| 233 | + |
| 234 | +```bash |
| 235 | +git clone https://github.com/PipedreamHQ/pipedream.git |
| 236 | +cd pipedream/python-sdk |
| 237 | +pip install -e . |
| 238 | +pip install -r requirements-dev.txt |
| 239 | +``` |
| 240 | + |
| 241 | +### Testing |
| 242 | + |
| 243 | +```bash |
| 244 | +pytest |
| 245 | +``` |
| 246 | + |
| 247 | +### Code Formatting |
| 248 | + |
| 249 | +```bash |
| 250 | +black pipedream_sdk/ |
| 251 | +flake8 pipedream_sdk/ |
| 252 | +mypy pipedream_sdk/ |
| 253 | +``` |
| 254 | + |
| 255 | +## Requirements |
| 256 | + |
| 257 | +- Python 3.8+ |
| 258 | +- No external dependencies (uses only Python standard library) |
| 259 | + |
| 260 | +## Documentation |
| 261 | + |
| 262 | +For detailed API documentation, visit [Pipedream Connect Docs](https://pipedream.com/docs/connect). |
| 263 | + |
| 264 | +## License |
| 265 | + |
| 266 | +See the main Pipedream repository for license information. |
0 commit comments