Python Backend SDK

Category
SDK
Published

We've released a new backend SDK for Python! Here's a quick overview of its capabilities and some resources to help you get started.

We're pleased to announce the release of our server-side Python SDK!

With this launch, Python developers can more easily interface with the Clerk Backend API to manage users, organizations, and sessions.

Asynchronous backend API call with asyncio
import asyncio
from clerk_backend_api import Clerk

async def main():
    sdk = Clerk(
        bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
    )
    res = await sdk.email_addresses.get_async(
        email_address_id="email_address_id_example"
    )
    if res is not None:
        # handle response
        pass

asyncio.run(main())

This release also makes it straightforward to authenticate backend requests in Django, Flask, and other Python web frameworks:

authenticateRequest in action
import os
import httpx
from clerk_backend_api import Clerk
from clerk_backend_api.jwks_helpers import AuthenticateRequestOptions

def is_signed_in(request: httpx.Request):
    sdk = Clerk(bearer_auth=os.getenv('CLERK_SECRET_KEY'))
    request_state = sdk.authenticate_request(
        request,
        AuthenticateRequestOptions(
            authorized_parties=['https://example.com']
        )
    )
    return request_state.is_signed_in

You can pip install the new clerk-backend-api module in any Python 3.8+ application to get started. To help you from there, we've prepared detailed reference documentation in the SDK GitHub repository.

Special thanks to Speakeasy for partnering with us on this SDK release 🎉!