Skip to content

chore: Fix incorrect Management API docs in Python SDK#675

Open
Koosha-Owji wants to merge 3 commits intokinde-oss:mainfrom
Koosha-Owji:main
Open

chore: Fix incorrect Management API docs in Python SDK#675
Koosha-Owji wants to merge 3 commits intokinde-oss:mainfrom
Koosha-Owji:main

Conversation

@Koosha-Owji
Copy link
Copy Markdown
Contributor

@Koosha-Owji Koosha-Owji commented Mar 3, 2026

Description (required)

The Management API section of the Python SDK docs showed oauth.get_management() — a method that doesn't exist on any of the SDK's OAuth classes. Rewrote the section to use the correct ManagementClient class with non-deprecated API class methods, accurate method signatures, proper FastAPI handler definitions, and correct token lifecycle documentation.

Summary by CodeRabbit

  • Documentation
    • Reworked Python SDK docs to emphasize a dedicated Management API client and explicit initialization patterns.
    • Added an "Available endpoints" section describing discoverable API properties and direct endpoint usage.
    • Expanded "Error handling" with concrete examples and best practices for robustness.
    • Updated authentication and credential handling guidance (client-credentials flow, token caching) and reorganized management-related sections for clarity.

@Koosha-Owji Koosha-Owji requested a review from a team as a code owner March 3, 2026 02:33
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 3, 2026

Walkthrough

Documentation reworked to center the Python Management API around a standalone ManagementClient (client-credentials flow). Examples, authentication patterns, dynamic endpoint discovery (snake_case API properties), error handling, and dotenv-based credential loading were updated and reorganized.

Changes

Cohort / File(s) Summary
Python SDK Documentation
src/content/docs/developer-tools/sdks/backend/python-sdk.mdx
Replaced OAuth-wrapper workflow with a standalone ManagementClient usage pattern. Updated init examples to use domain/client_id/client_secret and dotenv, added "Available endpoints" (snake_case API properties), refactored examples to call management.<api>. methods, documented client-credentials token caching/validation behavior, and expanded error handling and best practices sections. Areas to review: authentication examples, token lifecycle text, and updated code samples.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Python

Suggested reviewers

  • clairekinde11

Poem

🐰 I hop through docs with a jubilant twitch,
ManagementClient now takes center stitch,
Endpoints found in snake_case lines,
Dotenv stores keys, the flow refines,
A rabbit cheers—clean, clear, and rich! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing incorrect Management API documentation in the Python SDK by replacing non-existent oauth.get_management() with the correct ManagementClient class.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the sdk label Mar 3, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/content/docs/developer-tools/sdks/backend/python-sdk.mdx`:
- Around line 1408-1412: The snippet imports load_dotenv and will raise
ModuleNotFoundError unless python-dotenv is installed; update the docs near the
example to explicitly state the prerequisite and installation command (e.g.,
"pip install python-dotenv") and mention that load_dotenv() must be called
before initializing ManagementClient to load environment variables; reference
the import load_dotenv and the ManagementClient usage so the reader knows where
the note applies.
- Around line 1573-1580: The get_user endpoint currently catches broad Exception
and returns the raw error in HTTPException; change get_user to catch the
SDK-specific error type (e.g., ApiException or the SDK's typed error from
management.users_api.get_user_data) and handle it explicitly: map known SDK
status codes to appropriate FastAPI responses and return sanitized error
messages (no raw exception text) in HTTPException(detail=...), while logging the
full error server-side (using your logger) for diagnostics; leave a generic 500
catch-all that logs the error but returns a non-sensitive generic message.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85e89d3 and e7a6ee6.

📒 Files selected for processing (1)
  • src/content/docs/developer-tools/sdks/backend/python-sdk.mdx

@onderay onderay requested review from a team and tamalchowdhury March 4, 2026 04:42
@tamalchowdhury
Copy link
Copy Markdown
Collaborator

Kindly resolve the coderabbit issues and it should be good.

Copy link
Copy Markdown
Collaborator

@tamalchowdhury tamalchowdhury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve the coderabbit issues and it should be ready to go.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/content/docs/developer-tools/sdks/backend/python-sdk.mdx (1)

1566-1593: The defensive check for ApiException.status is not necessary in this context.

ApiException is OpenAPI-generated and always includes an HTTP status code when raised from a response. The e.status attribute will be populated as an integer in all normal exception flows. Adding a defensive fallback like 502 introduces unnecessary complexity for documentation code that should demonstrate the standard pattern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/content/docs/developer-tools/sdks/backend/python-sdk.mdx` around lines
1566 - 1593, The docs example should rely on the OpenAPI-generated ApiException
having a populated status, so in the get_user handler remove any defensive
fallback for ApiException.status and raise HTTPException using e.status
directly; update the exception block that references ApiException, keeping
logger.error("Kinde API error: %s %s", e.status, e.body) and replacing any code
like "status_code=e.status or 502" with "status_code=e.status" so the example
shows the standard pattern for ApiException handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/content/docs/developer-tools/sdks/backend/python-sdk.mdx`:
- Around line 1597-1604: Update the documentation text describing
ManagementClient's refresh behavior: remove the hardcoded "60 seconds before
expiration" claim and instead state that the client requests new tokens via the
client credentials grant when existing tokens expire, and that token lifetime is
configurable in the Kinde portal per application; adjust the sentence
referencing "Automatic re-acquisition" to reflect this and keep the rest of the
token acquisition/caching/shared-token wording unchanged (refer to the
ManagementClient description block).

---

Nitpick comments:
In `@src/content/docs/developer-tools/sdks/backend/python-sdk.mdx`:
- Around line 1566-1593: The docs example should rely on the OpenAPI-generated
ApiException having a populated status, so in the get_user handler remove any
defensive fallback for ApiException.status and raise HTTPException using
e.status directly; update the exception block that references ApiException,
keeping logger.error("Kinde API error: %s %s", e.status, e.body) and replacing
any code like "status_code=e.status or 502" with "status_code=e.status" so the
example shows the standard pattern for ApiException handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6d6f0327-68c6-4c56-b385-bf0e0357ca3e

📥 Commits

Reviewing files that changed from the base of the PR and between e7a6ee6 and 6c7b73c.

📒 Files selected for processing (1)
  • src/content/docs/developer-tools/sdks/backend/python-sdk.mdx

Comment on lines +1597 to +1604
The `ManagementClient` has its own token management system that is separate from the OAuth authentication clients. It uses the OAuth2 client credentials flow and automatically handles:

- **accessing Kinde Management API endpoints**: Obtains tokens for accessing Kinde's management endpoints
- **Token refresh**: Automatically refreshes management API tokens when they expire
- **Token storage**: Securely stores management API tokens
- **Thread safety**: Ensures thread-safe token handling for concurrent requests
- **Token acquisition**: Obtains tokens using a client credentials grant on the first API call
- **Token caching**: Tokens are cached and reused to avoid unnecessary requests
- **Automatic re-acquisition**: Requests new tokens via a client credentials grant when existing ones near expiry (60 seconds before expiration)
- **Shared tokens**: Multiple `ManagementClient` instances with the same domain and client ID share the same token

You don't need to manually manage Management API tokens - the client handles this for you. This is different from the core SDK's user session token management, which handles user authentication tokens automatically.
You don't need to manually manage tokens -- the client handles this for you. Note that credentials are validated on the first API call, not during client initialization. If your credentials are incorrect, the error will surface when you make your first request.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's find if there's a kinde-python-sdk directory or reference in the repository
find . -type d -name "*python*" -o -type d -name "*kinde*" 2>/dev/null | head -20

Repository: kinde-oss/documentation

Length of output: 280


🏁 Script executed:

# Search for any references to ManagementClient and token refresh in the current repo
rg -i "managementclient" --type=md -A 3 -B 3 | head -50

Repository: kinde-oss/documentation

Length of output: 49


🏁 Script executed:

# Look for the specific documentation file mentioned
find . -path "*python-sdk.mdx" 2>/dev/null

Repository: kinde-oss/documentation

Length of output: 129


🏁 Script executed:

# Read the specific lines mentioned in the review
sed -n '1590,1610p' ./src/content/docs/developer-tools/sdks/backend/python-sdk.mdx

Repository: kinde-oss/documentation

Length of output: 1565


🌐 Web query:

kinde-python-sdk ManagementClient token refresh 60 seconds

💡 Result:

In kinde-python-sdk, the ManagementClient / Management API client uses the OAuth2 client credentials flow, so it doesn’t use a refresh token; instead it caches the management access token and automatically fetches a new one when it expires. Multiple client instances with the same domain + client id can share the cached token. [1]

If you configure your Kinde application’s access token lifetime to 60 seconds, then the management access token will naturally expire every ~60 seconds and the SDK will renew it that often. Token lifetimes are configured in the Kinde portal per application (Settings → Environment → Applications → View details → Tokens → set expiry in seconds). [2]

Kinde’s Python SDK docs also note the Management API client’s token handling is separate from user-session token management and that it auto-refreshes management API tokens on expiry. [3]

Sources:
[1] Kinde Python SDK repo (Token Management section) (github.com)
[2] Kinde docs: Configure token and session expiry (docs.kinde.com)
[3] Kinde docs: Python SDK → Management API → Token management (docs.kinde.com)

Citations:


🌐 Web query:

kinde-python-sdk github repository

💡 Result:

The kinde-python-sdk GitHub repository is: https://github.com/kinde-oss/kinde-python-sdk [1].

(Starter kit repo: https://github.com/kinde-starter-kits/python-starter-kit [2].)


🏁 Script executed:

# Let's look at the kinde-python-sdk repository to verify the actual token refresh logic
# Search for token refresh/renewal code references
curl -s "https://api.github.com/repos/kinde-oss/kinde-python-sdk/contents/" | jq -r '.[].name' | head -20

Repository: kinde-oss/documentation

Length of output: 131


🏁 Script executed:

# Search within the documentation repo for any other token-related discussions
rg -i "60 seconds|token.*expir" ./src/content/docs/developer-tools/sdks/ -A 2 -B 2 --type=md | head -60

Repository: kinde-oss/documentation

Length of output: 49


Clarify ManagementClient token refresh behavior — it's not a hardcoded 60-second buffer.

The statement "Requests new tokens via a client credentials grant when existing ones near expiry (60 seconds before expiration)" is misleading. The SDK doesn't have a hardcoded 60-second pre-expiry refresh. Instead, token lifetime is configurable in the Kinde portal per application, and the SDK automatically refreshes when tokens expire. The "60 seconds" only applies if the application's token lifetime is configured to 60 seconds.

Rephrase to: "Requests new tokens via a client credentials grant when existing tokens expire" and remove the specific timeout reference. The token caching and shared-token-across-instances claims are accurate.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/content/docs/developer-tools/sdks/backend/python-sdk.mdx` around lines
1597 - 1604, Update the documentation text describing ManagementClient's refresh
behavior: remove the hardcoded "60 seconds before expiration" claim and instead
state that the client requests new tokens via the client credentials grant when
existing tokens expire, and that token lifetime is configurable in the Kinde
portal per application; adjust the sentence referencing "Automatic
re-acquisition" to reflect this and keep the rest of the token
acquisition/caching/shared-token wording unchanged (refer to the
ManagementClient description block).

@dtoxvanilla1991 dtoxvanilla1991 self-assigned this Apr 8, 2026
@dtoxvanilla1991
Copy link
Copy Markdown
Contributor

I'll resolve CAai comment tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants