Skip to content

Commit 85c4df4

Browse files
committed
Adjusting documentation
1 parent 318bd83 commit 85c4df4

File tree

7 files changed

+106
-157
lines changed

7 files changed

+106
-157
lines changed

.github/workflows/docs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
- name: Install dependencies
2525
run: pip install .[dev]
2626

27-
- name: Generate Sphinx HTML
28-
run: python -m sphinx -b html -W docs docs/_build
27+
- name: Run Sphinx doctest
28+
run: python -m sphinx -b doctest docs docs/_build

arangoasync/http.py

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,31 @@
1515

1616
class HTTPClient(ABC): # pragma: no cover
1717
"""Abstract base class for HTTP clients.
18+
1819
Custom HTTP clients should inherit from this class.
20+
21+
Example:
22+
.. code-block:: python
23+
24+
class MyCustomHTTPClient(HTTPClient):
25+
def create_session(self, host):
26+
pass
27+
async def send_request(self, session, request):
28+
pass
1929
"""
2030

2131
@abstractmethod
2232
def create_session(self, host: str) -> Any:
2333
"""Return a new session given the base host URL.
2434
25-
This method must be overridden by the user.
35+
Note:
36+
This method must be overridden by the user.
37+
38+
Args:
39+
host (str): ArangoDB host URL.
2640
27-
:param host: ArangoDB host URL.
28-
:type host: str
29-
:returns: Requests session object.
30-
:rtype: Any
41+
Returns:
42+
Requests session object.
3143
"""
3244
raise NotImplementedError
3345

@@ -39,37 +51,36 @@ async def send_request(
3951
) -> Response:
4052
"""Send an HTTP request.
4153
42-
This method must be overridden by the user.
54+
Note:
55+
This method must be overridden by the user.
4356
44-
:param session: Session object.
45-
:type session: Any
46-
:param request: HTTP request.
47-
:type request: arangoasync.request.Request
48-
:returns: HTTP response.
49-
:rtype: arangoasync.response.Response
57+
Args:
58+
session (Any): Client session object.
59+
request (Request): HTTP request.
60+
61+
Returns:
62+
Response: HTTP response.
5063
"""
5164
raise NotImplementedError
5265

5366

5467
class AioHTTPClient(HTTPClient):
55-
"""HTTP client implemented on top of [aiohttp](https://docs.aiohttp.org/en/stable/).
56-
57-
:param connector: Supports connection pooling.
58-
By default, 100 simultaneous connections are supported, with a 60-second timeout
59-
for connection reusing after release.
60-
:type connector: aiohttp.BaseConnector | None
61-
:param timeout: Timeout settings.
62-
300s total timeout by default for a complete request/response operation.
63-
:type timeout: aiohttp.ClientTimeout | None
64-
:param read_bufsize: Size of read buffer (64KB default).
65-
:type read_bufsize: int
66-
:param auth: HTTP authentication helper.
67-
Should be used for specifying authorization data in client API.
68-
:type auth: aiohttp.BasicAuth | None
69-
:param compression_threshold: Will compress requests to the server if
70-
the size of the request body (in bytes) is at least the value of this
71-
option.
72-
:type compression_threshold: int
68+
"""HTTP client implemented on top of aiohttp_.
69+
70+
Args:
71+
connector (aiohttp.BaseConnector | None): Supports connection pooling.
72+
By default, 100 simultaneous connections are supported, with a 60-second
73+
timeout for connection reusing after release.
74+
timeout (aiohttp.ClientTimeout | None): Client timeout settings.
75+
300s total timeout by default for a complete request/response operation.
76+
read_bufsize (int): Size of read buffer (64KB default).
77+
auth (aiohttp.BasicAuth | None): HTTP authentication helper.
78+
Should be used for specifying authorization data in client API.
79+
compression_threshold (int): Will compress requests to the server if the size
80+
of the request body (in bytes) is at least the value of this option.
81+
82+
.. _aiohttp:
83+
https://docs.aiohttp.org/en/stable/
7384
"""
7485

7586
def __init__(
@@ -95,11 +106,12 @@ def __init__(
95106
def create_session(self, host: str) -> ClientSession:
96107
"""Return a new session given the base host URL.
97108
98-
:param host: ArangoDB host URL. Typically, the address and port of a coordinator
99-
(e.g. "http://127.0.0.1:8529").
100-
:type host: str
101-
:returns: Session object.
102-
:rtype: aiohttp.ClientSession
109+
Args:
110+
host (str): ArangoDB host URL. Must not include any paths. Typically, this
111+
is the address and port of a coordinator (e.g. "http://127.0.0.1:8529").
112+
113+
Returns:
114+
aiohttp.ClientSession: Session object, used to send future requests.
103115
"""
104116
return ClientSession(
105117
base_url=host,
@@ -116,12 +128,12 @@ async def send_request(
116128
) -> Response:
117129
"""Send an HTTP request.
118130
119-
:param session: Session object.
120-
:type session: aiohttp.ClientSession
121-
:param request: HTTP request.
122-
:type request: arangoasync.request.Request
123-
:returns: HTTP response.
124-
:rtype: arangoasync.response.Response
131+
Args:
132+
session (aiohttp.ClientSession): Session object used to make the request.
133+
request (Request): HTTP request.
134+
135+
Returns:
136+
Response: HTTP response.
125137
"""
126138
method = request.method
127139
endpoint = request.endpoint

arangoasync/request.py

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
class Method(Enum):
14-
"""HTTP methods."""
14+
"""HTTP methods enum: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS"""
1515

1616
GET = auto()
1717
POST = auto()
@@ -25,31 +25,19 @@ class Method(Enum):
2525
class Request:
2626
"""HTTP request.
2727
28-
:param method: HTTP method.
29-
:type method: request.Method
30-
:param endpoint: API endpoint.
31-
:type endpoint: str
32-
:param headers: Request headers.
33-
:type headers: dict | None
34-
:param params: URL parameters.
35-
:type params: dict | None
36-
:param data: Request payload.
37-
:type data: Any
38-
:param deserialize: Whether the response body should be deserialized.
39-
:type deserialize: bool
40-
41-
:ivar method: HTTP method.
42-
:vartype method: request.Method
43-
:ivar endpoint: API endpoint, for example "_api/version".
44-
:vartype endpoint: str
45-
:ivar headers: Request headers.
46-
:vartype headers: dict | None
47-
:ivar params: URL (query) parameters.
48-
:vartype params: dict | None
49-
:ivar data: Request payload.
50-
:vartype data: Any
51-
:ivar deserialize: Whether the response body should be deserialized.
52-
:vartype deserialize: bool
28+
Args:
29+
method (Method): HTTP method.
30+
endpoint (str): API endpoint.
31+
headers (dict | None): Request headers.
32+
params (dict | None): URL parameters.
33+
data (str | None): Request payload.
34+
35+
Attributes:
36+
method (Method): HTTP method.
37+
endpoint (str): API endpoint.
38+
headers (dict | None): Request headers.
39+
params (dict | None): URL parameters.
40+
data (str | None): Request payload.
5341
"""
5442

5543
__slots__ = (
@@ -58,7 +46,6 @@ class Request:
5846
"headers",
5947
"params",
6048
"data",
61-
"deserialize",
6249
)
6350

6451
def __init__(
@@ -68,23 +55,22 @@ def __init__(
6855
headers: Optional[Headers] = None,
6956
params: Optional[Params] = None,
7057
data: Optional[str] = None,
71-
deserialize: bool = True,
7258
) -> None:
7359
self.method: Method = method
7460
self.endpoint: str = endpoint
7561
self.headers: Headers = self._normalize_headers(headers)
7662
self.params: Params = self._normalize_params(params)
7763
self.data: Optional[str] = data
78-
self.deserialize: bool = deserialize
7964

8065
@staticmethod
8166
def _normalize_headers(headers: Optional[Headers]) -> Headers:
8267
"""Normalize request headers.
8368
84-
:param headers: Request headers.
85-
:type headers: dict | None
86-
:returns: Normalized request headers.
87-
:rtype: dict
69+
Parameters:
70+
headers (dict | None): Request headers.
71+
72+
Returns:
73+
dict: Normalized request headers.
8874
"""
8975
driver_header = f"arangoasync/{__version__}"
9076
normalized_headers: Headers = {
@@ -103,10 +89,11 @@ def _normalize_headers(headers: Optional[Headers]) -> Headers:
10389
def _normalize_params(params: Optional[Params]) -> Params:
10490
"""Normalize URL parameters.
10591
106-
:param params: URL parameters.
107-
:type params: dict | None
108-
:returns: Normalized URL parameters.
109-
:rtype: dict
92+
Parameters:
93+
params (dict | None): URL parameters.
94+
95+
Returns:
96+
dict: Normalized URL parameters.
11097
"""
11198
normalized_params: Params = {}
11299

arangoasync/response.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,24 @@
1111
class Response:
1212
"""HTTP response.
1313
14-
:param method: HTTP method.
15-
:type method: request.Method
16-
:param url: API URL.
17-
:type url: str
18-
:param headers: Response headers.
19-
:type headers: dict | None
20-
:param status_code: Response status code.
21-
:type status_code: int
22-
:param status_text: Response status text.
23-
:type status_text: str
24-
:param raw_body: Raw response body.
25-
:type raw_body: str
14+
Parameters:
15+
method (Method): HTTP method.
16+
url (str): API URL.
17+
headers (dict | None): Response headers.
18+
status_code (int): Response status code.
19+
status_text (str): Response status text.
20+
raw_body (bytes): Raw response body.
2621
27-
:ivar method: HTTP method.
28-
:vartype method: request.Method
29-
:ivar url: API URL.
30-
:vartype url: str
31-
:ivar headers: Response headers.
32-
:vartype headers: dict | None
33-
:ivar status_code: Response status code.
34-
:vartype status_code: int
35-
:ivar status_text: Response status text.
36-
:vartype status_text: str
37-
:ivar raw_body: Raw response body.
38-
:vartype raw_body: str
39-
:ivar body: Response body after processing.
40-
:vartype body: Any
41-
:ivar error_code: Error code from ArangoDB server.
42-
:vartype error_code: int
43-
:ivar error_message: Error message from ArangoDB server.
44-
:vartype error_message: str
45-
:ivar is_success: True if response status code was 2XX.
46-
:vartype is_success: bool
22+
Attributes:
23+
method (Method): HTTP method.
24+
url (str): API URL.
25+
headers (dict | None): Response headers.
26+
status_code (int): Response status code.
27+
status_text (str): Response status text.
28+
raw_body (bytes): Raw response body.
29+
error_code (int | None): Error code from ArangoDB server.
30+
error_message (str | None): Error message from ArangoDB server.
31+
is_success (bool | None): True if response status code was 2XX.
4732
"""
4833

4934
__slots__ = (
@@ -52,7 +37,6 @@ class Response:
5237
"headers",
5338
"status_code",
5439
"status_text",
55-
"body",
5640
"raw_body",
5741
"error_code",
5842
"error_message",
@@ -76,7 +60,6 @@ def __init__(
7660
self.raw_body: bytes = raw_body
7761

7862
# Populated later
79-
self.body: Optional[str] = None
8063
self.error_code: Optional[int] = None
8164
self.error_message: Optional[str] = None
8265
self.is_success: Optional[bool] = None

docs/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
"sphinx.ext.autodoc",
1313
"sphinx.ext.doctest",
1414
"sphinx.ext.viewcode",
15+
"sphinx.ext.napoleon",
1516
"sphinx.ext.intersphinx",
1617
]
1718
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
1819
html_theme = "sphinx_rtd_theme"
1920
master_doc = "index"
2021

2122
autodoc_member_order = "bysource"
23+
autodoc_typehints = "none"
2224

2325
intersphinx_mapping = {
2426
"aiohttp": ("https://docs.aiohttp.org/en/stable/", None),
2527
}
28+
29+
napoleon_google_docstring = True
30+
napoleon_numpy_docstring = False
31+
napoleon_attr_annotations = True

docs/specs.rst

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,11 @@ API Specification
44
This page contains the specification for all classes and methods available in
55
python-arango-async.
66

7-
.. _AioHTTPClient:
8-
9-
AioHTTPClient
10-
=================
11-
12-
.. autoclass:: arangoasync.http.AioHTTPClient
13-
:members:
14-
15-
.. _DefaultHTTPClient:
16-
17-
DefaultHTTPClient
18-
=================
19-
20-
.. autoclass:: arangoasync.http.DefaultHTTPClient
21-
:members:
22-
23-
.. _HTTPClient:
24-
25-
HTTPClient
26-
==========
27-
28-
.. autoclass:: arangoasync.http.HTTPClient
7+
.. automodule:: arangoasync.http
298
:members:
309

31-
.. _Method:
32-
33-
Method
34-
=======
35-
36-
.. autoclass:: arangoasync.request.Method
10+
.. automodule:: arangoasync.request
3711
:members:
3812

39-
.. _Request:
40-
41-
Request
42-
=======
43-
44-
.. autoclass:: arangoasync.request.Request
45-
:members:
46-
47-
.. _Response:
48-
49-
Response
50-
========
51-
52-
.. autoclass:: arangoasync.response.Response
13+
.. automodule:: arangoasync.response
5314
:members:

0 commit comments

Comments
 (0)