First pass at autodoc support (#464)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* First pass at autodoc support * Add mkautodoc requirement for docs builds * Linting * pip install httpx when building docs, to make it available to mkautodoc * Fix code example in docstring slightly * Use latest mkautodoc to resolve rendering of code snippets in docstrings * Fill in 'Helper functions' API docs * First pass at documenting Client * Add autodoc for Client * Update to mkautodoc 0.1 * Fix typos
authored by Tom Christie · committed by Florimond Manca · parent e3140a0 · Browse files · 6 files·+290 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+290 added−33 removed
- other:+290 added−33 removed
Provenance
- Commit
1ce3cc3- Tree
a9983f8- Author
Tom Christie <tom@tomchristie.com>- Committer
Florimond Manca <florimond.manca@gmail.com>- Parent
e3140a0
6 files changed+290 added−33 removed
added:docs/css/custom.css+10 added
12345678910div.autodoc-docstring { padding-left: 20px; margin-bottom: 30px; border-left: 5px solid rgba(230, 230, 230);}
div.autodoc-members { padding-left: 20px; margin-bottom: 15px;}modified:docs/api.md+25 added-30 removed
6 unmodified lines7891011121314151617181911121321141516231718192526272820212230313233343536373839404142434423242526272829303132333435363738394041424344114 unmodified linesExpand all6 unmodified lines or making a small number of requests. Using a `Client` will enable HTTP/2 and connection pooling for more efficient and long-lived connections.
* `get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `post(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `put(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `patch(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `delete(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `request(method, url, [data], [files], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `build_request(method, url, [data], [files], [json], [params], [headers], [cookies])`::: httpx.request :docstring:
## `Client`::: httpx.get :docstring:
*An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.*::: httpx.options :docstring:
```python>>> with httpx.Client() as client:... response = client.get('https://example.org')```::: httpx.head :docstring:
* `def __init__([auth], [params], [headers], [cookies], [verify], [cert], [timeout], [pool_limits], [max_redirects], [app], [dispatch])`* `.params` - **QueryParams*** `.headers` - **Headers*** `.cookies` - **Cookies*** `def .get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `def .options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `def .head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `def .post(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `def .put(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `def .patch(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `def .delete(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `def .request(method, url, [data], [files], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `def .build_request(method, url, [data], [files], [json], [params], [headers], [cookies])`* `def .send(request, [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`* `def .close()`::: httpx.post :docstring:
::: httpx.put :docstring:
::: httpx.patch :docstring:
::: httpx.delete :docstring:
## `Client`
::: httpx.Client :docstring: :members: headers cookies params request get head options post put patch delete build_request send close
## `Response`
*An HTTP response.*
114 unmodified linesExpand allmodified:httpx/api.py+94 added
30 unmodified lines31 verify: VerifyTypes = True,32 stream: bool = False,33 trust_env: bool = None,34 ) -> Response:35+ """36+ Sends an HTTP request.37+38+ **Parameters:**39+40+ * **method** - HTTP method for the new `Request` object: `GET`, `OPTIONS`,41+ `HEAD`, `POST`, `PUT`, `PATCH`, or `DELETE`.42+ * **url** - URL for the new `Request` object.43+ * **params** - *(optional)* Query parameters to include in the URL, as a44+ string, dictionary, or list of two-tuples.45+ * **data** - *(optional)* Data to include in the body of the request, as a46+ dictionary47+ * **files** - *(optional)* A dictionary of upload files to include in the48+ body of the request.49+ * **json** - *(optional)* A JSON serializable object to include in the body50+ of the request.51+ * **headers** - *(optional)* Dictionary of HTTP headers to include in the52+ request.53+ * **cookies** - *(optional)* Dictionary of Cookie items to include in the54+ request.55+ * **auth** - *(optional)* An authentication class to use when sending the56+ request.57+ * **timeout** - *(optional)* The timeout configuration to use when sending58+ the request.59+ * **allow_redirects** - *(optional)* Enables or disables HTTP redirects.60+ * **cert** - *(optional)* Either a path to an SSL certificate file, or61+ two-tuple of (certificate file, key file), or a three-tuple of (certificate62+ file, key file, password).63+ * **verify** - *(optional)* Enables or disables SSL verification.64+ * **trust_env** - *(optional)* Enables or disables usage of environment65+ variables for configuration.66+ * **proxies** - *(optional)* A dictionary mapping HTTP protocols to proxy67+ URLs.68+69+ **Returns:** `Response`70+71+ Usage:72+73+ ```74+ >>> import httpx75+ >>> response = httpx.request('GET', 'https://httpbin.org/get')76+ >>> response77+ <Response [200 OK]>78+ ```79+ """80 with Client(http_versions=["HTTP/1.1"]) as client:81 return client.request(82 method=method,83 url=url,26 unmodified lines110 verify: VerifyTypes = True,111 timeout: TimeoutTypes = None,112 trust_env: bool = None,113 ) -> Response:114+ """115+ Sends a `GET` request.116+117+ **Parameters**: See `httpx.request`.118+119+ Note that the `data`, `files`, and `json` parameters are not available on120+ this function, as `GET` requests should not include a request body.121+ """122 return request(123 "GET",124 url,125 params=params,22 unmodified lines148 verify: VerifyTypes = True,149 timeout: TimeoutTypes = None,150 trust_env: bool = None,151 ) -> Response:152+ """153+ Sends an `OPTIONS` request.154+155+ **Parameters**: See `httpx.request`.156+157+ Note that the `data`, `files`, and `json` parameters are not available on158+ this function, as `OPTIONS` requests should not include a request body.159+ """160 return request(161 "OPTIONS",162 url,163 params=params,22 unmodified lines186 verify: VerifyTypes = True,187 timeout: TimeoutTypes = None,188 trust_env: bool = None,189 ) -> Response:190+ """191+ Sends a `HEAD` request.192+193+ **Parameters**: See `httpx.request`.194+195+ Note that the `data`, `files`, and `json` parameters are not available on196+ this function, as `HEAD` requests should not include a request body. The197+ `HEAD` method also differs from the other cases in that `allow_redirects`198+ defaults to `False`.199+ """200 return request(201 "HEAD",202 url,203 params=params,25 unmodified lines229 verify: VerifyTypes = True,230 timeout: TimeoutTypes = None,231 trust_env: bool = None,232 ) -> Response:233+ """234+ Sends a `POST` request.235+236+ **Parameters**: See `httpx.request`.237+ """238 return request(239 "POST",240 url,241 data=data,28 unmodified lines270 verify: VerifyTypes = True,271 timeout: TimeoutTypes = None,272 trust_env: bool = None,273 ) -> Response:274+ """275+ Sends a `PUT` request.276+277+ **Parameters**: See `httpx.request`.278+ """279 return request(280 "PUT",281 url,282 data=data,28 unmodified lines311 verify: VerifyTypes = True,312 timeout: TimeoutTypes = None,313 trust_env: bool = None,314 ) -> Response:315+ """316+ Sends a `PATCH` request.317+318+ **Parameters**: See `httpx.request`.319+ """320 return request(321 "PATCH",322 url,323 data=data,25 unmodified lines349 verify: VerifyTypes = True,350 timeout: TimeoutTypes = None,351 trust_env: bool = None,352 ) -> Response:353+ """354+ Sends a `DELETE` request.355+356+ **Parameters**: See `httpx.request`.357+358+ Note that the `data`, `files`, and `json` parameters are not available on359+ this function, as `DELETE` requests should not include a request body.360+ """361 return request(362 "DELETE",363 url,364 params=params,10 unmodified linesmodified:httpx/client.py+155 added
133 unmodified lines134 )135 136 @property137 def headers(self) -> Headers:138+ """139+ HTTP headers to include when sending requests.140+ """141 return self._headers142 143 @headers.setter144 def headers(self, headers: HeaderTypes) -> None:145 self._headers = Headers(headers)146 147 @property148 def cookies(self) -> Cookies:149+ """150+ Cookie values to include when sending requests.151+ """152 return self._cookies153 154 @cookies.setter155 def cookies(self, cookies: CookieTypes) -> None:156 self._cookies = Cookies(cookies)157 158 @property159 def params(self) -> QueryParams:160+ """161+ Query parameters to include in the URL when sending requests.162+ """163 return self._params164 165 @params.setter166 def params(self, params: QueryParamTypes) -> None:170 unmodified lines337 params: QueryParamTypes = None,338 headers: HeaderTypes = None,339 cookies: CookieTypes = None,340 ) -> AsyncRequest:341+ """342+ Build and return a request instance.343+ """344 url = self.merge_url(url)345 headers = self.merge_headers(headers)346 cookies = self.merge_cookies(cookies)347 params = self.merge_queryparams(params)317 unmodified lines665 await self.close()666 667 668 class Client(BaseClient):669+ """670+ An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.671+672+ Usage:673+674+ ```675+ >>> client = httpx.Client()676+ >>> response = client.get('https://example.org')677+ ```678+679+ **Parameters:**680+681+ * **auth** - *(optional)* An authentication class to use when sending682+ requests.683+ * **params** - *(optional)* Query parameters to include in request URLs, as684+ a string, dictionary, or list of two-tuples.685+ * **headers** - *(optional)* Dictionary of HTTP headers to include when686+ sending requests.687+ * **cookies** - *(optional)* Dictionary of Cookie items to include when688+ sending requests.689+ * **verify** - *(optional)* Enables or disables SSL verification.690+ * **cert** - *(optional)* Either a path to an SSL certificate file, or691+ two-tuple of (certificate file, key file), or a three-tuple of (certificate692+ file, key file, password).693+ * **http_versions** - *(optional)* A list of strings of HTTP protocol694+ versions to use when sending requests. eg. `http_versions=["HTTP/1.1"]`695+ * **proxies** - *(optional)* A dictionary mapping HTTP protocols to proxy696+ URLs.697+ * **timeout** - *(optional)* The timeout configuration to use when sending698+ requests.699+ * **pool_limits** - *(optional)* The connection pool configuration to use700+ when determining the maximum number of concurrently open HTTP connections.701+ * **max_redirects** - *(optional)* The maximum number of redirect responses702+ that should be followed.703+ * **base_url** - *(optional)* A URL to use as the base when building704+ request URLs.705+ * **dispatch** - *(optional)* A dispatch class to use for sending requests706+ over the network.707+ * **app** - *(optional)* A WSGI or ASGI application to send requests to,708+ rather than sending actual network requests.709+ * **backend** - *(optional)* A concurrency backend to use when issuing710+ async requests.711+ * **trust_env** - *(optional)* Enables or disables usage of environment712+ variables for configuration.713+ """714+715 def check_concurrency_backend(self, backend: ConcurrencyBackend) -> None:716 # Iterating over response content allocates an async environment on each step.717 # This is relatively cheap on asyncio, but cannot be guaranteed for all718 # concurrency backends.53 unmodified lines772 verify: VerifyTypes = None,773 timeout: TimeoutTypes = None,774 trust_env: bool = None,775 ) -> Response:776+ """777+ Sends an HTTP request.778+779+ **Parameters:**780+781+ * **method** - HTTP method for the new `Request` object: `GET`, `OPTIONS`,782+ `HEAD`, `POST`, `PUT`, `PATCH`, or `DELETE`.783+ * **url** - URL for the new `Request` object.784+ * **data** - *(optional)* Data to include in the body of the request, as a785+ dictionary786+ * **files** - *(optional)* A dictionary of upload files to include in the787+ body of the request.788+ * **json** - *(optional)* A JSON serializable object to include in the body789+ of the request.790+ * **params** - *(optional)* Query parameters to include in the URL, as a791+ string, dictionary, or list of two-tuples.792+ * **headers** - *(optional)* Dictionary of HTTP headers to include on the793+ request.794+ * **cookies** - *(optional)* Dictionary of Cookie items to include in the795+ request.796+ * **stream** - *(optional)* Enable/disable streaming responses.797+ * **auth** - *(optional)* An authentication class to use when sending the798+ request.799+ * **allow_redirects** - *(optional)* Enables or disables HTTP redirects.800+ * **cert** - *(optional)* Either a path to an SSL certificate file, or801+ two-tuple of (certificate file, key file), or a three-tuple of (certificate802+ file, key file, password).803+ * **verify** - *(optional)* Enables or disables SSL verification.804+ * **timeout** - *(optional)* The timeout configuration to use when sending805+ the request.806+ * **trust_env** - *(optional)* Enables or disables usage of environment807+ variables for configuration.808+809+ **Returns:** `Response`810+811+ Usage:812+813+ ```814+ >>> import httpx815+ >>> client = httpx.Client()816+ >>> response = client.request('GET', 'https://httpbin.org/get')817+ >>> response818+ <Response [200 OK]>819+ ```820+ """821 request = self.build_request(822 method=method,823 url=url,824 data=self._async_request_data(data),25 unmodified lines850 cert: CertTypes = None,851 timeout: TimeoutTypes = None,852 trust_env: bool = None,853 ) -> Response:854+ """855+ Sends a request over the network, returning a response.856+ """857 concurrency_backend = self.concurrency_backend858 859 coroutine = self._get_response860 args = [request]49 unmodified lines910 verify: VerifyTypes = None,911 timeout: TimeoutTypes = None,912 trust_env: bool = None,913 ) -> Response:914+ """915+ Sends a `GET` request.916+917+ **Parameters**: See `Client.request`.918+919+ Note that the `data`, `files`, and `json` parameters are not available on920+ this function, as `GET` requests should not include a request body.921+ """922 return self.request(923 "GET",924 url,925 params=params,22 unmodified lines948 verify: VerifyTypes = None,949 timeout: TimeoutTypes = None,950 trust_env: bool = None,951 ) -> Response:952+ """953+ Sends an `OPTIONS` request.954+955+ **Parameters**: See `Client.request`.956+957+ Note that the `data`, `files`, and `json` parameters are not available on958+ this function, as `OPTIONS` requests should not include a request body.959+ """960 return self.request(961 "OPTIONS",962 url,963 params=params,22 unmodified lines986 verify: VerifyTypes = None,987 timeout: TimeoutTypes = None,988 trust_env: bool = None,989 ) -> Response:990+ """991+ Sends a `HEAD` request.992+993+ **Parameters**: See `Client.request`.994+995+ Note that the `data`, `files`, and `json` parameters are not available on996+ this function, as `HEAD` requests should not include a request body. The997+ `HEAD` method also differs from the other cases in that `allow_redirects`998+ defaults to `False`.999+ """1000 return self.request(1001 "HEAD",1002 url,1003 params=params,25 unmodified lines1029 verify: VerifyTypes = None,1030 timeout: TimeoutTypes = None,1031 trust_env: bool = None,1032 ) -> Response:1033+ """1034+ Sends a `POST` request.1035+1036+ **Parameters**: See `Client.request`.1037+ """1038 return self.request(1039 "POST",1040 url,1041 data=data,28 unmodified lines1070 verify: VerifyTypes = None,1071 timeout: TimeoutTypes = None,1072 trust_env: bool = None,1073 ) -> Response:1074+ """1075+ Sends a `PUT` request.1076+1077+ **Parameters**: See `Client.request`.1078+ """1079 return self.request(1080 "PUT",1081 url,1082 data=data,28 unmodified lines1111 verify: VerifyTypes = None,1112 timeout: TimeoutTypes = None,1113 trust_env: bool = None,1114 ) -> Response:1115+ """1116+ Sends a `PATCH` request.1117+1118+ **Parameters**: See `Client.request`.1119+ """1120 return self.request(1121 "PATCH",1122 url,1123 data=data,25 unmodified lines1149 verify: VerifyTypes = None,1150 timeout: TimeoutTypes = None,1151 trust_env: bool = None,1152 ) -> Response:1153+ """1154+ Sends a `DELETE` request.1155+1156+ **Parameters**: See `Client.request`.1157+ """1158 return self.request(1159 "DELETE",1160 url,1161 params=params,8 unmodified lines1170 trust_env=trust_env,1171 )1172 1173 def close(self) -> None:1174+ """1175+ Close any open connections in the connection pool.1176+ """1177 coroutine = self.dispatch.close1178 self.concurrency_backend.run(coroutine)1179 1180 def __enter__(self) -> "Client":51 unmodified linesmodified:mkdocs.yml+4 added-1 removed
20 unmodified lines21222324252526272820 unmodified lines
markdown_extensions: - admonition - codehilite - pymdownx.superfences - mkautodoc
extra_css: - css/custom.cssmodified:noxfile.py+2 added-2 removed
42 unmodified lines43 44 45 @nox.session46 def docs(session):47- session.install("--upgrade", "mkdocs", "mkdocs-material", "pymdown-extensions")48-47+ session.install("--upgrade", "mkdocs", "mkdocs-material", "mkautodoc>=0.1.0")48+ session.install("-e", ".")49 session.run("mkdocs", "build")50 51 52 @nox.session(reuse_venv=True)10 unmodified lines