Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Polar Python SDK

The official Python client for the Polar API.

Installation

The SDK requires Python 3.11 or later.

The SDK is currently available as a pre-release. To install it with uv:

uv add polar-sdk --prerelease allow

or, with pip:

pip install --pre polar-sdk

Quick Start

Create an organization access token and use the client for the current API version:

from polar.v2026_04 import Polar

polar = Polar("polar_oat_xxx")

customer_state = polar.customers.get_state_external("customer_external_id")
print(customer_state)

Async Client

Use PolarAsync in asynchronous applications:

import asyncio

from polar.v2026_04 import PolarAsync


async def main() -> None:
    polar = PolarAsync("polar_oat_xxx")
    customer_state = await polar.customers.get_state_external("customer_external_id")
    print(customer_state)


asyncio.run(main())

Context Managers

Both clients support context managers to close their HTTP connections automatically when the block exits.

For synchronous applications, use Polar with with:

from polar.v2026_04 import Polar

with Polar("polar_oat_xxx") as polar:
    customer_state = polar.customers.get_state_external("customer_external_id")
    print(customer_state)

For asynchronous applications, use PolarAsync with async with:

import asyncio

from polar.v2026_04 import PolarAsync


async def main() -> None:
    async with PolarAsync("polar_oat_xxx") as polar:
        customer_state = await polar.customers.get_state_external(
            "customer_external_id"
        )
        print(customer_state)


asyncio.run(main())

The client uses the production environment by default. To use the sandbox, pass environment="sandbox" when creating the client. Sandbox and production access tokens are separate.

Keep organization access tokens on the server and never expose them in browser or client-side code.

Request Timeouts

Set the default timeout for all requests when creating the client. Timeout values are expressed in seconds:

polar = Polar("polar_oat_xxx", timeout=30)

Override the timeout for an individual request with request_timeout:

customer_state = polar.customers.get_state_external(
    "customer_external_id",
    request_timeout=60,
)

Pass an httpx.Timeout instance to configure connect, read, write, and pool timeouts separately.

Deserializing Data

Use deserialize to convert arbitrary data into a generated SDK model or union type:

from polar import deserialize
from polar.v2026_04.outputs import Customer

customer = deserialize(data, Customer)

Webhooks

Use validate_event to verify that a webhook was sent by Polar and parse it into a typed payload for the selected API version. Pass the raw request body, the request headers, and your webhook signing secret:

import os

from fastapi import FastAPI, HTTPException, Request

from polar.v2026_04.webhooks import (
    PolarWebhookError,
    PolarWebhookVerificationError,
    validate_event,
)

app = FastAPI()
webhook_secret = os.environ["POLAR_WEBHOOK_SECRET"]


@app.post("/webhooks/polar")
async def polar_webhook(request: Request) -> dict[str, bool]:
    try:
        event = validate_event(
            await request.body(),
            dict(request.headers),
            webhook_secret,
        )
    except PolarWebhookVerificationError as exc:
        raise HTTPException(
            status_code=403, detail="Invalid webhook signature"
        ) from exc
    except PolarWebhookError as exc:
        raise HTTPException(status_code=400, detail="Invalid webhook payload") from exc

    if event.type == "order.created":
        print(event.data.id)

    return {"received": True}

The signature is checked before the body is parsed. Verification accepts Polar's original HMAC key (UTF-8 bytes of the full secret, including whsec_) and the Standard Webhooks key (base64-decode of the remainder after whsec_). validate_event raises PolarWebhookVerificationError for invalid signatures and PolarWebhookUnknownTypeError when the event is not supported by the selected API version. Both inherit from PolarWebhookError.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polar_sdk-1.0.0a19.tar.gz (214.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polar_sdk-1.0.0a19-py3-none-any.whl (299.0 kB view details)

Uploaded Python 3

File details

Details for the file polar_sdk-1.0.0a19.tar.gz.

File metadata

  • Download URL: polar_sdk-1.0.0a19.tar.gz
  • Upload date:
  • Size: 214.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for polar_sdk-1.0.0a19.tar.gz
Algorithm Hash digest
SHA256 22f48dfb76a22161183a9dc9b94ac5b5f4ae8b2ee4b13af83f380986b8e76417
MD5 c0e9a257d9685d34d76aa47911ffd7a4
BLAKE2b-256 92f51287b3c5fe1e3dc5bebe58eaaae73c70dcf33ba05406387dad2960adb7b9

See more details on using hashes here.

File details

Details for the file polar_sdk-1.0.0a19-py3-none-any.whl.

File metadata

  • Download URL: polar_sdk-1.0.0a19-py3-none-any.whl
  • Upload date:
  • Size: 299.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for polar_sdk-1.0.0a19-py3-none-any.whl
Algorithm Hash digest
SHA256 5aa8a80e935f0aa51f595dbc4a90c157bced065c53758a43e6162c128d64e4f5
MD5 8ea5a51dd9ab857011a7fb60ac621a4a
BLAKE2b-256 bce1aff594a19172d195bb5a5768f827b88ef0acad93b55b345056709b6944aa

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0a19 This release

2 files

0.32.0

2 files

0.31.7

2 files

0.31.6

2 files

0.31.5

2 files

0.31.4

2 files

0.31.3

2 files

0.31.2

2 files

0.31.1

2 files

0.31.0

2 files

0.30.2

2 files

0.30.1

2 files

0.30.0

2 files

0.29.0

2 files

0.28.4

2 files

0.28.3

2 files

0.28.2

2 files

0.28.1

2 files

0.28.0

2 files

0.27.3

2 files

0.27.2

2 files

0.27.1

2 files

0.27.0

2 files

0.26.0

2 files

0.25.0

2 files

0.24.1

2 files

0.24.0

2 files

0.23.1

2 files

0.23.0

2 files

0.22.8

2 files

0.22.7

2 files

0.22.6

2 files

0.22.5

2 files

0.22.4

2 files

0.22.3

2 files

0.22.2

2 files

0.22.1

2 files

0.22.0

2 files

0.21.0

2 files

0.20.1

2 files

0.20.0

2 files

0.19.2

2 files

0.19.1

2 files

0.19.0

2 files

0.18.1

2 files

0.18.0

2 files

0.17.4

2 files

0.17.3

2 files

0.17.2

2 files

0.17.1

2 files

0.17.0

2 files

0.16.13

2 files

0.16.11

2 files

0.16.10

2 files

0.16.9

2 files

0.16.8

2 files

0.16.7

2 files

0.16.6

2 files

0.16.5

2 files

0.16.4

2 files

0.16.3

2 files

0.16.2

2 files

0.16.1

2 files

0.16.0

2 files

0.15.1

2 files

0.15.0

2 files

0.14.0

2 files

0.13.5

2 files

0.13.4

2 files

0.13.3

2 files

0.13.2

2 files

0.13.1

2 files

0.13.0

2 files

0.12.3

2 files

0.12.2

2 files

0.12.1

2 files

0.12.0

2 files

0.11.1

2 files

0.11.0

2 files

0.10.0

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.5

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.15

2 files

0.1.14

2 files

0.1.13

2 files

0.1.6

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page