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.

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. 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.0a15.tar.gz (112.7 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.0a15-py3-none-any.whl (137.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polar_sdk-1.0.0a15.tar.gz
  • Upload date:
  • Size: 112.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","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.0a15.tar.gz
Algorithm Hash digest
SHA256 073d84bc42babdeef00249b5f3d36d13fea2a8ac3dd199fe3ec7abaaf282376d
MD5 8747f10104e624fa1577d46bf86af214
BLAKE2b-256 ee597cf3c4099d735c452c848be4884e1f0e04c470a538815e1c2b8d5398a756

See more details on using hashes here.

File details

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

File metadata

  • Download URL: polar_sdk-1.0.0a15-py3-none-any.whl
  • Upload date:
  • Size: 137.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","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.0a15-py3-none-any.whl
Algorithm Hash digest
SHA256 294e8f5537fdb075dc9304014f841f5f3574e598bc166fdc51df0809fbe8a7ff
MD5 8ddcac6f0509ed934ca51c2d4d7aa8e6
BLAKE2b-256 dffb17beea261aa8bf6dcf9a5fa5a77ed61d6e0e5adce8d71a68bd758aacb7d1

See more details on using hashes here.

Release history Release notifications | RSS feed

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page