-
Notifications
You must be signed in to change notification settings - Fork 334
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
Merged
kthota-g
merged 49 commits into
a2aproject:main
from
darkhaniop:make-fastapi-package-optional
Aug 7, 2025
Merged
Changes from 36 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
95523a3
refactor!: Make the FastAPI dependency optional
darkhaniop 3661aa8
Ignore name redef warnings on ImportError
darkhaniop a74f5e5
Update .github/actions/spelling/allow.txt
darkhaniop 012ea77
Updates the installation instructions in README.md
darkhaniop d29c63a
Check FastAPI package on A2AFastAPIApplication()
darkhaniop 800a29a
Update A2AFastAPIApplication.__init__ docstring
darkhaniop 2af0be8
Merge branch 'main' into make-fastapi-package-optional
darkhaniop 1d06e63
Regenerate uv.lock
darkhaniop abfa743
Merge branch 'main' into make-fastapi-package-optional
holtskinner fe26fa1
Refactor to make starlette optional
holtskinner 17766ae
Fix mypy errors
holtskinner 46e2a5c
Formatting
holtskinner 61c5ca7
Remove uvlock
holtskinner 1678fd1
Merge branch 'main' of https://github.com/google-a2a/a2a-python into …
holtskinner 24c98e5
Recreate uv.lock
holtskinner 16059fb
Remove extra check for FastAPI
holtskinner c2f3454
Spelling
holtskinner 267bc4b
Merge branch 'main' into make-fastapi-package-optional
darkhaniop d1895af
Remove imports from starlette outside try-except
darkhaniop 2d214f1
Split starlette and fastapi imports and error msg
darkhaniop acdd67b
Merge branch 'main' into make-fastapi-package-optional
darkhaniop c73492c
Merge branch 'main' into make-fastapi-package-optional
holtskinner 7e159cd
Merge branch 'main' into make-fastapi-package-optional
darkhaniop 975e865
Add tests for initiation of apps with missing deps
darkhaniop 14d2db5
Merge branch 'main' into make-fastapi-package-optional
darkhaniop 804a1f4
Merge branch 'main' into make-fastapi-package-optional
holtskinner 3e1df0a
Formatting/tests
holtskinner 180898b
Merge branch 'main' into make-fastapi-package-optional
holtskinner e8233d1
Merge branch 'main' into make-fastapi-package-optional
darkhaniop 3f48966
Merge branch 'main' into make-fastapi-package-optional
holtskinner a65770f
Re-create uv lock
holtskinner aaacec1
Merge branch 'main' into make-fastapi-package-optional
holtskinner c5e4cbd
Merge branch 'main' into make-fastapi-package-optional
holtskinner ba5ec6e
regenerate uv lock
holtskinner 0d3643c
Merge branch 'main' into make-fastapi-package-optional
holtskinner f93abd8
Regenerate uv lock
holtskinner 35c3ea3
Merge branch 'main' of https://github.com/a2aproject/a2a-python into …
holtskinner bd41ca8
Re-add version for fastapi
holtskinner 4fcf7c6
Formatting
holtskinner 8f5e5a2
Merge branch 'main' into make-fastapi-package-optional
darkhaniop b5b3401
Merge branch 'main' into make-fastapi-package-optional
darkhaniop af76625
Update app constructor signatures
darkhaniop 2f74bc8
Update mock agent card attributes in tests
darkhaniop 6df65ac
Fix protobuf dependency
darkhaniop 89605bc
Refactor optional deps imports in apps/rest/*
darkhaniop 38739b7
Change coverage requirements to 88 percent
darkhaniop 109488c
Refactor starlette imports in utility modules
darkhaniop fa45bc8
Fix docstring (addresses a spell-checker error)
darkhaniop 9fa9e69
Merge branch 'main' into make-fastapi-package-optional
holtskinner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,7 @@ pyi | |
| pypistats | ||
| pyupgrade | ||
| pyversions | ||
| redef | ||
| respx | ||
| resub | ||
| RUF | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,11 @@ authors = [{ name = "Google LLC", email = "[email protected]" }] | |
| requires-python = ">=3.10" | ||
| keywords = ["A2A", "A2A SDK", "A2A Protocol", "Agent2Agent", "Agent 2 Agent"] | ||
| dependencies = [ | ||
| "fastapi>=0.115.2", | ||
| "httpx>=0.28.1", | ||
| "httpx-sse>=0.4.0", | ||
| "opentelemetry-api>=1.33.0", | ||
| "opentelemetry-sdk>=1.33.0", | ||
| "pydantic>=2.11.3", | ||
| "sse-starlette", | ||
| "starlette" | ||
| ] | ||
|
|
||
| classifiers = [ | ||
|
|
@@ -32,6 +29,7 @@ classifiers = [ | |
| ] | ||
|
|
||
| [project.optional-dependencies] | ||
| http-server = ["fastapi>=0.115.2", "sse-starlette", "starlette"] | ||
| postgresql = ["sqlalchemy[asyncio,postgresql-asyncpg]>=2.0.0"] | ||
| mysql = ["sqlalchemy[asyncio,aiomysql]>=2.0.0"] | ||
| sqlite = ["sqlalchemy[asyncio,aiosqlite]>=2.0.0"] | ||
|
|
@@ -88,6 +86,9 @@ dev = [ | |
| "types-protobuf", | ||
| "types-requests", | ||
| "pre-commit", | ||
| "fastapi>=0.115.2", | ||
| "sse-starlette", | ||
| "starlette", | ||
| "pyupgrade", | ||
| "autoflake", | ||
| "no_implicit_optional", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| from typing import Any | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from a2a.server.apps.jsonrpc import fastapi_app | ||
| from a2a.server.apps.jsonrpc.fastapi_app import A2AFastAPIApplication | ||
| from a2a.server.request_handlers.request_handler import ( | ||
| RequestHandler, # For mock spec | ||
| ) | ||
| from a2a.types import AgentCard # For mock spec | ||
|
|
||
|
|
||
| # --- A2AFastAPIApplication Tests --- | ||
|
|
||
|
|
||
| class TestA2AFastAPIApplicationOptionalDeps: | ||
| # Running tests in this class requires the optional dependency fastapi to be | ||
| # present in the test environment. | ||
|
|
||
| @pytest.fixture(scope='class', autouse=True) | ||
| def ensure_pkg_fastapi_is_present(self): | ||
| try: | ||
| import fastapi as _fastapi # noqa: F401 | ||
| except ImportError: | ||
| pytest.fail( | ||
| f'Running tests in {self.__class__.__name__} requires' | ||
| ' the optional dependency fastapi to be present in the test' | ||
| ' environment. Run `uv sync --dev ...` before running the test' | ||
| ' suite.' | ||
| ) | ||
|
|
||
| @pytest.fixture(scope='class') | ||
| def mock_app_params(self) -> dict: | ||
| # Mock http_handler | ||
| mock_handler = MagicMock(spec=RequestHandler) | ||
| # Mock agent_card with essential attributes accessed in __init__ | ||
| mock_agent_card = MagicMock(spec=AgentCard) | ||
| # Ensure 'url' attribute exists on the mock_agent_card, as it's accessed | ||
| # in __init__ | ||
| mock_agent_card.url = 'http://example.com' | ||
| # Ensure 'supportsAuthenticatedExtendedCard' attribute exists | ||
| mock_agent_card.supportsAuthenticatedExtendedCard = False | ||
| return dict(agent_card=mock_agent_card, http_handler=mock_handler) | ||
|
|
||
| @pytest.fixture(scope='class') | ||
| def mark_pkg_fastapi_not_installed(self): | ||
| pkg_fastapi_installed_flag = fastapi_app._package_fastapi_installed | ||
| fastapi_app._package_fastapi_installed = False | ||
| yield | ||
| fastapi_app._package_fastapi_installed = pkg_fastapi_installed_flag | ||
|
|
||
| def test_create_a2a_fastapi_app_with_present_deps_succeeds( | ||
| self, mock_app_params: dict | ||
| ): | ||
| try: | ||
| _app = A2AFastAPIApplication(**mock_app_params) | ||
| except ImportError: | ||
| pytest.fail( | ||
| 'With the fastapi package present, creating a' | ||
| ' A2AFastAPIApplication instance should not raise ImportError' | ||
| ) | ||
|
|
||
| def test_create_a2a_fastapi_app_with_missing_deps_raises_importerror( | ||
| self, | ||
| mock_app_params: dict, | ||
| mark_pkg_fastapi_not_installed: Any, | ||
| ): | ||
| with pytest.raises( | ||
| ImportError, | ||
| match=( | ||
| 'The `fastapi` package is required to use the' | ||
| ' `A2AFastAPIApplication`' | ||
| ), | ||
| ): | ||
| _app = A2AFastAPIApplication(**mock_app_params) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| pytest.main([__file__]) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.