Skip to content
Myr

api.md

This file

Path

docs/api.md

162 lines · 6.0 KiB · Markdown

Last changed by

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

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

Allow setting headers at the Client level (#159)Stephen Brown IIbefore adoption72e6f47

line 30why, one step back
30* `def __init__([auth], [headers], [cookies], [verify], [cert], [timeout], [pool_limits], [max_redirects], [app], [dispatch])`

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

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

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

lines 33–40why, one step back
33* `def .get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`
34* `def .options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`35* `def .head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`36* `def .post(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`37* `def .put(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`38* `def .patch(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`39* `def .delete(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`40* `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 41why, one step back
41* `def .build_request(method, url, [data], [files], [json], [params], [headers], [cookies])`

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 43–49why, one step back
43* `def .close()`
4445## `Response`4647*An HTTP response.*4849* `def __init__(...)`

Int status codes (#92)Tom Christiebefore adoption56a7943

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

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 82–127why, one step back
82>>> response = client.send(request)
83```8485* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`86* `.method` - **str**87* `.url` - **URL**88* `.content` - **byte** or **byte async iterator**89* `.headers` - **Headers**90* `.cookies` - **Cookies**9192## `URL`9394*A normalized, IDNA supporting URL.*9596```python97>>> url = URL("https://example.org/")98>>> url.host99'example.org'100```101102* `def __init__(url, allow_relative=False, params=None)`103* `.scheme` - **str**104* `.authority` - **str**105* `.host` - **str**106* `.port` - **int**107* `.path` - **str**108* `.query` - **str**109* `.full_path` - **str**110* `.fragment` - **str**111* `.is_ssl` - **bool**112* `.origin` - **Origin**113* `.is_absolute_url` - **bool**114* `.is_relative_url` - **bool**115* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**116* `def .resolve_with(url)` - **URL**117118## `Origin`119120*A normalized, IDNA supporting set of scheme/host/port info.*121122```python123>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')124True125```126127* `def __init__(url)`

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 129–162why, one step back
129* `.is_ssl` - **bool**
130* `.host` - **str**131* `.port` - **int**132133## `Headers`134135*A case-insensitive multi-dict.*136137```python138>>> headers = Headers({'Content-Type': 'application/json'})139>>> headers['content-type']140'application/json'141```142143* `def __init__(self, headers)`144145## `Cookies`146147*A dict-like cookie store.*148149```python150>>> cookies = Cookies()151>>> cookies.set("name", "value", domain="example.org")152```153154* `def __init__(cookies: [dict, Cookies, CookieJar])`155* `.jar` - **CookieJar**156* `def extract_cookies(response)`157* `def set_cookie_header(request)`158* `def set(name, value, [domain], [path])`159* `def get(name, [domain], [path])`160* `def delete(name, [domain], [path])`161* `def clear([domain], [path])`162* *Standard mutable mapping interface*