{"library":"polar-sdk","title":"Polar SDK","description":"The `polar-sdk` is the official Python client for the Polar API, designed to help developers integrate subscription and monetization features into their applications. It provides access to resources like products, subscriptions, and webhooks. As of version 0.31.3, it offers both synchronous and asynchronous interfaces and is actively maintained with frequent updates.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install polar-sdk"],"cli":null},"imports":["from polar import Polar","from polar.exceptions import PolarError"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom polar import Polar\nfrom polar.exceptions import PolarError\n\n# Initialize the Polar client. It automatically uses the POLAR_API_KEY\n# environment variable if set. Otherwise, you can pass it directly.\n# For testing, you might use a dummy key if not interacting with a live API.\nclient = Polar(auth=os.environ.get(\"POLAR_API_KEY\", \"sk_test_..._your_key\"))\n\nasync def main():\n    try:\n        # Example: List subscriptions (using the async client)\n        print(\"Attempting to list subscriptions...\")\n        subscriptions_page = await client.subscriptions.list(limit=5)\n\n        if subscriptions_page.items:\n            print(f\"Found {len(subscriptions_page.items)} subscriptions:\")\n            for sub in subscriptions_page.items:\n                print(f\"  - ID: {sub.id}, Status: {sub.status}, Product ID: {sub.product_id}\")\n        else:\n            print(\"No subscriptions found.\")\n\n    except PolarError as e:\n        print(f\"Polar API Error: {e.status_code} - {e.body}\")\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")\n\nif __name__ == \"__main__\":\n    # For running async code in a sync context (e.g., top-level script)\n    import asyncio\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates how to initialize the `Polar` client, fetch a list of subscriptions, and handle potential API errors. It uses an asynchronous client, which is recommended for modern Python applications. Ensure you have `POLAR_API_KEY` set in your environment or replace the placeholder with your actual API key.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}