Skip to content

feat: add dynamic module loading for client imports#871

Open
GunniBusch wants to merge 1 commit intoauthlib:mainfrom
GunniBusch:patch-1
Open

feat: add dynamic module loading for client imports#871
GunniBusch wants to merge 1 commit intoauthlib:mainfrom
GunniBusch:patch-1

Conversation

@GunniBusch
Copy link
Copy Markdown

What kind of change does this PR introduce?

This PR introduces a bugfix for developer ergonomics/import discovery.

It adds lazy-exported integration submodules in authlib.integrations.__init__ (including starlette_client) so IDEs/type checkers can resolve authlib.integrations.starlette_client correctly without forcing eager imports of optional integrations.

Related issue/PR: N/A.

Does this PR introduce a breaking change?

No.

Checklist

  • The commits follow the conventional commits specification.
  • You ran the linters with prek.
  • You wrote unit test to demonstrate the bug you are fixing, or to stress the feature you are bringing.
  • You reached 100% of code coverage on the code you edited, without abusive use of pragma: no cover
  • If this PR is about a new feature, or a behavior change, you have updated the documentation accordingly. (N/A)

  • You consent that the copyright of your pull request source code belongs to Authlib's author.
    This pull request refactors the authlib/integrations/__init__.py file to implement lazy loading for its submodules. This approach optimizes import times and resource usage by only loading submodules when they are actually accessed.

Key changes:

Lazy Loading Implementation:

  • Introduced a __getattr__ function that uses importlib.import_module to dynamically import submodules listed in __all__ when accessed as attributes. This enables lazy loading of integration submodules.

Type Checking Support:

  • Added a TYPE_CHECKING block to ensure that type checkers are aware of the available submodules without triggering actual imports at runtime.

Module Export Definition:

  • Defined an explicit __all__ list to specify the public submodules available for import from the authlib.integrations package.

@GunniBusch
Copy link
Copy Markdown
Author

GunniBusch commented Mar 11, 2026

The tests are failing due to a lower test coverage. But it doesn’t make sense to test a __init__.py file

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant