Python logo

Integrate WorkOS using the Python SDK

Easily add enterprise features like Single Sign-On (SSO/SAML), Directory Sync (SCIM), Audit Trail (SIEM), and Access Control (IAM) to your Python app.

Installation

You can install the Python SDK via PyPi with:

Terminal

file_copy
pip install workos

Alternatively, you can also install from source:

Terminal

file_copy
git clone git@github.com:workos-inc/workos-python.git && python setup.py install

Usage

Below is an example integration that adds SSO using the Python SDK. You can find other examples and more information in our Python SDK Docs.

Python

file_copy
import workos

workos.api_key = "WORKOS_API_SECRET_KEY"
workos.project_id = "PROJECT_ID"
  
DOMAIN = 'example.com'
REDIRECT_URI = 'REDIRECT_URI'

@app.route('/auth')
def auth():
  authorization_url = client.sso.get_authorization_url(
    DOMAIN,
    REDIRECT_URI,
    state={}
  )

  return redirect(authorization_url)

@app.route('/auth/callback')
def auth_callback():
  code = request.args.get('code')
  profile = client.sso.get_profile(code)

  return profile.to_dict()

Start Integrating Today

Create an account to begin adding enterprise-ready features to your application today.