Metadata-Version: 2.4
Name: whop_sdk
Version: 1.0.12
Summary: 
License: Apache-2.0
License-File: LICENSE
Requires-Python: >=3.10,<4.0
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: OS Independent
Classifier: Operating System :: POSIX
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Provides-Extra: aiohttp
Requires-Dist: aiohttp (>=3.14.1,<4) ; (python_version >= "3.10") and (extra == "aiohttp")
Requires-Dist: httpx (>=0.21.2)
Requires-Dist: httpx-aiohttp (>=0.1.8,<0.2.0) ; (python_version >= "3.10") and (extra == "aiohttp")
Requires-Dist: pydantic (>=1.9.2)
Requires-Dist: pydantic-core (>=2.18.2,<3.0.0)
Requires-Dist: typing_extensions (>=4.0.0)
Project-URL: Repository, https://github.com/whopio/whopsdk-python
Description-Content-Type: text/markdown

# Whop Python Library

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=Whop%2FPython)
[![pypi](https://img.shields.io/pypi/v/whop_sdk)](https://pypi.python.org/pypi/whop_sdk)

The Whop SDK gives you typed access to the Whop API. Pass your API key to the client explicitly — the SDK reads no environment variables, so a client built without a key sends unauthenticated requests and the API answers 401.

## Table of Contents

- [Documentation](#documentation)
- [Installation](#installation)
- [Reference](#reference)
- [Usage](#usage)
- [Migrating from 0.0.41 and earlier](#migrating-from-0041-and-earlier)
  - [There is no environment-variable fallback](#there-is-no-environment-variable-fallback)
- [A first request](#a-first-request)
- [Environments](#environments)
- [Async Client](#async-client)
- [Using aiohttp](#using-aiohttp)
- [Exception Handling](#exception-handling)
- [Pagination](#pagination)
  - [What a pager exposes](#what-a-pager-exposes)
- [Verifying user tokens](#verifying-user-tokens)
- [Advanced](#advanced)
  - [Access Raw Response Data](#access-raw-response-data)
  - [Retries](#retries)
  - [Timeouts](#timeouts)
  - [Custom Client](#custom-client)
- [Requirements](#requirements)
- [Determining the installed version](#determining-the-installed-version)
- [Contributing](#contributing)

## Documentation

API reference documentation is available [here](https://docs.whop.com/api-reference).

## Installation

```sh
pip install whop_sdk
```

## Reference

A full reference for this library is available [here](https://github.com/whopio/whopsdk-python/blob/HEAD/./reference.md).

## Usage

Instantiate and use the client with the following:

```python
from whop_sdk import Whop

client = Whop(
    token="<token>",
)

client.access_tokens.create()
```

## Migrating from 0.0.41 and earlier

Releases up to and including `0.0.41` were generated by Stainless. `1.0.0` onwards is
generated by Fern, and the constructor is not source-compatible with what came before —
which is why the line left `0.0.x`.

| Was | Now |
| --- | --- |
| `Whop(api_key=...)` | `Whop(token=...)` — accepts a `str` or a `Callable[[], str]` |
| `Whop(version=...)` | `Whop(api_version_date=...)`, default `"2026-08-21"` |
| `Whop(default_headers={...})` | `Whop(headers={...})` |
| `Whop(http_client=...)` | `Whop(httpx_client=...)` |
| `Whop(webhook_key=...)`, `Whop(app_id=...)` | removed — no constructor equivalent |
| `WHOP_API_KEY` and friends in the environment | removed — see below |
| `client.with_options(max_retries=5).x.y()` | `client.x.y(..., request_options={"max_retries": 5})` |
| `whop_sdk.APIStatusError`, `RateLimitError`, ... | `whop_sdk.core.api_error.ApiError` and the typed subclasses at the package root |
| `model.to_json()` / `model.to_dict()` | Pydantic's `model.model_dump_json()` / `model.model_dump()` |
| `client.webhooks.unwrap(...)` | removed |
| `api.md` | [`reference.md`](https://github.com/whopio/whopsdk-python/blob/HEAD/./reference.md) |

### There is no environment-variable fallback

The client reads no environment variables. Setting `WHOP_API_KEY` has no effect, and
`Whop()` with no `token` builds successfully and then sends unauthenticated requests,
so the first sign of the mistake is a `401` from the API rather than an error at
construction time.

```python
from whop_sdk import Whop

client = Whop(
    token="<token>",
    # Optional; both have working defaults.
    base_url="https://api.whop.com/api/v1",
    api_version_date="2026-08-21",
)
```

Every parameter is keyword-only.

## A first request

`products.list` is paginated and requires the account to list products for.

```python
from whop_sdk import Whop

client = Whop(token="<token>")

for product in client.products.list(account_id="biz_xxxxxxxxxxxxxx"):
    print(product.id, product.title)
```

## Environments

This SDK allows you to configure different environments for API requests.

```python
from whop_sdk import Whop
from whop_sdk.environment import WhopEnvironment

client = Whop(
    environment=WhopEnvironment.DEFAULT,
)
```

## Async Client

The SDK also exports an `async` client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, use `httpx.AsyncClient()` instead of `httpx.Client()` (e.g. for the `httpx_client` parameter of this client).

```python
import asyncio

from whop_sdk import AsyncWhop

client = AsyncWhop(
    token="<token>",
)


async def main() -> None:
    await client.access_tokens.create()


asyncio.run(main())
```

## Using aiohttp

`AsyncWhop` uses `httpx` by default. To run it on `aiohttp` instead, install the
`aiohttp` extra and pass `DefaultAioHttpClient` as the `httpx_client`:

```sh
pip install 'whop-sdk[aiohttp]'
```

```python
import asyncio

from whop_sdk import AsyncWhop, DefaultAioHttpClient


async def main() -> None:
    client = AsyncWhop(
        token="<token>",
        httpx_client=DefaultAioHttpClient(),
    )
    pager = await client.products.list(account_id="biz_xxxxxxxxxxxxxx")
    async for product in pager:
        print(product.id, product.title)


asyncio.run(main())
```

`DefaultAioHttpClient` is importable without the extra, but raises `RuntimeError` when
constructed.

Neither `Whop` nor `AsyncWhop` is a context manager and neither exposes a `close()`, so
there is no `with` / `async with` form. To shut the transport down cleanly — otherwise
`aiohttp` warns about an unclosed session at exit — keep a reference to the client you
passed in and close that:

```python
http_client = DefaultAioHttpClient()
client = AsyncWhop(token="<token>", httpx_client=http_client)
...
await http_client.aclose()
```

## Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
will be thrown.

```python
from whop_sdk.core.api_error import ApiError

try:
    client.access_tokens.create(...)
except ApiError as e:
    print(e.status_code)
    print(e.body)
```

## Pagination

Paginated requests will return a `SyncPager` or `AsyncPager`, which can be used as generators for the underlying object.

```python
from whop_sdk import Whop

client = Whop(
    token="<token>",
)

client.accounts.list()
```

```python
# You can also iterate through pages and access the typed response per page
pager = client.accounts.list(...)
for page in pager.iter_pages():
    print(page.response)  # access the typed response for each page
    for item in page:
        print(item)
```

### What a pager exposes

The pager is not the response body. It carries `items` (this page only), `has_next`,
`next_page()`, and `iter_pages()`, and iterating the pager itself walks every page. The
decoded response — `data` and `page_info` — is on `pager.response`:

```python
from whop_sdk import Whop

client = Whop(token="<token>")
pager = client.products.list(account_id="biz_xxxxxxxxxxxxxx")

print(pager.response.page_info.has_next_page)
print(pager.response.data)  # this page's items, as returned by the API
print(pager.items)          # the same items, off the pager
```

`SyncPager` and `AsyncPager` live in `whop_sdk.core.pagination`; they are not exported
from the package root.

## Verifying user tokens

`verify_user_token` checks the `x-whop-user-token` JWT that Whop sends to an embedded
app. It is hand-written rather than generated, and it is the only part of this package
that needs a dependency the package does not declare — install `pyjwt` yourself:

```sh
pip install pyjwt
```

```python
from whop_sdk.lib.verify_user_token import verify_user_token

payload = verify_user_token(request.headers, app_id="app_xxxxxxxxxxxxxx")
print(payload.user_id)
```

It accepts either the raw token or a headers mapping, and takes optional `public_key`,
`jwks_url`, and `header_name` overrides. By default it fetches Whop's public signing
keys from `https://api.whop.com/.well-known/jwks.json` and caches them in-process.

> The module docstring suggests `pip install 'whop-sdk[user-tokens]'`. That extra does
> not exist on the published distribution; `aiohttp` is the only one.

## Advanced

### Access Raw Response Data

The SDK provides access to raw response data, including headers, through the `.with_raw_response` property.
The `.with_raw_response` property returns a "raw" client that can be used to access the `.headers` and `.data` attributes.

```python
from whop_sdk import Whop

client = Whop(...)
response = client.access_tokens.with_raw_response.create(...)
print(response.headers)  # access the response headers
print(response.status_code)  # access the response status code
print(response.data)  # access the underlying object
```

### Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
retry limit (default: 2).

Which status codes are retried depends on the `retryStatusCodes` generator configuration:

**`legacy`** (current default): retries on
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
- [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (All server errors, including 500)

**`recommended`**: retries on
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
- [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
- [502](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502) (Bad Gateway)
- [503](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) (Service Unavailable)
- [504](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504) (Gateway Timeout)

Use the `max_retries` request option to configure this behavior.

```python
client.access_tokens.create(..., request_options={
    "max_retries": 1
})
```

### Timeouts

The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.

```python
from whop_sdk import Whop

client = Whop(..., timeout=20.0)

# Override timeout for a specific method
client.access_tokens.create(..., request_options={
    "timeout": 1
})
```

### Custom Client

You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
and transports.

```python
import httpx
from whop_sdk import Whop

client = Whop(
    ...,
    httpx_client=httpx.Client(
        proxy="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)
```

## Requirements

Python 3.10 or higher.

## Determining the installed version

```python
import whop_sdk

print(whop_sdk.__version__)
```

## Contributing

While we value open-source contributions to this SDK, this library is generated programmatically.
Additions made directly to this library would have to be moved over to our generation code,
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

