SDK Installation
Note
Python version upgrade policy
Once a Python version reaches its official end of life date, a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
The SDK can be installed with either pip or poetry package managers.
PIP
PIP is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
Poetry
Poetry is a modern tool that simplifies dependency management and package publishing by using a single pyproject.toml file to handle project metadata and dependencies.
Shell and script usage with uv
You can use this SDK in a Python shell with uv and the uvx command that comes with it like so:
uvx --from polar-sdk python
It's also possible to write a standalone Python script without needing to set up a whole project like so:
#!/usr/bin/env -S uv run --script # /// script # requires-python = ">=3.9" # dependencies = [ # "polar-sdk", # ] # /// from polar_sdk import Polar sdk = Polar( # SDK arguments ) # Rest of script here...
Once that is saved to a file, you can run it with uv run script.py where
script.py can be replaced with the actual file name.
IDE Support
PyCharm
Generally, the SDK will work well with most IDEs out of the box. However, when using PyCharm, you can enjoy much better integration with Pydantic by installing an additional plugin.
SDK Example Usage
Example
# Synchronous Example import dateutil.parser import polar_sdk from polar_sdk import Polar with Polar() as polar: res = polar.endpointcheckout_created_post(request=polar_sdk.WebhookCheckoutCreatedPayload( data=polar_sdk.Checkout( created_at=dateutil.parser.isoparse("2025-11-12T14:26:42.882Z"), modified_at=dateutil.parser.isoparse("2024-05-27T05:08:06.235Z"), id="<value>", payment_processor=polar_sdk.PaymentProcessor.STRIPE, status=polar_sdk.CheckoutStatus.FAILED, client_secret="<value>", url="https://heavy-beret.com/", expires_at=dateutil.parser.isoparse("2023-02-25T02:26:48.460Z"), success_url="https://sardonic-final.info/", embed_origin="<value>", amount=962818, tax_amount=6400, currency="Yen", subtotal_amount=648726, total_amount=210702, product_id="<value>", product_price_id="<value>", discount_id="<value>", allow_discount_codes=True, is_discount_applicable=False, is_free_product_price=False, is_payment_required=False, is_payment_setup_required=False, is_payment_form_required=False, customer_id="<value>", customer_name="<value>", customer_email="<value>", customer_ip_address="<value>", customer_billing_address={ "country": "Solomon Islands", }, customer_tax_id="<id>", payment_processor_metadata={ "key": "<value>", "key1": "<value>", "key2": "<value>", }, metadata={ "key": "<value>", }, products=[ { "created_at": dateutil.parser.isoparse("2024-05-27T05:08:06.235Z"), "modified_at": dateutil.parser.isoparse("2025-11-19T15:59:15.588Z"), "id": "<value>", "name": "<value>", "description": "brr institute tired rotten relative", "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "is_recurring": False, "is_archived": False, "organization_id": "<value>", "prices": [ ], "benefits": [ { "created_at": dateutil.parser.isoparse("2023-04-26T22:34:57.487Z"), "modified_at": dateutil.parser.isoparse("2023-08-07T19:57:51.694Z"), "id": "<value>", "type": polar_sdk.BenefitType.DISCORD, "description": "when waterlogged godparent pure solidly content sonar progress pacemaker", "selectable": True, "deletable": False, "organization_id": "<value>", }, { "created_at": dateutil.parser.isoparse("2024-10-18T15:45:53.088Z"), "modified_at": dateutil.parser.isoparse("2023-08-08T05:58:49.836Z"), "id": "<value>", "type": polar_sdk.BenefitType.LICENSE_KEYS, "description": "language traduce shrill minor hourly which yearly deeply but", "selectable": False, "deletable": False, "organization_id": "<value>", }, ], "medias": [ { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/Applications", "mime_type": "<value>", "size": 271748, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2023-03-11T18:00:05.573Z"), "version": "<value>", "is_uploaded": False, "created_at": dateutil.parser.isoparse("2025-09-09T13:21:53.200Z"), "size_readable": "<value>", "public_url": "https://male-season.net/", "service": "product_media", }, { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/bin", "mime_type": "<value>", "size": 187532, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2023-12-07T16:19:25.811Z"), "version": "<value>", "is_uploaded": False, "created_at": dateutil.parser.isoparse("2023-12-31T15:42:50.685Z"), "size_readable": "<value>", "public_url": "https://squeaky-editor.name", "service": "product_media", }, { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/usr/bin", "mime_type": "<value>", "size": 910846, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2025-02-19T14:34:23.071Z"), "version": "<value>", "is_uploaded": True, "created_at": dateutil.parser.isoparse("2024-07-14T23:53:19.831Z"), "size_readable": "<value>", "public_url": "https://sad-pupil.info/", "service": "product_media", }, ], }, { "created_at": dateutil.parser.isoparse("2025-09-29T06:23:47.676Z"), "modified_at": dateutil.parser.isoparse("2024-07-02T05:50:09.114Z"), "id": "<value>", "name": "<value>", "description": "as weekly drat nor why sparkling", "recurring_interval": polar_sdk.SubscriptionRecurringInterval.MONTH, "is_recurring": False, "is_archived": False, "organization_id": "<value>", "prices": [ { "created_at": dateutil.parser.isoparse("2025-11-19T15:59:15.588Z"), "modified_at": dateutil.parser.isoparse("2023-11-17T00:11:23.972Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "type": polar_sdk.ProductPriceType.ONE_TIME, "recurring_interval": polar_sdk.SubscriptionRecurringInterval.MONTH, "price_currency": "<value>", "minimum_amount": 82334, "maximum_amount": 50275, "preset_amount": 473871, "amount_type": "custom", }, { "created_at": dateutil.parser.isoparse("2024-04-03T00:20:23.805Z"), "modified_at": dateutil.parser.isoparse("2025-11-21T05:56:48.487Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "type": polar_sdk.ProductPriceType.ONE_TIME, "recurring_interval": polar_sdk.SubscriptionRecurringInterval.MONTH, "price_currency": "<value>", "price_amount": 648726, "amount_type": "fixed", }, ], "benefits": [ { "created_at": dateutil.parser.isoparse("2025-10-16T20:09:46.139Z"), "modified_at": dateutil.parser.isoparse("2023-09-29T18:20:07.088Z"), "id": "<value>", "type": polar_sdk.BenefitType.ADS, "description": "pupil divine roundabout gah oh hm over equatorial", "selectable": False, "deletable": False, "organization_id": "<value>", }, ], "medias": [ { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/lib", "mime_type": "<value>", "size": 887018, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2025-11-07T16:20:25.796Z"), "version": "<value>", "is_uploaded": True, "created_at": dateutil.parser.isoparse("2024-11-17T23:09:10.440Z"), "size_readable": "<value>", "public_url": "https://untimely-information.net/", "service": "product_media", }, { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/usr/local/bin", "mime_type": "<value>", "size": 75636, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2023-02-06T03:34:19.712Z"), "version": "<value>", "is_uploaded": True, "created_at": dateutil.parser.isoparse("2023-03-25T12:20:31.544Z"), "size_readable": "<value>", "public_url": "https://immense-finer.com/", "service": "product_media", }, { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/srv", "mime_type": "<value>", "size": 544978, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2024-09-24T17:52:13.602Z"), "version": "<value>", "is_uploaded": False, "created_at": dateutil.parser.isoparse("2023-09-28T13:20:26.690Z"), "size_readable": "<value>", "public_url": "https://pastel-character.info", "service": "product_media", }, ], }, { "created_at": dateutil.parser.isoparse("2023-09-09T06:37:57.046Z"), "modified_at": dateutil.parser.isoparse("2024-12-25T00:01:30.412Z"), "id": "<value>", "name": "<value>", "description": "delectable ugh likewise than every how milestone", "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "is_recurring": True, "is_archived": False, "organization_id": "<value>", "prices": [ { "created_at": dateutil.parser.isoparse("2025-04-20T22:18:45.464Z"), "modified_at": dateutil.parser.isoparse("2024-10-18T10:45:47.767Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "price_currency": "<value>", "price_amount": 688646, "amount_type": "fixed", "type": "recurring", "legacy": True, }, { "created_at": dateutil.parser.isoparse("2025-07-31T13:25:31.669Z"), "modified_at": dateutil.parser.isoparse("2023-11-12T09:40:10.044Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "type": polar_sdk.ProductPriceType.ONE_TIME, "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "amount_type": "free", }, { "created_at": dateutil.parser.isoparse("2025-06-25T22:47:14.264Z"), "modified_at": dateutil.parser.isoparse("2025-01-27T19:10:37.564Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "recurring_interval": polar_sdk.SubscriptionRecurringInterval.MONTH, "price_currency": "<value>", "price_amount": 18677, "amount_type": "fixed", "type": "recurring", "legacy": True, }, ], "benefits": [ { "created_at": dateutil.parser.isoparse("2024-04-20T16:45:08.626Z"), "modified_at": dateutil.parser.isoparse("2025-10-27T21:24:45.236Z"), "id": "<value>", "type": polar_sdk.BenefitType.DISCORD, "description": "until tenderly chapel quantify optimistically excluding aw because amongst emulsify", "selectable": False, "deletable": False, "organization_id": "<value>", }, { "created_at": dateutil.parser.isoparse("2023-12-28T12:56:50.963Z"), "modified_at": dateutil.parser.isoparse("2023-07-08T17:24:16.616Z"), "id": "<value>", "type": polar_sdk.BenefitType.LICENSE_KEYS, "description": "denitrify um extremely scotch breed rebuild tighten poppy unwritten apostrophize", "selectable": False, "deletable": True, "organization_id": "<value>", }, ], "medias": [ ], }, ], product={ "created_at": dateutil.parser.isoparse("2024-11-17T19:11:13.132Z"), "modified_at": dateutil.parser.isoparse("2024-02-27T04:46:39.621Z"), "id": "<value>", "name": "<value>", "description": "border opposite overload interior shady", "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "is_recurring": False, "is_archived": True, "organization_id": "<value>", "prices": [ ], "benefits": [ { "created_at": dateutil.parser.isoparse("2025-08-24T18:28:03.144Z"), "modified_at": dateutil.parser.isoparse("2023-10-21T11:52:11.842Z"), "id": "<value>", "type": polar_sdk.BenefitType.ADS, "description": "certainly these restfully geez who countess happily gym", "selectable": False, "deletable": False, "organization_id": "<value>", }, ], "medias": [ { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/private/tmp", "mime_type": "<value>", "size": 486328, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2023-09-26T17:28:00.673Z"), "version": "<value>", "is_uploaded": True, "created_at": dateutil.parser.isoparse("2025-05-06T18:54:29.001Z"), "size_readable": "<value>", "public_url": "https://forsaken-underpants.biz", "service": "product_media", }, { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/Users", "mime_type": "<value>", "size": 796127, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2023-09-05T18:42:07.313Z"), "version": "<value>", "is_uploaded": False, "created_at": dateutil.parser.isoparse("2025-10-05T11:55:07.194Z"), "size_readable": "<value>", "public_url": "https://quick-witted-markup.org/", "service": "product_media", }, ], }, product_price={ "created_at": dateutil.parser.isoparse("2023-04-02T00:05:42.586Z"), "modified_at": dateutil.parser.isoparse("2024-12-15T03:02:38.803Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "type": polar_sdk.ProductPriceType.RECURRING, "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "price_currency": "<value>", "price_amount": 825463, "amount_type": "fixed", }, discount={ "duration": polar_sdk.DiscountDuration.REPEATING, "type": polar_sdk.DiscountType.PERCENTAGE, "basis_points": 416143, "id": "<value>", "name": "<value>", "code": "<value>", }, subscription_id="<value>", attached_custom_fields=[ { "custom_field_id": "<value>", "custom_field": { "created_at": dateutil.parser.isoparse("2023-01-09T04:38:53.436Z"), "modified_at": dateutil.parser.isoparse("2024-12-24T07:52:43.518Z"), "id": "<value>", "metadata": { "key": "<value>", }, "slug": "<value>", "name": "<value>", "organization_id": "<value>", "properties": { "options": [ { "value": "<value>", "label": "<value>", }, ], }, "type": "select", }, "order": 169862, "required": True, }, { "custom_field_id": "<value>", "custom_field": { "created_at": dateutil.parser.isoparse("2024-04-28T02:33:08.095Z"), "modified_at": dateutil.parser.isoparse("2025-07-27T09:28:36.892Z"), "id": "<value>", "metadata": { "key": "<value>", }, "slug": "<value>", "name": "<value>", "organization_id": "<value>", "properties": {}, "type": "checkbox", }, "order": 918364, "required": True, }, { "custom_field_id": "<value>", "custom_field": { "created_at": dateutil.parser.isoparse("2024-11-27T14:29:40.329Z"), "modified_at": dateutil.parser.isoparse("2025-12-25T02:24:08.035Z"), "id": "<value>", "metadata": { "key": "<value>", }, "slug": "<value>", "name": "<value>", "organization_id": "<value>", "properties": { "options": [ { "value": "<value>", "label": "<value>", }, ], }, "type": "select", }, "order": 187532, "required": True, }, ], customer_metadata={ "key": "<value>", "key1": 790078, }, ), type="checkout.created", )) # Handle response print(res)
The same SDK client can also be used to make asychronous requests by importing asyncio.
# Asynchronous Example import asyncio import dateutil.parser import polar_sdk from polar_sdk import Polar async def main(): async with Polar() as polar: res = await polar.endpointcheckout_created_post_async(request=polar_sdk.WebhookCheckoutCreatedPayload( data=polar_sdk.Checkout( created_at=dateutil.parser.isoparse("2025-11-12T14:26:42.882Z"), modified_at=dateutil.parser.isoparse("2024-05-27T05:08:06.235Z"), id="<value>", payment_processor=polar_sdk.PaymentProcessor.STRIPE, status=polar_sdk.CheckoutStatus.FAILED, client_secret="<value>", url="https://heavy-beret.com/", expires_at=dateutil.parser.isoparse("2023-02-25T02:26:48.460Z"), success_url="https://sardonic-final.info/", embed_origin="<value>", amount=962818, tax_amount=6400, currency="Yen", subtotal_amount=648726, total_amount=210702, product_id="<value>", product_price_id="<value>", discount_id="<value>", allow_discount_codes=True, is_discount_applicable=False, is_free_product_price=False, is_payment_required=False, is_payment_setup_required=False, is_payment_form_required=False, customer_id="<value>", customer_name="<value>", customer_email="<value>", customer_ip_address="<value>", customer_billing_address={ "country": "Solomon Islands", }, customer_tax_id="<id>", payment_processor_metadata={ "key": "<value>", "key1": "<value>", "key2": "<value>", }, metadata={ "key": "<value>", }, products=[ { "created_at": dateutil.parser.isoparse("2024-05-27T05:08:06.235Z"), "modified_at": dateutil.parser.isoparse("2025-11-19T15:59:15.588Z"), "id": "<value>", "name": "<value>", "description": "brr institute tired rotten relative", "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "is_recurring": False, "is_archived": False, "organization_id": "<value>", "prices": [ ], "benefits": [ { "created_at": dateutil.parser.isoparse("2023-04-26T22:34:57.487Z"), "modified_at": dateutil.parser.isoparse("2023-08-07T19:57:51.694Z"), "id": "<value>", "type": polar_sdk.BenefitType.DISCORD, "description": "when waterlogged godparent pure solidly content sonar progress pacemaker", "selectable": True, "deletable": False, "organization_id": "<value>", }, { "created_at": dateutil.parser.isoparse("2024-10-18T15:45:53.088Z"), "modified_at": dateutil.parser.isoparse("2023-08-08T05:58:49.836Z"), "id": "<value>", "type": polar_sdk.BenefitType.LICENSE_KEYS, "description": "language traduce shrill minor hourly which yearly deeply but", "selectable": False, "deletable": False, "organization_id": "<value>", }, ], "medias": [ { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/Applications", "mime_type": "<value>", "size": 271748, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2023-03-11T18:00:05.573Z"), "version": "<value>", "is_uploaded": False, "created_at": dateutil.parser.isoparse("2025-09-09T13:21:53.200Z"), "size_readable": "<value>", "public_url": "https://male-season.net/", "service": "product_media", }, { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/bin", "mime_type": "<value>", "size": 187532, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2023-12-07T16:19:25.811Z"), "version": "<value>", "is_uploaded": False, "created_at": dateutil.parser.isoparse("2023-12-31T15:42:50.685Z"), "size_readable": "<value>", "public_url": "https://squeaky-editor.name", "service": "product_media", }, { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/usr/bin", "mime_type": "<value>", "size": 910846, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2025-02-19T14:34:23.071Z"), "version": "<value>", "is_uploaded": True, "created_at": dateutil.parser.isoparse("2024-07-14T23:53:19.831Z"), "size_readable": "<value>", "public_url": "https://sad-pupil.info/", "service": "product_media", }, ], }, { "created_at": dateutil.parser.isoparse("2025-09-29T06:23:47.676Z"), "modified_at": dateutil.parser.isoparse("2024-07-02T05:50:09.114Z"), "id": "<value>", "name": "<value>", "description": "as weekly drat nor why sparkling", "recurring_interval": polar_sdk.SubscriptionRecurringInterval.MONTH, "is_recurring": False, "is_archived": False, "organization_id": "<value>", "prices": [ { "created_at": dateutil.parser.isoparse("2023-09-19T22:46:24.110Z"), "modified_at": dateutil.parser.isoparse("2024-10-23T17:16:18.939Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "type": polar_sdk.ProductPriceType.ONE_TIME, "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "amount_type": "free", }, { "created_at": dateutil.parser.isoparse("2025-10-29T00:32:24.235Z"), "modified_at": dateutil.parser.isoparse("2025-04-28T15:46:25.145Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "type": polar_sdk.ProductPriceType.RECURRING, "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "price_currency": "<value>", "minimum_amount": 634111, "maximum_amount": 482040, "preset_amount": 134, "amount_type": "custom", }, ], "benefits": [ { "created_at": dateutil.parser.isoparse("2025-10-16T20:09:46.139Z"), "modified_at": dateutil.parser.isoparse("2023-09-29T18:20:07.088Z"), "id": "<value>", "type": polar_sdk.BenefitType.ADS, "description": "pupil divine roundabout gah oh hm over equatorial", "selectable": False, "deletable": False, "organization_id": "<value>", }, ], "medias": [ { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/lib", "mime_type": "<value>", "size": 887018, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2025-11-07T16:20:25.796Z"), "version": "<value>", "is_uploaded": True, "created_at": dateutil.parser.isoparse("2024-11-17T23:09:10.440Z"), "size_readable": "<value>", "public_url": "https://untimely-information.net/", "service": "product_media", }, { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/usr/local/bin", "mime_type": "<value>", "size": 75636, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2023-02-06T03:34:19.712Z"), "version": "<value>", "is_uploaded": True, "created_at": dateutil.parser.isoparse("2023-03-25T12:20:31.544Z"), "size_readable": "<value>", "public_url": "https://immense-finer.com/", "service": "product_media", }, { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/srv", "mime_type": "<value>", "size": 544978, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2024-09-24T17:52:13.602Z"), "version": "<value>", "is_uploaded": False, "created_at": dateutil.parser.isoparse("2023-09-28T13:20:26.690Z"), "size_readable": "<value>", "public_url": "https://pastel-character.info", "service": "product_media", }, ], }, { "created_at": dateutil.parser.isoparse("2023-09-09T06:37:57.046Z"), "modified_at": dateutil.parser.isoparse("2024-12-25T00:01:30.412Z"), "id": "<value>", "name": "<value>", "description": "delectable ugh likewise than every how milestone", "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "is_recurring": True, "is_archived": False, "organization_id": "<value>", "prices": [ { "created_at": dateutil.parser.isoparse("2023-10-21T11:52:11.842Z"), "modified_at": dateutil.parser.isoparse("2023-10-09T19:13:38.530Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "amount_type": "free", "type": "recurring", "legacy": True, }, { "created_at": dateutil.parser.isoparse("2024-12-10T06:44:06.426Z"), "modified_at": dateutil.parser.isoparse("2025-11-05T18:06:37.266Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "type": polar_sdk.ProductPriceType.RECURRING, "recurring_interval": polar_sdk.SubscriptionRecurringInterval.MONTH, "price_currency": "<value>", "minimum_amount": 102328, "maximum_amount": 332863, "preset_amount": 287633, "amount_type": "custom", }, { "created_at": dateutil.parser.isoparse("2024-09-15T18:10:19.969Z"), "modified_at": dateutil.parser.isoparse("2025-12-08T10:05:37.208Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "type": polar_sdk.ProductPriceType.RECURRING, "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "price_currency": "<value>", "minimum_amount": 674791, "maximum_amount": 138001, "preset_amount": 879649, "amount_type": "custom", }, ], "benefits": [ { "created_at": dateutil.parser.isoparse("2024-04-20T16:45:08.626Z"), "modified_at": dateutil.parser.isoparse("2025-10-27T21:24:45.236Z"), "id": "<value>", "type": polar_sdk.BenefitType.DISCORD, "description": "until tenderly chapel quantify optimistically excluding aw because amongst emulsify", "selectable": False, "deletable": False, "organization_id": "<value>", }, { "created_at": dateutil.parser.isoparse("2023-12-28T12:56:50.963Z"), "modified_at": dateutil.parser.isoparse("2023-07-08T17:24:16.616Z"), "id": "<value>", "type": polar_sdk.BenefitType.LICENSE_KEYS, "description": "denitrify um extremely scotch breed rebuild tighten poppy unwritten apostrophize", "selectable": False, "deletable": True, "organization_id": "<value>", }, ], "medias": [ ], }, ], product={ "created_at": dateutil.parser.isoparse("2024-11-17T19:11:13.132Z"), "modified_at": dateutil.parser.isoparse("2024-02-27T04:46:39.621Z"), "id": "<value>", "name": "<value>", "description": "border opposite overload interior shady", "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "is_recurring": False, "is_archived": True, "organization_id": "<value>", "prices": [ ], "benefits": [ { "created_at": dateutil.parser.isoparse("2025-08-24T18:28:03.144Z"), "modified_at": dateutil.parser.isoparse("2023-10-21T11:52:11.842Z"), "id": "<value>", "type": polar_sdk.BenefitType.ADS, "description": "certainly these restfully geez who countess happily gym", "selectable": False, "deletable": False, "organization_id": "<value>", }, ], "medias": [ { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/private/tmp", "mime_type": "<value>", "size": 486328, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2023-09-26T17:28:00.673Z"), "version": "<value>", "is_uploaded": True, "created_at": dateutil.parser.isoparse("2025-05-06T18:54:29.001Z"), "size_readable": "<value>", "public_url": "https://forsaken-underpants.biz", "service": "product_media", }, { "id": "<value>", "organization_id": "<value>", "name": "<value>", "path": "/Users", "mime_type": "<value>", "size": 796127, "storage_version": "<value>", "checksum_etag": "<value>", "checksum_sha256_base64": "<value>", "checksum_sha256_hex": "<value>", "last_modified_at": dateutil.parser.isoparse("2023-09-05T18:42:07.313Z"), "version": "<value>", "is_uploaded": False, "created_at": dateutil.parser.isoparse("2025-10-05T11:55:07.194Z"), "size_readable": "<value>", "public_url": "https://quick-witted-markup.org/", "service": "product_media", }, ], }, product_price={ "created_at": dateutil.parser.isoparse("2025-01-07T06:19:30.216Z"), "modified_at": dateutil.parser.isoparse("2025-12-22T08:06:55.176Z"), "id": "<value>", "is_archived": False, "product_id": "<value>", "type": polar_sdk.ProductPriceType.ONE_TIME, "recurring_interval": polar_sdk.SubscriptionRecurringInterval.YEAR, "price_currency": "<value>", "price_amount": 449076, "amount_type": "fixed", }, discount={ "duration": polar_sdk.DiscountDuration.REPEATING, "type": polar_sdk.DiscountType.PERCENTAGE, "basis_points": 416143, "id": "<value>", "name": "<value>", "code": "<value>", }, subscription_id="<value>", attached_custom_fields=[ { "custom_field_id": "<value>", "custom_field": { "created_at": dateutil.parser.isoparse("2023-07-01T09:35:23.526Z"), "modified_at": dateutil.parser.isoparse("2023-09-05T11:14:58.018Z"), "id": "<value>", "metadata": { "key": False, }, "slug": "<value>", "name": "<value>", "organization_id": "<value>", "properties": { "options": [ { "value": "<value>", "label": "<value>", }, ], }, "type": "select", }, "order": 169862, "required": True, }, { "custom_field_id": "<value>", "custom_field": { "created_at": dateutil.parser.isoparse("2024-12-03T12:38:50.277Z"), "modified_at": dateutil.parser.isoparse("2024-05-21T13:41:47.986Z"), "id": "<value>", "metadata": { "key": 473941, }, "slug": "<value>", "name": "<value>", "organization_id": "<value>", "properties": {}, "type": "text", }, "order": 918364, "required": True, }, { "custom_field_id": "<value>", "custom_field": { "created_at": dateutil.parser.isoparse("2023-01-30T18:58:55.355Z"), "modified_at": dateutil.parser.isoparse("2024-12-15T18:35:30.312Z"), "id": "<value>", "metadata": { "key": 143857, }, "slug": "<value>", "name": "<value>", "organization_id": "<value>", "properties": {}, "type": "text", }, "order": 187532, "required": True, }, ], customer_metadata={ "key": "<value>", "key1": 790078, }, ), type="checkout.created", )) # Handle response print(res) asyncio.run(main())
Webhook support
The SDK has built-in support to validate webhook events. Here is an example with Flask:
from flask import Flask, request from polar_sdk.webhooks import validate_event, WebhookVerificationError app = Flask(__name__) @app.route('/webhook', methods=['POST']) def webhook(): try: event = validate_event( payload=request.data, headers=request.headers, secret='<YOUR_WEBHOOK_SECRET>', ) # Process the event return "", 202 except WebhookVerificationError as e: return "", 403
Available Resources and Operations
Available methods
advertisements
benefits
- list - List Benefits
- create - Create Benefit
- get - Get Benefit
- update - Update Benefit
- delete - Delete Benefit
- grants - List Benefit Grants
checkout_links
- list - List Checkout Links
- create - Create Checkout Link
- get - Get Checkout Link
- update - Update Checkout Link
- delete - Delete Checkout Link
checkouts
- list - List Checkout Sessions
- create - Create Checkout Session
- get - Get Checkout Session
- update - Update Checkout Session
- client_get - Get Checkout Session from Client
- client_update - Update Checkout Session from Client
- client_confirm - Confirm Checkout Session from Client
custom_fields
- list - List Custom Fields
- create - Create Custom Field
- get - Get Custom Field
- update - Update Custom Field
- delete - Delete Custom Field
customer_portal
customer_portal.benefit_grants
customer_portal.customers
- get - Get Customer
customer_portal.downloadables
customer_portal.license_keys
- list - List License Keys
- get - Get License Key
- validate - Validate License Key
- activate - Activate License Key
- deactivate - Deactivate License Key
customer_portal.orders
customer_portal.organizations
- get - Get Organization
customer_portal.subscriptions
- list - List Subscriptions
- get - Get Subscription
- update - Update Subscription
- cancel - Cancel Subscription
customer_sessions
- create - Create Customer Session
customers
- list - List Customers
- create - Create Customer
- get - Get Customer
- update - Update Customer
- delete - Delete Customer
discounts
- list - List Discounts
- create - Create Discount
- get - Get Discount
- update - Update Discount
- delete - Delete Discount
events
external_organizations
- list - List External Organizations
files
- list - List Files
- create - Create File
- uploaded - Complete File Upload
- update - Update File
- delete - Delete File
license_keys
- list - List License Keys
- get - Get License Key
- update - Update License Key
- get_activation - Get Activation
meters
- list - List Meters
- create - Create Meter
- get - Get Meter
- update - Update Meter
- events - Get Meter Events
- quantities - Get Meter Quantities
metrics
oauth2
- authorize - Authorize
- token - Request Token
- revoke - Revoke Token
- introspect - Introspect Token
- userinfo - Get User Info
oauth2.clients
- list - List Clients
- create - Create Client
- get - Get Client
- update - Update Client
- delete - Delete Client
orders
organizations
- list - List Organizations
- create - Create Organization
- get - Get Organization
- update - Update Organization
products
- list - List Products
- create - Create Product
- get - Get Product
- update - Update Product
- update_benefits - Update Product Benefits
refunds
repositories
subscriptions
Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a RetryConfig object to the call:
from polar_sdk import Polar from polar_sdk.utils import BackoffStrategy, RetryConfig with Polar( access_token="<YOUR_BEARER_TOKEN_HERE>", ) as polar: res = polar.external_organizations.list(, RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False)) while res is not None: # Handle items res = res.next()
If you'd like to override the default retry strategy for all operations that support retries, you can use the retry_config optional parameter when initializing the SDK:
from polar_sdk import Polar from polar_sdk.utils import BackoffStrategy, RetryConfig with Polar( retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False), access_token="<YOUR_BEARER_TOKEN_HERE>", ) as polar: res = polar.external_organizations.list() while res is not None: # Handle items res = res.next()
Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.
By default, an API error will raise a models.SDKError exception, which has the following properties:
| Property | Type | Description |
|---|---|---|
.status_code |
int | The HTTP status code |
.message |
str | The error message |
.raw_response |
httpx.Response | The raw HTTP response |
.body |
str | The response content |
When custom error responses are specified for an operation, the SDK may also raise their associated exceptions. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the list_async method may raise the following exceptions:
| Error Type | Status Code | Content Type |
|---|---|---|
| models.HTTPValidationError | 422 | application/json |
| models.SDKError | 4XX, 5XX | */* |
Example
from polar_sdk import Polar, models with Polar( access_token="<YOUR_BEARER_TOKEN_HERE>", ) as polar: res = None try: res = polar.external_organizations.list() while res is not None: # Handle items res = res.next() except models.HTTPValidationError as e: # handle e.data: models.HTTPValidationErrorData raise(e) except models.SDKError as e: # handle exception raise(e)
Server Selection
Select Server by Name
You can override the default server globally by passing a server name to the server: str optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:
| Name | Server | Description |
|---|---|---|
production |
https://api.polar.sh |
Production environment |
sandbox |
https://sandbox-api.polar.sh |
Sandbox environment |
Example
from polar_sdk import Polar with Polar( server="sandbox", access_token="<YOUR_BEARER_TOKEN_HERE>", ) as polar: res = polar.external_organizations.list() while res is not None: # Handle items res = res.next()
Override Server URL Per-Client
The default server can also be overridden globally by passing a URL to the server_url: str optional parameter when initializing the SDK client instance. For example:
from polar_sdk import Polar with Polar( server_url="https://api.polar.sh", access_token="<YOUR_BEARER_TOKEN_HERE>", ) as polar: res = polar.external_organizations.list() while res is not None: # Handle items res = res.next()
Custom HTTP Client
The Python SDK makes API calls using the httpx HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance.
Depending on whether you are using the sync or async version of the SDK, you can pass an instance of HttpClient or AsyncHttpClient respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls.
This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of httpx.Client or httpx.AsyncClient directly.
For example, you could specify a header for every request that this sdk makes as follows:
from polar_sdk import Polar import httpx http_client = httpx.Client(headers={"x-custom-header": "someValue"}) s = Polar(client=http_client)
or you could wrap the client with your own custom logic:
from polar_sdk import Polar from polar_sdk.httpclient import AsyncHttpClient import httpx class CustomClient(AsyncHttpClient): client: AsyncHttpClient def __init__(self, client: AsyncHttpClient): self.client = client async def send( self, request: httpx.Request, *, stream: bool = False, auth: Union[ httpx._types.AuthTypes, httpx._client.UseClientDefault, None ] = httpx.USE_CLIENT_DEFAULT, follow_redirects: Union[ bool, httpx._client.UseClientDefault ] = httpx.USE_CLIENT_DEFAULT, ) -> httpx.Response: request.headers["Client-Level-Header"] = "added by client" return await self.client.send( request, stream=stream, auth=auth, follow_redirects=follow_redirects ) def build_request( self, method: str, url: httpx._types.URLTypes, *, content: Optional[httpx._types.RequestContent] = None, data: Optional[httpx._types.RequestData] = None, files: Optional[httpx._types.RequestFiles] = None, json: Optional[Any] = None, params: Optional[httpx._types.QueryParamTypes] = None, headers: Optional[httpx._types.HeaderTypes] = None, cookies: Optional[httpx._types.CookieTypes] = None, timeout: Union[ httpx._types.TimeoutTypes, httpx._client.UseClientDefault ] = httpx.USE_CLIENT_DEFAULT, extensions: Optional[httpx._types.RequestExtensions] = None, ) -> httpx.Request: return self.client.build_request( method, url, content=content, data=data, files=files, json=json, params=params, headers=headers, cookies=cookies, timeout=timeout, extensions=extensions, ) s = Polar(async_client=CustomClient(httpx.AsyncClient()))
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
| Name | Type | Scheme |
|---|---|---|
access_token |
http | HTTP Bearer |
To authenticate with the API the access_token parameter must be set when initializing the SDK client instance. For example:
from polar_sdk import Polar with Polar( access_token="<YOUR_BEARER_TOKEN_HERE>", ) as polar: res = polar.external_organizations.list() while res is not None: # Handle items res = res.next()
Resource Management
The Polar class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a context manager and reuse it across the application.
from polar_sdk import Polar def main(): with Polar( access_token="<YOUR_BEARER_TOKEN_HERE>", ) as polar: # Rest of application here... # Or when using async: async def amain(): async with Polar( access_token="<YOUR_BEARER_TOKEN_HERE>", ) as polar: # Rest of application here...
Debugging
You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass your own logger class directly into your SDK.
from polar_sdk import Polar import logging logging.basicConfig(level=logging.DEBUG) s = Polar(debug_logger=logging.getLogger("polar_sdk"))
Pagination
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
returned response object will have a Next method that can be called to pull down the next group of results. If the
return value of Next is None, then there are no more pages to be fetched.
Here's an example of one such pagination call:
from polar_sdk import Polar with Polar( access_token="<YOUR_BEARER_TOKEN_HERE>", ) as polar: res = polar.external_organizations.list() while res is not None: # Handle items res = res.next()
Summary
Polar API: Polar HTTP and Webhooks API
Read the docs at https://docs.polar.sh/api-reference
Table of Contents
Development
Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.