Skip to content
Myr

api.py

This file

Path

httpcore/api.py

254 lines · 5.5 KiB · Python

Last changed by

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

History of this file

Take it

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 1–3why, one step back
1import typing
23from .client import Client

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

line 4why, one step back
4from .config import CertTypes, TimeoutTypes, VerifyTypes

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 5–10why, one step back
5from .models import (
6 AuthTypes,7 CookieTypes,8 HeaderTypes,9 QueryParamTypes,10 RequestData,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 11why, one step back
11 Response,

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 12–19why, one step back
12 URLTypes,
13)141516def request(17 method: str,18 url: URLTypes,19 *,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

line 20why, one step back
20 params: QueryParamTypes = None,

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 21–24why, one step back
21 data: RequestData = b"",
22 json: typing.Any = None,23 headers: HeaderTypes = None,24 cookies: CookieTypes = None,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

line 25why, one step back
25 # files

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

line 26why, one step back
26 auth: AuthTypes = None,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

line 27why, one step back
27 timeout: TimeoutTypes = None,

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

line 28why, one step back
28 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 29–32why, one step back
29 # proxies
30 cert: CertTypes = None,31 verify: VerifyTypes = True,32 stream: bool = False,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 33why, one step back
33) -> Response:

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 34–45why, one step back
34 with Client() as client:
35 return client.request(36 method=method,37 url=url,38 data=data,39 json=json,40 params=params,41 headers=headers,42 cookies=cookies,43 stream=stream,44 auth=auth,45 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 46–47why, one step back
46 cert=cert,
47 verify=verify,

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 48–60why, one step back
48 timeout=timeout,
49 )505152def get(53 url: URLTypes,54 *,55 params: QueryParamTypes = None,56 headers: HeaderTypes = None,57 cookies: CookieTypes = None,58 stream: bool = False,59 auth: AuthTypes = None,60 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 61–63why, one step back
61 cert: CertTypes = None,
62 verify: VerifyTypes = True,63 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 64why, one step back
64) -> Response:

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 65–72why, one step back
65 return request(
66 "GET",67 url,68 headers=headers,69 cookies=cookies,70 stream=stream,71 auth=auth,72 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 73–74why, one step back
73 cert=cert,
74 verify=verify,

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 75–87why, one step back
75 timeout=timeout,
76 )777879def options(80 url: URLTypes,81 *,82 params: QueryParamTypes = None,83 headers: HeaderTypes = None,84 cookies: CookieTypes = None,85 stream: bool = False,86 auth: AuthTypes = None,87 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 88–90why, one step back
88 cert: CertTypes = None,
89 verify: VerifyTypes = True,90 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 91why, one step back
91) -> Response:

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 92–99why, one step back
92 return request(
93 "OPTIONS",94 url,95 headers=headers,96 cookies=cookies,97 stream=stream,98 auth=auth,99 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 100–101why, one step back
100 cert=cert,
101 verify=verify,

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 102–114why, one step back
102 timeout=timeout,
103 )104105106def head(107 url: URLTypes,108 *,109 params: QueryParamTypes = None,110 headers: HeaderTypes = None,111 cookies: CookieTypes = None,112 stream: bool = False,113 auth: AuthTypes = None,114 allow_redirects: bool = False, #  Note: Differs to usual default.

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 115–117why, one step back
115 cert: CertTypes = None,
116 verify: VerifyTypes = True,117 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 118why, one step back
118) -> Response:

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 119–126why, one step back
119 return request(
120 "HEAD",121 url,122 headers=headers,123 cookies=cookies,124 stream=stream,125 auth=auth,126 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 127–128why, one step back
127 cert=cert,
128 verify=verify,

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 129–143why, one step back
129 timeout=timeout,
130 )131132133def post(134 url: URLTypes,135 *,136 data: RequestData = b"",137 json: typing.Any = None,138 params: QueryParamTypes = None,139 headers: HeaderTypes = None,140 cookies: CookieTypes = None,141 stream: bool = False,142 auth: AuthTypes = None,143 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 144–146why, one step back
144 cert: CertTypes = None,
145 verify: VerifyTypes = True,146 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 147why, one step back
147) -> Response:

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 148–157why, one step back
148 return request(
149 "POST",150 url,151 data=data,152 json=json,153 headers=headers,154 cookies=cookies,155 stream=stream,156 auth=auth,157 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 158–159why, one step back
158 cert=cert,
159 verify=verify,

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 160–174why, one step back
160 timeout=timeout,
161 )162163164def put(165 url: URLTypes,166 *,167 data: RequestData = b"",168 json: typing.Any = None,169 params: QueryParamTypes = None,170 headers: HeaderTypes = None,171 cookies: CookieTypes = None,172 stream: bool = False,173 auth: AuthTypes = None,174 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 175–177why, one step back
175 cert: CertTypes = None,
176 verify: VerifyTypes = True,177 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 178why, one step back
178) -> Response:

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 179–188why, one step back
179 return request(
180 "PUT",181 url,182 data=data,183 json=json,184 headers=headers,185 cookies=cookies,186 stream=stream,187 auth=auth,188 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 189–190why, one step back
189 cert=cert,
190 verify=verify,

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 191–205why, one step back
191 timeout=timeout,
192 )193194195def patch(196 url: URLTypes,197 *,198 data: RequestData = b"",199 json: typing.Any = None,200 params: QueryParamTypes = None,201 headers: HeaderTypes = None,202 cookies: CookieTypes = None,203 stream: bool = False,204 auth: AuthTypes = None,205 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 206–208why, one step back
206 cert: CertTypes = None,
207 verify: VerifyTypes = True,208 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 209why, one step back
209) -> Response:

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 210–219why, one step back
210 return request(
211 "PATCH",212 url,213 data=data,214 json=json,215 headers=headers,216 cookies=cookies,217 stream=stream,218 auth=auth,219 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 220–221why, one step back
220 cert=cert,
221 verify=verify,

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 222–236why, one step back
222 timeout=timeout,
223 )224225226def delete(227 url: URLTypes,228 *,229 data: RequestData = b"",230 json: typing.Any = None,231 params: QueryParamTypes = None,232 headers: HeaderTypes = None,233 cookies: CookieTypes = None,234 stream: bool = False,235 auth: AuthTypes = None,236 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 237–239why, one step back
237 cert: CertTypes = None,
238 verify: VerifyTypes = True,239 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 240why, one step back
240) -> Response:

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 241–250why, one step back
241 return request(
242 "DELETE",243 url,244 data=data,245 json=json,246 headers=headers,247 cookies=cookies,248 stream=stream,249 auth=auth,250 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 251–252why, one step back
251 cert=cert,
252 verify=verify,

Add top-level API (#75)Tom Christiebefore adoptionfc627f3

lines 253–254why, one step back
253 timeout=timeout,
254 )