Skip to content

Commit 2cf402c

Browse files
committed
Update messaging/typing/comments
1 parent 1d06e63 commit 2cf402c

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,23 @@ If you prefer to use pip, the standard Python package installer, you can install
4040
pip install a2a-sdk
4141
```
4242

43-
### Optional
43+
### Optional Dependencies
4444

4545
#### FastAPI-based A2A Server App
4646

47-
Using `a2a.server.apps.A2AFastAPIApplication` requires the FastAPI package, which is an optional dependency.
48-
With `uv`, it can be specified as follows:
47+
If you plan to build a server application using the `A2AFastAPIApplication` helper, you will need to install the `fastapi` package. This is an optional dependency.
48+
49+
You can install it with the `fastapi` extra:
4950

5051
```shell
52+
# Using uv
5153
uv add a2a-sdk[fastapi]
54+
55+
# Using pip
56+
pip install "a2a-sdk[fastapi]"
5257
```
5358

54-
Alternatively, a preferred version of the `fastapi` package can be added directly to the project:
59+
Alternatively, if you manage your dependencies separately, you can add `fastapi` to your project directly:
5560

5661
```shell
5762
uv add fastapi
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
"""Helper functions for handling optional FastAPI package imports."""
22

3-
try:
3+
import sys
4+
5+
6+
_FASTAPI_INSTALLED = 'fastapi' in sys.modules
7+
8+
if _FASTAPI_INSTALLED:
49
from fastapi import FastAPI, Request, Response
5-
except ImportError:
10+
else:
611
_FASTAPI_DEPENDENCY_ERROR_MSG = """
712
The A2A Python SDK FastAPI app requires the FastAPI package, which
813
is an optional dependency. To fix this issue, please add the fastapi
@@ -15,18 +20,18 @@
1520
uv add a2a-sdk[fastapi]
1621
"""
1722

18-
class _DummyFastAPIClasses:
19-
"""Parent class for dummy fastapi.* class declarations."""
23+
class _OptionalDependencyPlaceholder:
24+
"""Base class for placeholder fastapi.* declarations."""
2025

21-
def __init__(self) -> None:
22-
"""Raises ImportError when initiating a dummy fastapi.* instance."""
26+
def __init__(self, *args, **kwargs):
27+
"""Raises ImportError when an instance is created."""
2328
raise ImportError(_FASTAPI_DEPENDENCY_ERROR_MSG)
2429

25-
class FastAPI(_DummyFastAPIClasses): # type: ignore[no-redef]
26-
"""A dummy fastapi.FastAPI declaration."""
30+
class FastAPI(_OptionalDependencyPlaceholder):
31+
"""A placeholder for fastapi.FastAPI."""
2732

28-
class Request(_DummyFastAPIClasses): # type: ignore[no-redef]
29-
"""A dummy fastapi.Request declaration."""
33+
class Request(_OptionalDependencyPlaceholder):
34+
"""A placeholder for fastapi.Request."""
3035

31-
class Response(_DummyFastAPIClasses): # type: ignore[no-redef]
32-
"""A dummy fastapi.Response declaration."""
36+
class Response(_OptionalDependencyPlaceholder):
37+
"""A placeholder for fastapi.Response."""

0 commit comments

Comments
 (0)