feat(python): Make framework and client dependencies optional extras #886
+115
−31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Problem
Hey, I tried installing
x402for a FastAPI project and noticed it installs all frameworks and clients (Flask, FastAPI, httpx, requests) as hard dependencies, even if you only need FastAPI.This causes unnecessary bloat, potential version conflicts, and makes it harder to add new integrations in the future as more middleware and clients are added.
Solution
I propose moving framework and client deps to optional extras, with graceful import errors when missing.
This avoids import-time coupling and keeps the package lean and extensible for future integrations.
Extras:
flask,fastapi,httpx,requests,servers,clients,allAdded clear errors when deps are missing:
Breaking Changes
Frameworks and clients are no longer installed by default:
pip install x402[fastapi,httpx] # or pip install x402 fastapi httpxClients are now imported from their submodules:
I was considering using lazy imports instead, but it would've increased maintenance costs and probably is bad r/r.
Tests
No new tests needed. All existing tests are passing.
Checklist