Skip to content
Myr

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

6 files+290 added−33 removed

added:docs/css/custom.css+10 added
modified:docs/api.md+25 added-30 removed
modified:httpx/api.py+94 added
30 unmodified lines
31 verify: VerifyTypes = True,32 stream: bool = False,33 trust_env: bool = None,34) -> Response:35 """36 Sends an HTTP request.3738 **Parameters:**3940 * **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.6869 **Returns:** `Response`7071 Usage:7273 ```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 lines
110 verify: VerifyTypes = True,111 timeout: TimeoutTypes = None,112 trust_env: bool = None,113) -> Response:114 """115 Sends a `GET` request.116117 **Parameters**: See `httpx.request`.118119 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 lines
148 verify: VerifyTypes = True,149 timeout: TimeoutTypes = None,150 trust_env: bool = None,151) -> Response:152 """153 Sends an `OPTIONS` request.154155 **Parameters**: See `httpx.request`.156157 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 lines
186 verify: VerifyTypes = True,187 timeout: TimeoutTypes = None,188 trust_env: bool = None,189) -> Response:190 """191 Sends a `HEAD` request.192193 **Parameters**: See `httpx.request`.194195 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 lines
229 verify: VerifyTypes = True,230 timeout: TimeoutTypes = None,231 trust_env: bool = None,232) -> Response:233 """234 Sends a `POST` request.235236 **Parameters**: See `httpx.request`.237 """238 return request(239 "POST",240 url,241 data=data,
28 unmodified lines
270 verify: VerifyTypes = True,271 timeout: TimeoutTypes = None,272 trust_env: bool = None,273) -> Response:274 """275 Sends a `PUT` request.276277 **Parameters**: See `httpx.request`.278 """279 return request(280 "PUT",281 url,282 data=data,
28 unmodified lines
311 verify: VerifyTypes = True,312 timeout: TimeoutTypes = None,313 trust_env: bool = None,314) -> Response:315 """316 Sends a `PATCH` request.317318 **Parameters**: See `httpx.request`.319 """320 return request(321 "PATCH",322 url,323 data=data,
25 unmodified lines
349 verify: VerifyTypes = True,350 timeout: TimeoutTypes = None,351 trust_env: bool = None,352) -> Response:353 """354 Sends a `DELETE` request.355356 **Parameters**: See `httpx.request`.357358 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 lines
modified:httpx/client.py+155 added
133 unmodified lines
134 )135136 @property137 def headers(self) -> Headers:138 """139 HTTP headers to include when sending requests.140 """141 return self._headers142143 @headers.setter144 def headers(self, headers: HeaderTypes) -> None:145 self._headers = Headers(headers)146147 @property148 def cookies(self) -> Cookies:149 """150 Cookie values to include when sending requests.151 """152 return self._cookies153154 @cookies.setter155 def cookies(self, cookies: CookieTypes) -> None:156 self._cookies = Cookies(cookies)157158 @property159 def params(self) -> QueryParams:160 """161 Query parameters to include in the URL when sending requests.162 """163 return self._params164165 @params.setter166 def params(self, params: QueryParamTypes) -> None:
170 unmodified lines
337 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 lines
665 await self.close()666667668class Client(BaseClient):669 """670 An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.671672 Usage:673674 ```675 >>> client = httpx.Client()676 >>> response = client.get('https://example.org')677 ```678679 **Parameters:**680681 * **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 """714715 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 lines
772 verify: VerifyTypes = None,773 timeout: TimeoutTypes = None,774 trust_env: bool = None,775 ) -> Response:776 """777 Sends an HTTP request.778779 **Parameters:**780781 * **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.808809 **Returns:** `Response`810811 Usage:812813 ```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 lines
850 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_backend858859 coroutine = self._get_response860 args = [request]
49 unmodified lines
910 verify: VerifyTypes = None,911 timeout: TimeoutTypes = None,912 trust_env: bool = None,913 ) -> Response:914 """915 Sends a `GET` request.916917 **Parameters**: See `Client.request`.918919 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 lines
948 verify: VerifyTypes = None,949 timeout: TimeoutTypes = None,950 trust_env: bool = None,951 ) -> Response:952 """953 Sends an `OPTIONS` request.954955 **Parameters**: See `Client.request`.956957 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 lines
986 verify: VerifyTypes = None,987 timeout: TimeoutTypes = None,988 trust_env: bool = None,989 ) -> Response:990 """991 Sends a `HEAD` request.992993 **Parameters**: See `Client.request`.994995 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 lines
1029 verify: VerifyTypes = None,1030 timeout: TimeoutTypes = None,1031 trust_env: bool = None,1032 ) -> Response:1033 """1034 Sends a `POST` request.10351036 **Parameters**: See `Client.request`.1037 """1038 return self.request(1039 "POST",1040 url,1041 data=data,
28 unmodified lines
1070 verify: VerifyTypes = None,1071 timeout: TimeoutTypes = None,1072 trust_env: bool = None,1073 ) -> Response:1074 """1075 Sends a `PUT` request.10761077 **Parameters**: See `Client.request`.1078 """1079 return self.request(1080 "PUT",1081 url,1082 data=data,
28 unmodified lines
1111 verify: VerifyTypes = None,1112 timeout: TimeoutTypes = None,1113 trust_env: bool = None,1114 ) -> Response:1115 """1116 Sends a `PATCH` request.11171118 **Parameters**: See `Client.request`.1119 """1120 return self.request(1121 "PATCH",1122 url,1123 data=data,
25 unmodified lines
1149 verify: VerifyTypes = None,1150 timeout: TimeoutTypes = None,1151 trust_env: bool = None,1152 ) -> Response:1153 """1154 Sends a `DELETE` request.11551156 **Parameters**: See `Client.request`.1157 """1158 return self.request(1159 "DELETE",1160 url,1161 params=params,
8 unmodified lines
1170 trust_env=trust_env,1171 )11721173 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)11791180 def __enter__(self) -> "Client":
51 unmodified lines
modified:mkdocs.yml+4 added-1 removed
modified:noxfile.py+2 added-2 removed
42 unmodified lines
434445@nox.session46def docs(session):47 session.install("--upgrade", "mkdocs", "mkdocs-material", "pymdown-extensions")4847 session.install("--upgrade", "mkdocs", "mkdocs-material", "mkautodoc>=0.1.0")48 session.install("-e", ".")49 session.run("mkdocs", "build")505152@nox.session(reuse_venv=True)
10 unmodified lines