-
Notifications
You must be signed in to change notification settings - Fork 240
refactor!: Make the FastAPI and Starlette dependencies optional #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor!: Make the FastAPI and Starlette dependencies optional #217
Conversation
With this update, using A2AFastAPIApplication requires either adding the FastAPI package directly to the project or indicating the "fastapi" group when installing a2a-sdk, e.g., with uv "uv add a2a-sdk[fastapi]" or with pip "pip install a2a-sdk[fastapi]"
When defining missing optional dependencies from fastapi, mypy issues errors of the following form: 'Name "FastAPI" already defined (possibly by an import) [no-redef]'. This commit fixes such mypy errors.
Updates the FastAPI optional dependency installation instructions in README.md.
On app initialization with app = A2aFastAPIApplication(), check that the FastAPI package is installed and raise ImportError with the custom messsage if necessary.
This won't solve the core issue on its own, because starlette is also a dependency and it depends on fastapi, so you'll need to remove that dependency as well. |
Hi @holtskinner,
It seems the dependencies are the other way around, so if we do it one framework at a time, I think refactoring FastAPI first makes sense. Starlette dependency treeA quick dependency check shows that
for reference, see FastAPI dependency tree hereFastAPI dependency treeOn the other hand, if a project requires
SDK development vs downstream project dependenciesI kept FastAPI in dev dependencies so that when working on the SDK itself, i.e., running At the same time, with this refactoring non-FastAPI downstream projects (agents) that use Considerations for next steps (refactoring
|
Package respx was added by another PR, so we need to resync uv.lock.
3788450
to
1d06e63
Compare
@darkhaniop Sorry for the extra hassle, but could you make this work with the new refactoring in #348 |
* chore(deps): Update python samples' optional deps In future versions of a2a-sdk, HTTP server packages may become optional. See a2aproject/a2a-python/pull/217 for details. This PR ensures that agents in `samples/python/agents/` continue to work with the future versions on a2a-sdk. Refs #190 * Add langchain-openai dep to the langgraph sample This issue was noted by the automated code review bot.
Adds optional card_modifier and extended_card_modifier params to A2AFastAPIApplication and A2AStarletteApplication constructors.
Additionally, coverage fails when test files have the same name: ./jsonrpc_test_fastapi_app.py and ./rest/test_fastapi_app.py So, the latter one was renamed to ./rest/test_rest_fastapi_app.py
Ensures the version specifier is the same as on the main branch.
This ensures the importing of the upper level packages a2a.server.apps succeed when optional http-server dependencies are not installed.
From what I understood, the newly added RESTful interface modules directly import Starlette and FastAPI (and since they are always initialized by the upper-level package in So, I refactored the imports and made other minor adjustments to make it work with recent changes from the main branch. Please let me know if you find anything missing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
thanks for the PR. I see a couple of other places where the starlette imports are unhandled. Can you please address these as well?
from starlette.requests import Request |
from starlette.responses import JSONResponse, Response |
Ensures [http-server] optional dependency imports are handled within try-except in utility modules: - server/request_handlers/rest_handler.py - and utils/error_handlers.py Also, removes duplicate imports from `starlette` in `rest_adapter.py`.
@kthota-g, thanks for the review. I applied the changes. In |
BEGIN_COMMIT_OVERRIDE
Description
This update makes Starlette and FastAPI libraries as optional dependencies. Users can run
uv add a2a-sdk[http-server]
to install these dependencies.Additional Checks
A2AFastAPIApplication
.Release-As: 0.3.1
END_COMMIT_OVERRIDE