whop-sdk 0.0.1__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.

Potentially problematic release.


This version of whop-sdk might be problematic. Click here for more details.

Files changed (212) hide show
  1. whop_sdk/__init__.py +94 -0
  2. whop_sdk/_base_client.py +1995 -0
  3. whop_sdk/_client.py +664 -0
  4. whop_sdk/_compat.py +219 -0
  5. whop_sdk/_constants.py +14 -0
  6. whop_sdk/_exceptions.py +112 -0
  7. whop_sdk/_files.py +123 -0
  8. whop_sdk/_models.py +835 -0
  9. whop_sdk/_qs.py +150 -0
  10. whop_sdk/_resource.py +43 -0
  11. whop_sdk/_response.py +830 -0
  12. whop_sdk/_streaming.py +333 -0
  13. whop_sdk/_types.py +260 -0
  14. whop_sdk/_utils/__init__.py +64 -0
  15. whop_sdk/_utils/_compat.py +45 -0
  16. whop_sdk/_utils/_datetime_parse.py +136 -0
  17. whop_sdk/_utils/_logs.py +25 -0
  18. whop_sdk/_utils/_proxy.py +65 -0
  19. whop_sdk/_utils/_reflection.py +42 -0
  20. whop_sdk/_utils/_resources_proxy.py +24 -0
  21. whop_sdk/_utils/_streams.py +12 -0
  22. whop_sdk/_utils/_sync.py +86 -0
  23. whop_sdk/_utils/_transform.py +457 -0
  24. whop_sdk/_utils/_typing.py +156 -0
  25. whop_sdk/_utils/_utils.py +421 -0
  26. whop_sdk/_version.py +4 -0
  27. whop_sdk/lib/.keep +4 -0
  28. whop_sdk/pagination.py +61 -0
  29. whop_sdk/py.typed +0 -0
  30. whop_sdk/resources/__init__.py +316 -0
  31. whop_sdk/resources/app_builds.py +562 -0
  32. whop_sdk/resources/apps.py +665 -0
  33. whop_sdk/resources/authorized_users.py +336 -0
  34. whop_sdk/resources/chat_channels.py +469 -0
  35. whop_sdk/resources/checkout_configurations.py +464 -0
  36. whop_sdk/resources/companies.py +171 -0
  37. whop_sdk/resources/course_lesson_interactions.py +343 -0
  38. whop_sdk/resources/entries.py +539 -0
  39. whop_sdk/resources/experiences.py +859 -0
  40. whop_sdk/resources/forum_posts.py +512 -0
  41. whop_sdk/resources/invoices.py +633 -0
  42. whop_sdk/resources/ledger_accounts.py +171 -0
  43. whop_sdk/resources/memberships.py +810 -0
  44. whop_sdk/resources/messages.py +446 -0
  45. whop_sdk/resources/payments.py +761 -0
  46. whop_sdk/resources/plans.py +906 -0
  47. whop_sdk/resources/products.py +969 -0
  48. whop_sdk/resources/reactions.py +423 -0
  49. whop_sdk/resources/shipments.py +451 -0
  50. whop_sdk/resources/support_channels.py +455 -0
  51. whop_sdk/resources/transfers.py +488 -0
  52. whop_sdk/resources/users.py +248 -0
  53. whop_sdk/resources/webhooks.py +69 -0
  54. whop_sdk/types/__init__.py +135 -0
  55. whop_sdk/types/app_build_create_params.py +59 -0
  56. whop_sdk/types/app_build_list_params.py +34 -0
  57. whop_sdk/types/app_build_list_response.py +50 -0
  58. whop_sdk/types/app_create_params.py +19 -0
  59. whop_sdk/types/app_list_params.py +54 -0
  60. whop_sdk/types/app_list_response.py +91 -0
  61. whop_sdk/types/app_update_params.py +58 -0
  62. whop_sdk/types/authorized_user_list_params.py +33 -0
  63. whop_sdk/types/authorized_user_list_response.py +33 -0
  64. whop_sdk/types/authorized_user_retrieve_response.py +33 -0
  65. whop_sdk/types/chat_channel_list_params.py +28 -0
  66. whop_sdk/types/chat_channel_list_response.py +43 -0
  67. whop_sdk/types/chat_channel_update_params.py +32 -0
  68. whop_sdk/types/checkout_configuration_create_params.py +129 -0
  69. whop_sdk/types/checkout_configuration_list_params.py +33 -0
  70. whop_sdk/types/checkout_configuration_list_response.py +66 -0
  71. whop_sdk/types/course_lesson_interaction_list_params.py +34 -0
  72. whop_sdk/types/entry_approve_response.py +10 -0
  73. whop_sdk/types/entry_list_params.py +44 -0
  74. whop_sdk/types/entry_list_response.py +56 -0
  75. whop_sdk/types/experience_attach_params.py +12 -0
  76. whop_sdk/types/experience_create_params.py +22 -0
  77. whop_sdk/types/experience_delete_response.py +7 -0
  78. whop_sdk/types/experience_detach_params.py +12 -0
  79. whop_sdk/types/experience_list_params.py +31 -0
  80. whop_sdk/types/experience_list_response.py +47 -0
  81. whop_sdk/types/experience_update_params.py +41 -0
  82. whop_sdk/types/forum_post_create_params.py +85 -0
  83. whop_sdk/types/forum_post_list_params.py +31 -0
  84. whop_sdk/types/forum_post_list_response.py +53 -0
  85. whop_sdk/types/invoice_create_params.py +137 -0
  86. whop_sdk/types/invoice_create_response.py +16 -0
  87. whop_sdk/types/invoice_created_webhook_event.py +26 -0
  88. whop_sdk/types/invoice_list_params.py +50 -0
  89. whop_sdk/types/invoice_paid_webhook_event.py +26 -0
  90. whop_sdk/types/invoice_past_due_webhook_event.py +26 -0
  91. whop_sdk/types/invoice_void_response.py +7 -0
  92. whop_sdk/types/invoice_voided_webhook_event.py +26 -0
  93. whop_sdk/types/ledger_account_retrieve_response.py +78 -0
  94. whop_sdk/types/membership_cancel_params.py +13 -0
  95. whop_sdk/types/membership_list_params.py +70 -0
  96. whop_sdk/types/membership_list_response.py +117 -0
  97. whop_sdk/types/membership_pause_params.py +16 -0
  98. whop_sdk/types/membership_update_params.py +13 -0
  99. whop_sdk/types/message_create_params.py +51 -0
  100. whop_sdk/types/message_list_params.py +30 -0
  101. whop_sdk/types/message_list_response.py +90 -0
  102. whop_sdk/types/payment_list_params.py +72 -0
  103. whop_sdk/types/payment_list_response.py +221 -0
  104. whop_sdk/types/payment_refund_params.py +13 -0
  105. whop_sdk/types/plan_create_params.py +106 -0
  106. whop_sdk/types/plan_delete_response.py +7 -0
  107. whop_sdk/types/plan_list_params.py +49 -0
  108. whop_sdk/types/plan_list_response.py +92 -0
  109. whop_sdk/types/plan_update_params.py +95 -0
  110. whop_sdk/types/product_create_params.py +170 -0
  111. whop_sdk/types/product_delete_response.py +7 -0
  112. whop_sdk/types/product_list_params.py +41 -0
  113. whop_sdk/types/product_update_params.py +90 -0
  114. whop_sdk/types/reaction_create_params.py +19 -0
  115. whop_sdk/types/reaction_list_params.py +25 -0
  116. whop_sdk/types/reaction_list_response.py +32 -0
  117. whop_sdk/types/shared/__init__.py +55 -0
  118. whop_sdk/types/shared/access_pass_type.py +7 -0
  119. whop_sdk/types/shared/app.py +159 -0
  120. whop_sdk/types/shared/app_build.py +50 -0
  121. whop_sdk/types/shared/app_build_platforms.py +7 -0
  122. whop_sdk/types/shared/app_build_statuses.py +7 -0
  123. whop_sdk/types/shared/app_statuses.py +7 -0
  124. whop_sdk/types/shared/app_view_type.py +7 -0
  125. whop_sdk/types/shared/authorized_user_roles.py +9 -0
  126. whop_sdk/types/shared/business_types.py +22 -0
  127. whop_sdk/types/shared/chat_channel.py +43 -0
  128. whop_sdk/types/shared/checkout_configuration.py +66 -0
  129. whop_sdk/types/shared/collection_method.py +7 -0
  130. whop_sdk/types/shared/company.py +71 -0
  131. whop_sdk/types/shared/course_lesson_interaction.py +44 -0
  132. whop_sdk/types/shared/course_lesson_interaction_list_item.py +44 -0
  133. whop_sdk/types/shared/currency.py +92 -0
  134. whop_sdk/types/shared/custom_cta.py +21 -0
  135. whop_sdk/types/shared/direction.py +7 -0
  136. whop_sdk/types/shared/dms_post_types.py +7 -0
  137. whop_sdk/types/shared/entry.py +70 -0
  138. whop_sdk/types/shared/entry_status.py +7 -0
  139. whop_sdk/types/shared/experience.py +66 -0
  140. whop_sdk/types/shared/forum_post.py +53 -0
  141. whop_sdk/types/shared/friendly_receipt_status.py +24 -0
  142. whop_sdk/types/shared/global_affiliate_status.py +7 -0
  143. whop_sdk/types/shared/industry_types.py +67 -0
  144. whop_sdk/types/shared/invoice.py +61 -0
  145. whop_sdk/types/shared/invoice_list_item.py +61 -0
  146. whop_sdk/types/shared/invoice_status.py +7 -0
  147. whop_sdk/types/shared/membership.py +117 -0
  148. whop_sdk/types/shared/membership_status.py +9 -0
  149. whop_sdk/types/shared/message.py +90 -0
  150. whop_sdk/types/shared/page_info.py +21 -0
  151. whop_sdk/types/shared/payment.py +211 -0
  152. whop_sdk/types/shared/plan.py +123 -0
  153. whop_sdk/types/shared/plan_type.py +7 -0
  154. whop_sdk/types/shared/product.py +124 -0
  155. whop_sdk/types/shared/product_list_item.py +49 -0
  156. whop_sdk/types/shared/promo_type.py +7 -0
  157. whop_sdk/types/shared/reaction.py +32 -0
  158. whop_sdk/types/shared/receipt_status.py +7 -0
  159. whop_sdk/types/shared/release_method.py +7 -0
  160. whop_sdk/types/shared/shipment.py +48 -0
  161. whop_sdk/types/shared/shipment_carrier.py +84 -0
  162. whop_sdk/types/shared/shipment_status.py +18 -0
  163. whop_sdk/types/shared/shipment_substatus.py +36 -0
  164. whop_sdk/types/shared/support_channel.py +39 -0
  165. whop_sdk/types/shared/tax_type.py +7 -0
  166. whop_sdk/types/shared/transfer.py +109 -0
  167. whop_sdk/types/shared/visibility.py +7 -0
  168. whop_sdk/types/shared/visibility_filter.py +9 -0
  169. whop_sdk/types/shared/who_can_post.py +7 -0
  170. whop_sdk/types/shared/who_can_react.py +7 -0
  171. whop_sdk/types/shared_params/__init__.py +27 -0
  172. whop_sdk/types/shared_params/access_pass_type.py +9 -0
  173. whop_sdk/types/shared_params/app_build_platforms.py +9 -0
  174. whop_sdk/types/shared_params/app_build_statuses.py +9 -0
  175. whop_sdk/types/shared_params/app_statuses.py +9 -0
  176. whop_sdk/types/shared_params/app_view_type.py +9 -0
  177. whop_sdk/types/shared_params/authorized_user_roles.py +11 -0
  178. whop_sdk/types/shared_params/business_types.py +24 -0
  179. whop_sdk/types/shared_params/collection_method.py +9 -0
  180. whop_sdk/types/shared_params/currency.py +94 -0
  181. whop_sdk/types/shared_params/custom_cta.py +23 -0
  182. whop_sdk/types/shared_params/direction.py +9 -0
  183. whop_sdk/types/shared_params/entry_status.py +9 -0
  184. whop_sdk/types/shared_params/friendly_receipt_status.py +26 -0
  185. whop_sdk/types/shared_params/global_affiliate_status.py +9 -0
  186. whop_sdk/types/shared_params/industry_types.py +69 -0
  187. whop_sdk/types/shared_params/invoice_status.py +9 -0
  188. whop_sdk/types/shared_params/membership_status.py +11 -0
  189. whop_sdk/types/shared_params/plan_type.py +9 -0
  190. whop_sdk/types/shared_params/receipt_status.py +9 -0
  191. whop_sdk/types/shared_params/release_method.py +9 -0
  192. whop_sdk/types/shared_params/tax_type.py +9 -0
  193. whop_sdk/types/shared_params/visibility.py +9 -0
  194. whop_sdk/types/shared_params/visibility_filter.py +11 -0
  195. whop_sdk/types/shared_params/who_can_post.py +9 -0
  196. whop_sdk/types/shared_params/who_can_react.py +9 -0
  197. whop_sdk/types/shipment_create_params.py +18 -0
  198. whop_sdk/types/shipment_list_params.py +31 -0
  199. whop_sdk/types/shipment_list_response.py +48 -0
  200. whop_sdk/types/support_channel_create_params.py +15 -0
  201. whop_sdk/types/support_channel_list_params.py +40 -0
  202. whop_sdk/types/support_channel_list_response.py +39 -0
  203. whop_sdk/types/transfer_create_params.py +36 -0
  204. whop_sdk/types/transfer_list_params.py +42 -0
  205. whop_sdk/types/transfer_list_response.py +35 -0
  206. whop_sdk/types/unwrap_webhook_event.py +15 -0
  207. whop_sdk/types/user_check_access_response.py +15 -0
  208. whop_sdk/types/user_retrieve_response.py +25 -0
  209. whop_sdk-0.0.1.dist-info/METADATA +522 -0
  210. whop_sdk-0.0.1.dist-info/RECORD +212 -0
  211. whop_sdk-0.0.1.dist-info/WHEEL +4 -0
  212. whop_sdk-0.0.1.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,522 @@
1
+ Metadata-Version: 2.3
2
+ Name: whop-sdk
3
+ Version: 0.0.1
4
+ Summary: The official Python library for the Whop API
5
+ Project-URL: Homepage, https://github.com/whopio/whopsdk-python
6
+ Project-URL: Repository, https://github.com/whopio/whopsdk-python
7
+ Author: Whop
8
+ License: Apache-2.0
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.8
25
+ Requires-Dist: anyio<5,>=3.5.0
26
+ Requires-Dist: distro<2,>=1.7.0
27
+ Requires-Dist: httpx<1,>=0.23.0
28
+ Requires-Dist: pydantic<3,>=1.9.0
29
+ Requires-Dist: sniffio
30
+ Requires-Dist: typing-extensions<5,>=4.10
31
+ Provides-Extra: aiohttp
32
+ Requires-Dist: aiohttp; extra == 'aiohttp'
33
+ Requires-Dist: httpx-aiohttp>=0.1.8; extra == 'aiohttp'
34
+ Provides-Extra: webhooks
35
+ Requires-Dist: standardwebhooks; extra == 'webhooks'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # Whop Python API library
39
+
40
+ <!-- prettier-ignore -->
41
+ [![PyPI version](https://img.shields.io/pypi/v/whop-sdk.svg?label=pypi%20(stable))](https://pypi.org/project/whop-sdk/)
42
+
43
+ The Whop Python library provides convenient access to the Whop REST API from any Python 3.8+
44
+ application. The library includes type definitions for all request params and response fields,
45
+ and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
46
+
47
+ It is generated with [Stainless](https://www.stainless.com/).
48
+
49
+ ## Documentation
50
+
51
+ The REST API documentation can be found on [docs.whop.com](https://docs.whop.com/apps). The full API of this library can be found in [api.md](https://github.com/whopio/whopsdk-python/tree/main/api.md).
52
+
53
+ ## Installation
54
+
55
+ ```sh
56
+ # install from PyPI
57
+ pip install whop-sdk
58
+ ```
59
+
60
+ ## Usage
61
+
62
+ The full API of this library can be found in [api.md](https://github.com/whopio/whopsdk-python/tree/main/api.md).
63
+
64
+ ```python
65
+ import os
66
+ from whop_sdk import Whop
67
+
68
+ client = Whop(
69
+ app_id="app_xxxxxxxxxxxxxx",
70
+ api_key=os.environ.get("WHOP_API_KEY"), # This is the default and can be omitted
71
+ )
72
+
73
+ page = client.payments.list(
74
+ company_id="biz_xxxxxxxxxxxxxx",
75
+ )
76
+ print(page.data)
77
+ ```
78
+
79
+ While you can provide an `api_key` keyword argument,
80
+ we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
81
+ to add `WHOP_API_KEY="My API Key"` to your `.env` file
82
+ so that your API Key is not stored in source control.
83
+
84
+ ## Async usage
85
+
86
+ Simply import `AsyncWhop` instead of `Whop` and use `await` with each API call:
87
+
88
+ ```python
89
+ import os
90
+ import asyncio
91
+ from whop_sdk import AsyncWhop
92
+
93
+ client = AsyncWhop(
94
+ app_id="app_xxxxxxxxxxxxxx",
95
+ api_key=os.environ.get("WHOP_API_KEY"), # This is the default and can be omitted
96
+ )
97
+
98
+
99
+ async def main() -> None:
100
+ page = await client.payments.list(
101
+ company_id="biz_xxxxxxxxxxxxxx",
102
+ )
103
+ print(page.data)
104
+
105
+
106
+ asyncio.run(main())
107
+ ```
108
+
109
+ Functionality between the synchronous and asynchronous clients is otherwise identical.
110
+
111
+ ### With aiohttp
112
+
113
+ By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.
114
+
115
+ You can enable this by installing `aiohttp`:
116
+
117
+ ```sh
118
+ # install from PyPI
119
+ pip install whop-sdk[aiohttp]
120
+ ```
121
+
122
+ Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
123
+
124
+ ```python
125
+ import asyncio
126
+ from whop_sdk import DefaultAioHttpClient
127
+ from whop_sdk import AsyncWhop
128
+
129
+
130
+ async def main() -> None:
131
+ async with AsyncWhop(
132
+ app_id="app_xxxxxxxxxxxxxx",
133
+ api_key="My API Key",
134
+ http_client=DefaultAioHttpClient(),
135
+ ) as client:
136
+ page = await client.payments.list(
137
+ company_id="biz_xxxxxxxxxxxxxx",
138
+ )
139
+ print(page.data)
140
+
141
+
142
+ asyncio.run(main())
143
+ ```
144
+
145
+ ## Using types
146
+
147
+ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
148
+
149
+ - Serializing back into JSON, `model.to_json()`
150
+ - Converting to a dictionary, `model.to_dict()`
151
+
152
+ Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
153
+
154
+ ## Pagination
155
+
156
+ List methods in the Whop API are paginated.
157
+
158
+ This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
159
+
160
+ ```python
161
+ from whop_sdk import Whop
162
+
163
+ client = Whop(
164
+ app_id="app_xxxxxxxxxxxxxx",
165
+ )
166
+
167
+ all_payments = []
168
+ # Automatically fetches more pages as needed.
169
+ for payment in client.payments.list(
170
+ company_id="biz_xxxxxxxxxxxxxx",
171
+ ):
172
+ # Do something with payment here
173
+ all_payments.append(payment)
174
+ print(all_payments)
175
+ ```
176
+
177
+ Or, asynchronously:
178
+
179
+ ```python
180
+ import asyncio
181
+ from whop_sdk import AsyncWhop
182
+
183
+ client = AsyncWhop(
184
+ app_id="app_xxxxxxxxxxxxxx",
185
+ )
186
+
187
+
188
+ async def main() -> None:
189
+ all_payments = []
190
+ # Iterate through items across all pages, issuing requests as needed.
191
+ async for payment in client.payments.list(
192
+ company_id="biz_xxxxxxxxxxxxxx",
193
+ ):
194
+ all_payments.append(payment)
195
+ print(all_payments)
196
+
197
+
198
+ asyncio.run(main())
199
+ ```
200
+
201
+ Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
202
+
203
+ ```python
204
+ first_page = await client.payments.list(
205
+ company_id="biz_xxxxxxxxxxxxxx",
206
+ )
207
+ if first_page.has_next_page():
208
+ print(f"will fetch next page using these details: {first_page.next_page_info()}")
209
+ next_page = await first_page.get_next_page()
210
+ print(f"number of items we just fetched: {len(next_page.data)}")
211
+
212
+ # Remove `await` for non-async usage.
213
+ ```
214
+
215
+ Or just work directly with the returned data:
216
+
217
+ ```python
218
+ first_page = await client.payments.list(
219
+ company_id="biz_xxxxxxxxxxxxxx",
220
+ )
221
+
222
+ print(f"next page cursor: {first_page.page_info.end_cursor}") # => "next page cursor: ..."
223
+ for payment in first_page.data:
224
+ print(payment.id)
225
+
226
+ # Remove `await` for non-async usage.
227
+ ```
228
+
229
+ ## Nested params
230
+
231
+ Nested parameters are dictionaries, typed using `TypedDict`, for example:
232
+
233
+ ```python
234
+ from whop_sdk import Whop
235
+
236
+ client = Whop(
237
+ app_id="app_xxxxxxxxxxxxxx",
238
+ )
239
+
240
+ app = client.apps.update(
241
+ id="app_xxxxxxxxxxxxxx",
242
+ icon={},
243
+ )
244
+ print(app.icon)
245
+ ```
246
+
247
+ ## Handling errors
248
+
249
+ When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `whop_sdk.APIConnectionError` is raised.
250
+
251
+ When the API returns a non-success status code (that is, 4xx or 5xx
252
+ response), a subclass of `whop_sdk.APIStatusError` is raised, containing `status_code` and `response` properties.
253
+
254
+ All errors inherit from `whop_sdk.APIError`.
255
+
256
+ ```python
257
+ import whop_sdk
258
+ from whop_sdk import Whop
259
+
260
+ client = Whop(
261
+ app_id="app_xxxxxxxxxxxxxx",
262
+ )
263
+
264
+ try:
265
+ client.payments.list(
266
+ company_id="biz_xxxxxxxxxxxxxx",
267
+ )
268
+ except whop_sdk.APIConnectionError as e:
269
+ print("The server could not be reached")
270
+ print(e.__cause__) # an underlying Exception, likely raised within httpx.
271
+ except whop_sdk.RateLimitError as e:
272
+ print("A 429 status code was received; we should back off a bit.")
273
+ except whop_sdk.APIStatusError as e:
274
+ print("Another non-200-range status code was received")
275
+ print(e.status_code)
276
+ print(e.response)
277
+ ```
278
+
279
+ Error codes are as follows:
280
+
281
+ | Status Code | Error Type |
282
+ | ----------- | -------------------------- |
283
+ | 400 | `BadRequestError` |
284
+ | 401 | `AuthenticationError` |
285
+ | 403 | `PermissionDeniedError` |
286
+ | 404 | `NotFoundError` |
287
+ | 422 | `UnprocessableEntityError` |
288
+ | 429 | `RateLimitError` |
289
+ | >=500 | `InternalServerError` |
290
+ | N/A | `APIConnectionError` |
291
+
292
+ ### Retries
293
+
294
+ Certain errors are automatically retried 2 times by default, with a short exponential backoff.
295
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
296
+ 429 Rate Limit, and >=500 Internal errors are all retried by default.
297
+
298
+ You can use the `max_retries` option to configure or disable retry settings:
299
+
300
+ ```python
301
+ from whop_sdk import Whop
302
+
303
+ # Configure the default for all requests:
304
+ client = Whop(
305
+ app_id="app_xxxxxxxxxxxxxx",
306
+ # default is 2
307
+ max_retries=0,
308
+ )
309
+
310
+ # Or, configure per-request:
311
+ client.with_options(max_retries=5).payments.list(
312
+ company_id="biz_xxxxxxxxxxxxxx",
313
+ )
314
+ ```
315
+
316
+ ### Timeouts
317
+
318
+ By default requests time out after 1 minute. You can configure this with a `timeout` option,
319
+ which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
320
+
321
+ ```python
322
+ from whop_sdk import Whop
323
+
324
+ # Configure the default for all requests:
325
+ client = Whop(
326
+ app_id="app_xxxxxxxxxxxxxx",
327
+ # 20 seconds (default is 1 minute)
328
+ timeout=20.0,
329
+ )
330
+
331
+ # More granular control:
332
+ client = Whop(
333
+ app_id="app_xxxxxxxxxxxxxx",
334
+ timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
335
+ )
336
+
337
+ # Override per-request:
338
+ client.with_options(timeout=5.0).payments.list(
339
+ company_id="biz_xxxxxxxxxxxxxx",
340
+ )
341
+ ```
342
+
343
+ On timeout, an `APITimeoutError` is thrown.
344
+
345
+ Note that requests that time out are [retried twice by default](https://github.com/whopio/whopsdk-python/tree/main/#retries).
346
+
347
+ ## Advanced
348
+
349
+ ### Logging
350
+
351
+ We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
352
+
353
+ You can enable logging by setting the environment variable `WHOP_LOG` to `info`.
354
+
355
+ ```shell
356
+ $ export WHOP_LOG=info
357
+ ```
358
+
359
+ Or to `debug` for more verbose logging.
360
+
361
+ ### How to tell whether `None` means `null` or missing
362
+
363
+ In an API response, a field may be explicitly `null`, or missing entirely; in either case, its value is `None` in this library. You can differentiate the two cases with `.model_fields_set`:
364
+
365
+ ```py
366
+ if response.my_field is None:
367
+ if 'my_field' not in response.model_fields_set:
368
+ print('Got json like {}, without a "my_field" key present at all.')
369
+ else:
370
+ print('Got json like {"my_field": null}.')
371
+ ```
372
+
373
+ ### Accessing raw response data (e.g. headers)
374
+
375
+ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
376
+
377
+ ```py
378
+ from whop_sdk import Whop
379
+
380
+ client = Whop(
381
+ app_id="app_xxxxxxxxxxxxxx",
382
+ )
383
+ response = client.payments.with_raw_response.list(
384
+ company_id="biz_xxxxxxxxxxxxxx",
385
+ )
386
+ print(response.headers.get('X-My-Header'))
387
+
388
+ payment = response.parse() # get the object that `payments.list()` would have returned
389
+ print(payment.id)
390
+ ```
391
+
392
+ These methods return an [`APIResponse`](https://github.com/whopio/whopsdk-python/tree/main/src/whop_sdk/_response.py) object.
393
+
394
+ The async client returns an [`AsyncAPIResponse`](https://github.com/whopio/whopsdk-python/tree/main/src/whop_sdk/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
395
+
396
+ #### `.with_streaming_response`
397
+
398
+ The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
399
+
400
+ To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
401
+
402
+ ```python
403
+ with client.payments.with_streaming_response.list(
404
+ company_id="biz_xxxxxxxxxxxxxx",
405
+ ) as response:
406
+ print(response.headers.get("X-My-Header"))
407
+
408
+ for line in response.iter_lines():
409
+ print(line)
410
+ ```
411
+
412
+ The context manager is required so that the response will reliably be closed.
413
+
414
+ ### Making custom/undocumented requests
415
+
416
+ This library is typed for convenient access to the documented API.
417
+
418
+ If you need to access undocumented endpoints, params, or response properties, the library can still be used.
419
+
420
+ #### Undocumented endpoints
421
+
422
+ To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
423
+ http verbs. Options on the client will be respected (such as retries) when making this request.
424
+
425
+ ```py
426
+ import httpx
427
+
428
+ response = client.post(
429
+ "/foo",
430
+ cast_to=httpx.Response,
431
+ body={"my_param": True},
432
+ )
433
+
434
+ print(response.headers.get("x-foo"))
435
+ ```
436
+
437
+ #### Undocumented request params
438
+
439
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
440
+ options.
441
+
442
+ #### Undocumented response properties
443
+
444
+ To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
445
+ can also get all the extra fields on the Pydantic model as a dict with
446
+ [`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
447
+
448
+ ### Configuring the HTTP client
449
+
450
+ You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
451
+
452
+ - Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
453
+ - Custom [transports](https://www.python-httpx.org/advanced/transports/)
454
+ - Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
455
+
456
+ ```python
457
+ import httpx
458
+ from whop_sdk import Whop, DefaultHttpxClient
459
+
460
+ client = Whop(
461
+ app_id="app_xxxxxxxxxxxxxx",
462
+ # Or use the `WHOP_BASE_URL` env var
463
+ base_url="http://my.test.server.example.com:8083",
464
+ http_client=DefaultHttpxClient(
465
+ proxy="http://my.test.proxy.example.com",
466
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
467
+ ),
468
+ )
469
+ ```
470
+
471
+ You can also customize the client on a per-request basis by using `with_options()`:
472
+
473
+ ```python
474
+ client.with_options(http_client=DefaultHttpxClient(...))
475
+ ```
476
+
477
+ ### Managing HTTP resources
478
+
479
+ By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
480
+
481
+ ```py
482
+ from whop_sdk import Whop
483
+
484
+ with Whop(
485
+ app_id="app_xxxxxxxxxxxxxx",
486
+ ) as client:
487
+ # make requests here
488
+ ...
489
+
490
+ # HTTP client is now closed
491
+ ```
492
+
493
+ ## Versioning
494
+
495
+ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
496
+
497
+ 1. Changes that only affect static types, without breaking runtime behavior.
498
+ 2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
499
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
500
+
501
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
502
+
503
+ We are keen for your feedback; please open an [issue](https://www.github.com/whopio/whopsdk-python/issues) with questions, bugs, or suggestions.
504
+
505
+ ### Determining the installed version
506
+
507
+ If you've upgraded to the latest version but aren't seeing any new features you were expecting then your python environment is likely still using an older version.
508
+
509
+ You can determine the version that is being used at runtime with:
510
+
511
+ ```py
512
+ import whop_sdk
513
+ print(whop_sdk.__version__)
514
+ ```
515
+
516
+ ## Requirements
517
+
518
+ Python 3.8 or higher.
519
+
520
+ ## Contributing
521
+
522
+ See [the contributing documentation](https://github.com/whopio/whopsdk-python/tree/main/./CONTRIBUTING.md).