SDK
We officially maintain client libraries and SDK for a variety of languages. It'll help you integrate Polar API into your project in no time!
JavaScript
We maintain a SDK for JavaScript runtimes (Node.js and browsers). It's available on npm.
Quickstart
npm add @polar-sh/sdkimport { Polar } from '@polar-sh/sdk'
const polar = new Polar({
accessToken: process.env['POLAR_ACCESS_TOKEN'] ?? '',
})
async function run() {
const result = await polar.users.benefits.list({})
for await (const page of result) {
// Handle the page
console.log(page)
}
}
run()Sandbox environment
You can configure the SDK so it hits the sandbox environment instead of the production one. You just need to add the server property to the configuration object:
const polar = new Polar({
server: 'sandbox',
accessToken: process.env['POLAR_ACCESS_TOKEN'] ?? '',
})Python
We maintain a SDK for Python. It's fully type-hinted and allows both synchronous and asynchronous usage, thanks to HTTPX. Under the hood, schemas are validated by Pydantic.
It's available on PyPI.
Quickstart
pip install polar-sdk# Synchronous Example
from polar_sdk import Polar
s = Polar(
access_token="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.users.benefits.list()
if res is not None:
while True:
# handle items
res = res.Next()
if res is None:
breakSandbox environment
You can configure the SDK so it hits the sandbox environment instead of the production one. You just need to add the server argument when instantiating the client:
s = Polar(
server="sandbox",
access_token="<YOUR_BEARER_TOKEN_HERE>",
)Go
We maintain a SDK for Go.
Quickstart
go get github.com/polarsource/polar-gopackage main
import(
"context"
"os"
polargo "github.com/polarsource/polar-go"
"log"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
res, err := s.Benefits.List(ctx, nil, nil, nil, nil)
if err != nil {
log.Fatal(err)
}
if res.ListResourceBenefit != nil {
for {
// handle items
res, err = res.Next()
if err != nil {
// handle error
}
if res == nil {
break
}
}
}
}Sandbox environment
You can configure the SDK so it hits the sandbox environment instead of the production one. You just need to add the WithServer option when initializing the client:
s := polargo.New(
polargo.WithServer("sandbox"),
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)