Skip to content
Myr

api.md

This file

Path

docs/api.md

157 lines · 3.9 KiB · Markdown

Last changed by

Use pycon for Python console code blocks (#1187)Hugo van Kemenadebefore adoptiond10b7cd

History of this file

Take it

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

Fix repo URLTom Christiebefore adoptiond515e4b

lines 1–38why, 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.1011::: httpx.request12 :docstring:1314::: httpx.get15 :docstring:1617::: httpx.options18 :docstring:1920::: httpx.head21 :docstring:2223::: httpx.post24 :docstring:2526::: httpx.put27 :docstring:2829::: httpx.patch30 :docstring:3132::: httpx.delete33 :docstring:3435## `Client`3637::: httpx.Client38 :docstring:

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

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

Fix repo URLTom Christiebefore adoptiond515e4b

line 40why, one step back
40

Fix Client Docstring and add AsyncClient to API docs (#883)Ed Singletonbefore adoptionfc980e7

lines 41–44why, one step back
41## `AsyncClient`
4243::: httpx.AsyncClient44 :docstring:

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

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

Fix Client Docstring and add AsyncClient to API docs (#883)Ed Singletonbefore adoptionfc980e7

lines 46–47why, one step back
46
47

Fix repo URLTom Christiebefore adoptiond515e4b

lines 48–71why, one step back
48## `Response`
4950*An HTTP response.*5152* `def __init__(...)`53* `.status_code` - **int**54* `.reason_phrase` - **str**55* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"`56* `.url` - **URL**57* `.headers` - **Headers**58* `.content` - **bytes**59* `.text` - **str**60* `.encoding` - **str**61* `.is_redirect` - **bool**62* `.request` - **Request**63* `.cookies` - **Cookies**64* `.history` - **List[Response]**65* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**66 * The amount of time elapsed between sending the request and calling `close()` on the corresponding response received for that request.67 [total_seconds()](https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds) to correctly get68 the total elapsed seconds.69* `def .raise_for_status()` - **None**70* `def .json()` - **Any**71* `def .read()` - **bytes**

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

lines 72–75why, one step back
72* `def .iter_raw()` - **bytes iterator**
73* `def .iter_bytes()` - **bytes iterator**74* `def .iter_text()` - **text iterator**75* `def .iter_lines()` - **text iterator**

Fix repo URLTom Christiebefore adoptiond515e4b

lines 76–90why, one step back
76* `def .close()` - **None**
77* `def .next()` - **Response**78* `def .aread()` - **bytes**79* `def .aiter_raw()` - **async bytes iterator**80* `def .aiter_bytes()` - **async bytes iterator**81* `def .aiter_text()` - **async text iterator**82* `def .aiter_lines()` - **async text iterator**83* `def .aclose()` - **None**84* `def .anext()` - **Response**8586## `Request`8788*An HTTP request. Can be constructed explicitly for more control over exactly89what gets sent over the wire.*90

Use pycon for Python console code blocks (#1187)Hugo van Kemenadebefore adoptiond10b7cd

line 91why, one step back
91```pycon

Fix repo URLTom Christiebefore adoptiond515e4b

lines 92–106why, one step back
92>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})
93>>> response = client.send(request)94```9596* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`97* `.method` - **str**98* `.url` - **URL**99* `.content` - **byte**, **byte iterator**, or **byte async iterator**100* `.headers` - **Headers**101* `.cookies` - **Cookies**102103## `URL`104105*A normalized, IDNA supporting URL.*106

Use pycon for Python console code blocks (#1187)Hugo van Kemenadebefore adoptiond10b7cd

line 107why, one step back
107```pycon

Fix repo URLTom Christiebefore adoptiond515e4b

lines 108–130why, one step back
108>>> url = URL("https://example.org/")
109>>> url.host110'example.org'111```112113* `def __init__(url, allow_relative=False, params=None)`114* `.scheme` - **str**115* `.authority` - **str**116* `.host` - **str**117* `.port` - **int**118* `.path` - **str**119* `.query` - **str**120* `.full_path` - **str**121* `.fragment` - **str**122* `.is_ssl` - **bool**123* `.is_absolute_url` - **bool**124* `.is_relative_url` - **bool**125* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**126127## `Headers`128129*A case-insensitive multi-dict.*130

Use pycon for Python console code blocks (#1187)Hugo van Kemenadebefore adoptiond10b7cd

line 131why, one step back
131```pycon

Fix repo URLTom Christiebefore adoptiond515e4b

lines 132–136why, one step back
132>>> headers = Headers({'Content-Type': 'application/json'})
133>>> headers['content-type']134'application/json'135```136

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 137–138why, one step back
137* `def __init__(self, headers, encoding=None)`
138* `def copy()` - **Headers**

Fix repo URLTom Christiebefore adoptiond515e4b

lines 139–143why, one step back
139
140## `Cookies`141142*A dict-like cookie store.*143

Use pycon for Python console code blocks (#1187)Hugo van Kemenadebefore adoptiond10b7cd

line 144why, one step back
144```pycon

Fix repo URLTom Christiebefore adoptiond515e4b

lines 145–157why, one step back
145>>> cookies = Cookies()
146>>> cookies.set("name", "value", domain="example.org")147```148149* `def __init__(cookies: [dict, Cookies, CookieJar])`150* `.jar` - **CookieJar**151* `def extract_cookies(response)`152* `def set_cookie_header(request)`153* `def set(name, value, [domain], [path])`154* `def get(name, [domain], [path])`155* `def delete(name, [domain], [path])`156* `def clear([domain], [path])`157* *Standard mutable mapping interface*