Skip to content
Myr

api.md

This file

Path

docs/api.md

163 lines · 6.0 KiB · Markdown

Last changed by

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

History of this file

Take it

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 1–2why, one step back
1# Developer Interface
2

Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6

line 3why, one step back
3## Helper Functions

http3 (#86)Tom Christiebefore adoptionc9747aa

line 4why, one step back
4

Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6

lines 5–10why, one step back
5!!! note
6 Only use these functions if you're testing HTTPX in a console7 or making a small number of requests. Using a `Client` will8 enable HTTP/2 and connection pooling for more efficient and9 long-lived connections.10

Configure Proxy from Client (#353)Seth Michael Larsonbefore adoptionb0fa085

lines 11–18why, one step back
11* `get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`
12* `options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`13* `head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`14* `post(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`15* `put(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`16* `patch(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`17* `delete(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`18* `request(method, url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`

Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac

line 19why, one step back
19* `build_request(method, url, [data], [files], [json], [params], [headers], [cookies])`

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 20–22why, one step back
20
21## `Client`22

Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6

line 23why, one step back
23*An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.*

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 24–25why, one step back
24
25```python

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 26why, one step back
26>>> client = httpx.Client()

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 27–29why, one step back
27>>> response = client.get('https://example.org')
28```29

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 30–31why, one step back
30* `def __init__([auth], [params], [headers], [cookies], [verify], [cert], [timeout], [pool_limits], [max_redirects], [app], [dispatch])`
31* `.params` - **QueryParams**

Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5

lines 32–33why, one step back
32* `.headers` - **Headers**
33* `.cookies` - **Cookies**

Configure Proxy from Client (#353)Seth Michael Larsonbefore adoptionb0fa085

lines 34–41why, one step back
34* `def .get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`
35* `def .options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`36* `def .head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`37* `def .post(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`38* `def .put(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`39* `def .patch(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`40* `def .delete(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`41* `def .request(method, url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`

Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac

line 42why, one step back
42* `def .build_request(method, url, [data], [files], [json], [params], [headers], [cookies])`

Configure Proxy from Client (#353)Seth Michael Larsonbefore adoptionb0fa085

line 43why, one step back
43* `def .send(request, [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 44–50why, one step back
44* `def .close()`
4546## `Response`4748*An HTTP response.*4950* `def __init__(...)`

Int status codes (#92)Tom Christiebefore adoption56a7943

line 51why, one step back
51* `.status_code` - **int**

http3 (#86)Tom Christiebefore adoptionc9747aa

line 52why, one step back
52* `.reason_phrase` - **str**

Response.protocol -> Response.http_version (#250)Tom Christiebefore adoptionc1ec1c3

line 53why, one step back
53* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"`

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 54–62why, one step back
54* `.url` - **URL**
55* `.headers` - **Headers**56* `.content` - **bytes**57* `.text` - **str**58* `.encoding` - **str**59* `.is_redirect` - **bool**60* `.request` - **Request**61* `.cookies` - **Cookies**62* `.history` - **List[Response]**

Add `.elapsed` onto Response objects tracking how long a request took. (#351)Roy Williamsbefore adoption05ac117

lines 63–67why, one step back
63* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**
64 * The amount of time elapsed between sending the first byte and parsing the headers (not including time spent reading65 the response). Use66 [total_seconds()](https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds) to correctly get67 the total elapsed seconds.

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 68–81why, one step back
68* `def .raise_for_status()` - **None**
69* `def .json()` - **Any**70* `def .read()` - **bytes**71* `def .stream()` - **bytes iterator**72* `def .raw()` - **bytes iterator**73* `def .close()` - **None**74* `def .next()` - **Response**7576## `Request`7778*An HTTP request. Can be constructed explicitly for more control over exactly79what gets sent over the wire.*8081```python

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 82why, one step back
82>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 83–128why, one step back
83>>> response = client.send(request)
84```8586* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`87* `.method` - **str**88* `.url` - **URL**89* `.content` - **byte** or **byte async iterator**90* `.headers` - **Headers**91* `.cookies` - **Cookies**9293## `URL`9495*A normalized, IDNA supporting URL.*9697```python98>>> url = URL("https://example.org/")99>>> url.host100'example.org'101```102103* `def __init__(url, allow_relative=False, params=None)`104* `.scheme` - **str**105* `.authority` - **str**106* `.host` - **str**107* `.port` - **int**108* `.path` - **str**109* `.query` - **str**110* `.full_path` - **str**111* `.fragment` - **str**112* `.is_ssl` - **bool**113* `.origin` - **Origin**114* `.is_absolute_url` - **bool**115* `.is_relative_url` - **bool**116* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**117* `def .resolve_with(url)` - **URL**118119## `Origin`120121*A normalized, IDNA supporting set of scheme/host/port info.*122123```python124>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')125True126```127128* `def __init__(url)`

Make Origin use scheme, not is_ssl (#168)Stephen Brown IIbefore adoption44beaa1

line 129why, one step back
129* `.scheme` - **str**

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 130–163why, one step back
130* `.is_ssl` - **bool**
131* `.host` - **str**132* `.port` - **int**133134## `Headers`135136*A case-insensitive multi-dict.*137138```python139>>> headers = Headers({'Content-Type': 'application/json'})140>>> headers['content-type']141'application/json'142```143144* `def __init__(self, headers)`145146## `Cookies`147148*A dict-like cookie store.*149150```python151>>> cookies = Cookies()152>>> cookies.set("name", "value", domain="example.org")153```154155* `def __init__(cookies: [dict, Cookies, CookieJar])`156* `.jar` - **CookieJar**157* `def extract_cookies(response)`158* `def set_cookie_header(request)`159* `def set(name, value, [domain], [path])`160* `def get(name, [domain], [path])`161* `def delete(name, [domain], [path])`162* `def clear([domain], [path])`163* *Standard mutable mapping interface*