Skip to content

Conversation

evansims
Copy link
Member

@evansims evansims commented Oct 3, 2025

This pull request adds a headers property to the SDK's client configuration class, allowing developers to pass headers that are automatically included in all API requests by default.

This pattern aligns the Python SDK with behavior already present in the other SDKs.

from openfga_sdk.client import ClientConfiguration, OpenFgaClient

# Configure default headers that apply to ALL requests
config = ClientConfiguration(
    api_url="https://api.fga.example",
    store_id="01ARZ3NDEKTSV4RRFFQ69G5FAV",
    headers={
        "X-Tenant-ID": "tenant-123",
        "X-App-Version": "1.0.0",
        "X-Request-Priority": "normal"
    }
)

async with OpenFgaClient(config) as client:
    # Default headers are automatically included in all requests
    await client.read_authorization_models()
    # Includes: X-Tenant-ID: tenant-123, X-App-Version: 1.0.0, X-Request-Priority: normal

    # Add per-request headers (merged with defaults)
    await client.check(
        user="user:alice",
        relation="viewer",
        object="document:roadmap",
        options={
            "headers": {
                "X-Request-ID": "req-456",
                "X-Correlation-ID": "corr-789"
            }
        }
    )
    # Includes: X-Tenant-ID: tenant-123, X-App-Version: 1.0.0, X-Request-Priority: normal,
    #           X-Request-ID: req-456, X-Correlation-ID: corr-789

    # Override default headers with per-request values
    await client.check(
        user="user:bob",
        relation="admin",
        object="document:secrets",
        options={
            "headers": {
                "X-Request-Priority": "high", # Overrides default "normal" priority
                "X-Request-ID": "req-789"
            }
        }
    )
    # Includes: X-Tenant-ID: tenant-123, X-App-Version: 1.0.0,
    #           X-Request-Priority: high (OVERRIDDEN), X-Request-ID: req-789

References

openfga/sdk-generator#631

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

@evansims evansims requested review from a team as code owners October 3, 2025 23:37
@evansims evansims added the documentation Improvements or additions to documentation label Oct 3, 2025
@evansims evansims requested a review from a team as a code owner October 3, 2025 23:37
@codecov-commenter
Copy link

codecov-commenter commented Oct 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.79%. Comparing base (8e38d75) to head (0f812e4).

❌ Your project status has failed because the head coverage (70.79%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #232      +/-   ##
==========================================
+ Coverage   70.73%   70.79%   +0.05%     
==========================================
  Files         134      134              
  Lines       10882    10904      +22     
==========================================
+ Hits         7697     7719      +22     
  Misses       3185     3185              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

README.md updated to document setting custom HTTP headers in the OpenFGA Python SDK, including default headers via set_default_header and per-request headers via options.headers, with synchronous client notes and examples.

Changes

Cohort / File(s) Summary
Documentation: Custom Headers in Python SDK
README.md
Added sections describing default headers (via set_default_header) and per-request headers (options.headers), with code samples and a synchronous client note; reorganized/duplicated header guidance under Getting Started.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

Suggested reviewers

  • rhamzeh

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title “feat: add headers configuration property” implies a new code feature and configuration API change, but the PR only updates README documentation to demonstrate custom header usage without altering any exported code entities. This mismatch makes the title misleading and not reflective of the actual changes. Rename the pull request title to clearly describe the documentation update, for example “docs: add custom headers guidance to README.md” so it accurately reflects that only README content was changed.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docs/custom-headers

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.

Copy link
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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e38d75 and 35ca07f.

📒 Files selected for processing (1)
  • README.md (1 hunks)

@evansims evansims changed the title docs: add custom headers guidance to README feat: add headers configuration property Oct 6, 2025
@evansims evansims added this pull request to the merge queue Oct 6, 2025
Merged via the queue into main with commit ac3395c Oct 6, 2025
28 checks passed
@evansims evansims deleted the docs/custom-headers branch October 6, 2025 16:26
@coderabbitai coderabbitai bot mentioned this pull request Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add documentation and examples for per-request custom HTTP headers usage
3 participants