snaptrade-python-sdk 13.3.0__py3-none-any.whl → 13.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,7 @@
12
12
  Created by: https://snaptrade.com/
13
13
  """
14
14
 
15
- __version__ = "13.3.0"
15
+ __version__ = "13.4.0"
16
16
 
17
17
  # import ApiClient
18
18
  from snaptrade_client.api_client import ApiClient
@@ -1175,7 +1175,7 @@ class ApiClient(typing.Generic[TAuth]):
1175
1175
  self.default_headers[header_name] = header_value
1176
1176
  self.cookie = cookie
1177
1177
  # Set default User-Agent.
1178
- self.user_agent = 'Konfig/13.3.0/python'
1178
+ self.user_agent = 'Konfig/13.4.0/python'
1179
1179
 
1180
1180
  def __enter__(self):
1181
1181
  return self
@@ -537,7 +537,7 @@ conf = snaptrade_client.Configuration(
537
537
  "OS: {env}\n"\
538
538
  "Python Version: {pyversion}\n"\
539
539
  "Version of the API: 1.0.0\n"\
540
- "SDK Package Version: 13.3.0".\
540
+ "SDK Package Version: 13.4.0".\
541
541
  format(env=sys.platform, pyversion=sys.version)
542
542
 
543
543
  def get_host_settings(self):
snaptrade_client/oauth.py CHANGED
@@ -135,11 +135,13 @@ class SnapTradeOAuth:
135
135
  issuer: typing.Optional[str] = None,
136
136
  authorization_endpoint: typing.Optional[str] = None,
137
137
  token_endpoint: typing.Optional[str] = None,
138
+ revocation_endpoint: typing.Optional[str] = None,
138
139
  timeout: typing.Optional[float] = None,
139
140
  ):
140
141
  self.issuer = _trim_trailing_slash(_origin(issuer or "https://api.snaptrade.com"))
141
142
  self.authorization_endpoint = authorization_endpoint
142
143
  self.token_endpoint = token_endpoint
144
+ self.revocation_endpoint = revocation_endpoint
143
145
  self.client_id = client_id
144
146
  self.redirect_uri = redirect_uri
145
147
  self.client_secret = client_secret
@@ -206,6 +208,27 @@ class SnapTradeOAuth:
206
208
  },
207
209
  )
208
210
 
211
+ def revoke_token(
212
+ self,
213
+ *,
214
+ token: str,
215
+ token_type_hint: typing.Optional[typing.Literal["access_token", "refresh_token"]] = None,
216
+ ) -> None:
217
+ """Revoke the supplied token; unknown tokens succeed.
218
+
219
+ Refresh-token revocation also invalidates its paired access token.
220
+ Independent token pairs remain valid.
221
+ """
222
+ endpoint = self.revocation_endpoint
223
+ if not endpoint:
224
+ endpoint = self._fetch_server_metadata().get("revocation_endpoint")
225
+ if not endpoint:
226
+ raise RuntimeError("OAuth server metadata did not include revocation_endpoint.")
227
+ body = {"token": token, "client_id": self.client_id}
228
+ if token_type_hint is not None:
229
+ body["token_type_hint"] = token_type_hint
230
+ self._post_form_request(endpoint, body)
231
+
209
232
  def _resolve_endpoints(self) -> _ResolvedEndpoints:
210
233
  if self.authorization_endpoint and self.token_endpoint:
211
234
  return _ResolvedEndpoints(
@@ -240,6 +263,14 @@ class SnapTradeOAuth:
240
263
  body: typing.Dict[str, str],
241
264
  ) -> SnapTradeOAuthTokenResponse:
242
265
  endpoints = self._resolve_endpoints()
266
+ raw = self._post_form_request(endpoints.token_endpoint, body)
267
+ return _normalize_token_response(raw)
268
+
269
+ def _post_form_request(
270
+ self,
271
+ endpoint: str,
272
+ body: typing.Dict[str, str],
273
+ ) -> typing.Dict[str, typing.Any]:
243
274
  client_id = self.client_id
244
275
  client_secret = self.client_secret
245
276
  resolved_client_auth_method = self.client_auth_method or ("client_secret_basic" if client_secret else "none")
@@ -257,11 +288,10 @@ class SnapTradeOAuth:
257
288
  elif resolved_client_auth_method != "none":
258
289
  raise RuntimeError(f"Unsupported OAuth client_auth_method: {resolved_client_auth_method}")
259
290
 
260
- raw = _json_request(
261
- endpoints.token_endpoint,
291
+ return _json_request(
292
+ endpoint,
262
293
  method="POST",
263
294
  body=urllib.parse.urlencode(request_body),
264
295
  headers=headers,
265
296
  timeout=self.timeout,
266
297
  )
267
- return _normalize_token_response(raw)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: snaptrade-python-sdk
3
- Version: 13.3.0
3
+ Version: 13.4.0
4
4
  Summary: Client for SnapTrade
5
5
  License: MIT
6
6
  Author: SnapTrade
@@ -87,7 +87,7 @@ See https://docs.snaptrade.com/docs/ratelimiting.
87
87
 
88
88
 
89
89
 
90
- [![PyPI](https://img.shields.io/badge/PyPI-v13.3.0-blue)](https://pypi.org/project/snaptrade-python-sdk/13.3.0)
90
+ [![PyPI](https://img.shields.io/badge/PyPI-v13.4.0-blue)](https://pypi.org/project/snaptrade-python-sdk/13.4.0)
91
91
  [![README.md](https://img.shields.io/badge/README-Click%20Here-green)](https://github.com/passiv/snaptrade-sdks/tree/master/sdks/python#readme)
92
92
  [![More Info](https://img.shields.io/badge/More%20Info-Click%20Here-orange)](https://snaptrade.com/)
93
93
 
@@ -104,7 +104,7 @@ See https://docs.snaptrade.com/docs/ratelimiting.
104
104
  * [Personal API Key Auth authentication](#personal-api-key-auth-authentication)
105
105
  * [OAuth Auth authentication](#oauth-auth-authentication)
106
106
  * [Device login](#device-login)
107
- * [Browser OAuth and explicit refresh](#browser-oauth-and-explicit-refresh)
107
+ * [Browser OAuth, explicit refresh and revocation](#browser-oauth-explicit-refresh-and-revocation)
108
108
  - [Getting Started](#getting-started)
109
109
  - [Request timeouts](#request-timeouts)
110
110
  - [Async](#async)
@@ -184,7 +184,7 @@ Python >=3.8
184
184
  ## Installation<a id="installation"></a>
185
185
 
186
186
  ```sh
187
- pip install snaptrade-python-sdk==13.3.0
187
+ pip install snaptrade-python-sdk==13.4.0
188
188
  ```
189
189
 
190
190
  ## Authentication<a id="authentication"></a>
@@ -258,7 +258,7 @@ interrupt polling waits. An in-flight request is bounded by the HTTP timeout
258
258
  `SnapTradeOAuthDeviceError` and inspect `.error` for denial, expiry or cancellation.
259
259
  Applications own token storage and refresh, including refresh-token rotation.
260
260
 
261
- ### Browser OAuth and explicit refresh<a id="browser-oauth-and-explicit-refresh"></a>
261
+ ### Browser OAuth, explicit refresh and revocation<a id="browser-oauth-explicit-refresh-and-revocation"></a>
262
262
 
263
263
  Configure confidential-client credentials on your backend. The synchronous helper generates fresh state and S256 PKCE and uses server discovery by default. Run blocking calls in a worker thread in asynchronous apps.
264
264
 
@@ -284,6 +284,8 @@ refreshed_client = SnapTrade(
284
284
 
285
285
  Token responses include `access_token`, `refresh_token`, `expires_in`, `token_type`, `scope`, and `raw`. Applications own token storage, callback validation, refresh scheduling and concurrency. A configured secret defaults to `client_secret_basic`; public clients omit the secret. Browser code must never receive a confidential-client secret.
286
286
 
287
+ To revoke a token explicitly, call `oauth.revoke_token(token=token, token_type_hint="refresh_token")`. The hint is optional (`"access_token"` or `"refresh_token"`). Success returns `None`, including for unknown or already revoked tokens. Revoking a refresh token also invalidates its paired access token; independent token pairs remain valid. The helper discovers `revocation_endpoint` or uses the constructor's `revocation_endpoint` override and reuses the configured client authentication. OAuth errors raise `RuntimeError` with the HTTP status and response body.
288
+
287
289
  ## Getting Started<a id="getting-started"></a>
288
290
 
289
291
  ```python
@@ -1,5 +1,5 @@
1
- snaptrade_client/__init__.py,sha256=WOkWOLO0TUV6bKOGH5HSyT6UbHVs7ZxBo3npl0EnrZM,4370
2
- snaptrade_client/api_client.py,sha256=8YU6AfoSIqSIYstnsYCQO9SqrMdCTHmX8WHsNl0Fl1Q,78308
1
+ snaptrade_client/__init__.py,sha256=WbU7EEtKIjpJLUebhslBkT8cxiV9o4JpaynlGgIw4w4,4370
2
+ snaptrade_client/api_client.py,sha256=96MnKftmVkj_WWrD3YR3upulZK5BdmAHRaywIdyf6EE,78308
3
3
  snaptrade_client/api_response.py,sha256=mZn18p_TNr6OY0HXTZW5InL9iXfqsJWstYGeGD-euPA,663
4
4
  snaptrade_client/apis/__init__.py,sha256=RTosXhMn41tMsKPUjIy-VK-_efOWzhkKiuGggJ3A6E0,214
5
5
  snaptrade_client/apis/path_to_api.py,sha256=xHjhZWAnlLIvvtGOQYUE-WmdDRZqhgkpB_auzT3rHG8,16169
@@ -89,7 +89,7 @@ snaptrade_client/auth.py,sha256=85VAIdB-s7SGAHoU0xZnPd7pc680Y58ILZgRiKVn2pk,4797
89
89
  snaptrade_client/client.py,sha256=ncRPbSzbjqr4YVdjzfm8IrCgFhawclXFRlYJzkHNu98,6361
90
90
  snaptrade_client/client.pyi,sha256=s5mcwbmAEVZMJrZOT3fTP9-_r7rf2L0qdJiX8RlnX9o,6358
91
91
  snaptrade_client/client_custom.py,sha256=hNQMRFrY_KWEOCgf36fsZBs3sBU2SQtnZin8dAEVyYo,3931
92
- snaptrade_client/configuration.py,sha256=i5rgB_j66UDRUsdzY2bEFFXthf1ntwIks2mmq889G9c,26562
92
+ snaptrade_client/configuration.py,sha256=LpU2CE14tQM9-dCpptuwddFPNdiz3u9UZ1km_3FMK48,26562
93
93
  snaptrade_client/exceptions.py,sha256=pRlZiy1hSulcXfTCqqBU5Jys0hRBkxljOiv212M_yeo,10957
94
94
  snaptrade_client/exceptions_base.py,sha256=LAQkaC5C61-SdBLfyMjb0K7AYJkWVuLmg2uCvHa71FM,2274
95
95
  snaptrade_client/model/__init__.py,sha256=ayi2MIzcf0eAIsY13ToiNplV9tW-pMBFrC0I9yckGM8,350
@@ -674,7 +674,7 @@ snaptrade_client/model/user_secret.pyi,sha256=BiF8M99Os_WXMHiGaivayDrU53MNuyr2Zj
674
674
  snaptrade_client/model/validated_trade_body.py,sha256=KOObe8mGtKr29bjV0l7cdiqKJQn3E22WqNIfHG-1Kig,6271
675
675
  snaptrade_client/model/validated_trade_body.pyi,sha256=KOObe8mGtKr29bjV0l7cdiqKJQn3E22WqNIfHG-1Kig,6271
676
676
  snaptrade_client/models/__init__.py,sha256=E9m_lnITxLRwD-bl4a5KWafO0hXIhFgXmGyb3PYIMm0,23526
677
- snaptrade_client/oauth.py,sha256=ucxZolFtXB8t3kaTiGcZi-UeLGgfc8qz-KmP-VEUipA,12852
677
+ snaptrade_client/oauth.py,sha256=hld39wsLslZwX7OKRpTC98EE6wv7QyxfYesmWdH-2S8,14009
678
678
  snaptrade_client/oauth_device.py,sha256=mgH6ak8zRa0YCLKzd_rKctpS2e71OeC0QHbetQICSWY,10511
679
679
  snaptrade_client/operation_parameter_map.py,sha256=3yq6LEXUrKBoJr3GndRRcv91ARt5EjJ5WN5mxI7byrM,16333
680
680
  snaptrade_client/paths/__init__.py,sha256=yaQWUIwysHW1tT2SwK_Cwg23E_669h0dWNBPmyJNMW0,4674
@@ -1171,7 +1171,7 @@ snaptrade_client/type/user_secret.py,sha256=B6gpY5ECG6fV4aCV7XH9TK9uW9UsZYZlng56
1171
1171
  snaptrade_client/type/validated_trade_body.py,sha256=3d5fH-7GtjtWxBTBDyjK2RSmoFcMQpr7Sv6MXgCfKQc,4076
1172
1172
  snaptrade_client/type_util.py,sha256=y93VO77G7QTwguvfc3HnevIWtLat__tNZXfpSCSxHoU,3749
1173
1173
  snaptrade_client/validation_metadata.py,sha256=VTN5y-NudHXok1X468J4PnGze_tGEAcs1v3gsXmcrb0,3172
1174
- snaptrade_python_sdk-13.3.0.dist-info/LICENSE,sha256=GxvPdqYTCDLPwtMD70oHKcnAL8Os4eOjPVhERWpJ5Cs,1081
1175
- snaptrade_python_sdk-13.3.0.dist-info/METADATA,sha256=8cOkoy0GMwJKV7kLbK5rRq3KPPLr3_HUzDtZOfZNZS4,209191
1176
- snaptrade_python_sdk-13.3.0.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
1177
- snaptrade_python_sdk-13.3.0.dist-info/RECORD,,
1174
+ snaptrade_python_sdk-13.4.0.dist-info/LICENSE,sha256=GxvPdqYTCDLPwtMD70oHKcnAL8Os4eOjPVhERWpJ5Cs,1081
1175
+ snaptrade_python_sdk-13.4.0.dist-info/METADATA,sha256=gPL2RZDI9O7A4JzXvZqgu_6bdImTRe6_g373VvM8YR8,209804
1176
+ snaptrade_python_sdk-13.4.0.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
1177
+ snaptrade_python_sdk-13.4.0.dist-info/RECORD,,