Skip to content
Myr

api.md

This file

Path

docs/api.md

166 lines · 4.0 KiB · Markdown

Last changed by

Document that iter_* methods are synchronous (#807)Colin Bounouarbefore adoptioncfe2278

History of this file

Take it

The walk stopped after 200 commits: lines older than 57ae7ea point at it.

Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea

lines 1–10why, one step back
1# Developer Interface
23## Helper Functions45!!! note6 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

First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3

lines 11–12why, one step back
11::: httpx.request
12 :docstring:

Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea

line 13why, one step back
13

First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3

lines 14–15why, one step back
14::: httpx.get
15 :docstring:

Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea

line 16why, one step back
16

First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3

lines 17–18why, one step back
17::: httpx.options
18 :docstring:

Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea

line 19why, one step back
19

First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3

lines 20–21why, one step back
20::: httpx.head
21 :docstring:

Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea

line 22why, one step back
22

First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3

lines 23–34why, one step back
23::: httpx.post
24 :docstring:2526::: httpx.put27 :docstring:2829::: httpx.patch30 :docstring:3132::: httpx.delete33 :docstring:34

Proposed 0.11 docs (#727)Tom Christiebefore adoption2038919

line 35why, one step back
35## `Client`

First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3

line 36why, one step back
36

Proposed 0.11 docs (#727)Tom Christiebefore adoption2038919

line 37why, one step back
37::: httpx.Client

First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3

line 38why, one step back
38 :docstring:

Proposed 0.11 docs (#727)Tom Christiebefore adoption2038919

line 39why, one step back
39 :members: headers cookies params request get head options post put patch delete build_request send close

Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea

lines 40–58why, one step back
40
41## `Response`4243*An HTTP response.*4445* `def __init__(...)`46* `.status_code` - **int**47* `.reason_phrase` - **str**48* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"`49* `.url` - **URL**50* `.headers` - **Headers**51* `.content` - **bytes**52* `.text` - **str**53* `.encoding` - **str**54* `.is_redirect` - **bool**55* `.request` - **Request**56* `.cookies` - **Cookies**57* `.history` - **List[Response]**58* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**

response.elapsed now reflects entire request/response time. (#692)Tom Christiebefore adoption6a1ee0e

line 59why, one step back
59 * The amount of time elapsed between sending the request and calling `close()` on the corresponding response received for that request.

Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea

lines 60–63why, one step back
60 [total_seconds()](https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds) to correctly get
61 the total elapsed seconds.62* `def .raise_for_status()` - **None**63* `def .json()` - **Any**

Proposed 0.11 docs (#727)Tom Christiebefore adoption2038919

line 64why, one step back
64* `def .read()` - **bytes**

Document that iter_* methods are synchronous (#807)Colin Bounouarbefore adoptioncfe2278

lines 65–68why, one step back
65* `def .iter_raw()` - **bytes iterator**
66* `def .iter_bytes()` - **bytes iterator**67* `def .iter_text()` - **text iterator**68* `def .iter_lines()` - **text iterator**

Proposed 0.11 docs (#727)Tom Christiebefore adoption2038919

lines 69–70why, one step back
69* `def .close()` - **None**
70* `def .next()` - **Response**

Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8

line 71why, one step back
71* `def .aread()` - **bytes**

Fix out-of-date methods on Response API docs (#673)Florimond Mancabefore adoptione30ec85

lines 72–75why, one step back
72* `def .aiter_raw()` - **async bytes iterator**
73* `def .aiter_bytes()` - **async bytes iterator**74* `def .aiter_text()` - **async text iterator**75* `def .aiter_lines()` - **async text iterator**

Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8

line 76why, one step back
76* `def .aclose()` - **None**

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

line 77why, one step back
77* `def .anext()` - **Response**

Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea

lines 78–85why, one step back
78
79## `Request`8081*An HTTP request. Can be constructed explicitly for more control over exactly82what gets sent over the wire.*8384```python85>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})

Proposed 0.11 docs (#727)Tom Christiebefore adoption2038919

line 86why, one step back
86>>> response = client.send(request)

Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea

lines 87–91why, one step back
87```
8889* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`90* `.method` - **str**91* `.url` - **URL**

Proposed 0.11 docs (#727)Tom Christiebefore adoption2038919

line 92why, one step back
92* `.content` - **byte**, **byte iterator**, or **byte async iterator**

Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea

lines 93–166why, one step back
93* `.headers` - **Headers**
94* `.cookies` - **Cookies**9596## `URL`9798*A normalized, IDNA supporting URL.*99100```python101>>> url = URL("https://example.org/")102>>> url.host103'example.org'104```105106* `def __init__(url, allow_relative=False, params=None)`107* `.scheme` - **str**108* `.authority` - **str**109* `.host` - **str**110* `.port` - **int**111* `.path` - **str**112* `.query` - **str**113* `.full_path` - **str**114* `.fragment` - **str**115* `.is_ssl` - **bool**116* `.origin` - **Origin**117* `.is_absolute_url` - **bool**118* `.is_relative_url` - **bool**119* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**120* `def .resolve_with(url)` - **URL**121122## `Origin`123124*A normalized, IDNA supporting set of scheme/host/port info.*125126```python127>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')128True129```130131* `def __init__(url)`132* `.scheme` - **str**133* `.is_ssl` - **bool**134* `.host` - **str**135* `.port` - **int**136137## `Headers`138139*A case-insensitive multi-dict.*140141```python142>>> headers = Headers({'Content-Type': 'application/json'})143>>> headers['content-type']144'application/json'145```146147* `def __init__(self, headers)`148149## `Cookies`150151*A dict-like cookie store.*152153```python154>>> cookies = Cookies()155>>> cookies.set("name", "value", domain="example.org")156```157158* `def __init__(cookies: [dict, Cookies, CookieJar])`159* `.jar` - **CookieJar**160* `def extract_cookies(response)`161* `def set_cookie_header(request)`162* `def set(name, value, [domain], [path])`163* `def get(name, [domain], [path])`164* `def delete(name, [domain], [path])`165* `def clear([domain], [path])`166* *Standard mutable mapping interface*