Skip to content
Myr

api.md

This file

Path

docs/api.md

160 lines · 4.0 KiB · Markdown

Last changed by

Add stream docstring (#1200)Joebefore adoption924fa8c

History of this file

Take it

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

asgi: Send http.disconnect message on receive() after response complete (#909)Jamie Hewlandbefore adoption8710079

lines 1–33why, 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:

Add stream docstring (#1200)Joebefore adoption924fa8c

lines 34–36why, one step back
34
35::: httpx.stream36 :docstring:

asgi: Send http.disconnect message on receive() after response complete (#909)Jamie Hewlandbefore adoption8710079

lines 37–41why, one step back
37
38## `Client`3940::: httpx.Client41 :docstring:

Add stream docstring (#1200)Joebefore adoption924fa8c

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

asgi: Send http.disconnect message on receive() after response complete (#909)Jamie Hewlandbefore adoption8710079

lines 43–47why, one step back
43
44## `AsyncClient`4546::: httpx.AsyncClient47 :docstring:

Add stream docstring (#1200)Joebefore adoption924fa8c

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

asgi: Send http.disconnect message on receive() after response complete (#909)Jamie Hewlandbefore adoption8710079

lines 49–93why, one step back
49
5051## `Response`5253*An HTTP response.*5455* `def __init__(...)`56* `.status_code` - **int**57* `.reason_phrase` - **str**58* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"`59* `.url` - **URL**60* `.headers` - **Headers**61* `.content` - **bytes**62* `.text` - **str**63* `.encoding` - **str**64* `.is_redirect` - **bool**65* `.request` - **Request**66* `.cookies` - **Cookies**67* `.history` - **List[Response]**68* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**69 * The amount of time elapsed between sending the request and calling `close()` on the corresponding response received for that request.70 [total_seconds()](https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds) to correctly get71 the total elapsed seconds.72* `def .raise_for_status()` - **None**73* `def .json()` - **Any**74* `def .read()` - **bytes**75* `def .iter_raw()` - **bytes iterator**76* `def .iter_bytes()` - **bytes iterator**77* `def .iter_text()` - **text iterator**78* `def .iter_lines()` - **text iterator**79* `def .close()` - **None**80* `def .next()` - **Response**81* `def .aread()` - **bytes**82* `def .aiter_raw()` - **async bytes iterator**83* `def .aiter_bytes()` - **async bytes iterator**84* `def .aiter_text()` - **async text iterator**85* `def .aiter_lines()` - **async text iterator**86* `def .aclose()` - **None**87* `def .anext()` - **Response**8889## `Request`9091*An HTTP request. Can be constructed explicitly for more control over exactly92what gets sent over the wire.*93

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

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

asgi: Send http.disconnect message on receive() after response complete (#909)Jamie Hewlandbefore adoption8710079

lines 95–109why, one step back
95>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})
96>>> response = client.send(request)97```9899* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`100* `.method` - **str**101* `.url` - **URL**102* `.content` - **byte**, **byte iterator**, or **byte async iterator**103* `.headers` - **Headers**104* `.cookies` - **Cookies**105106## `URL`107108*A normalized, IDNA supporting URL.*109

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

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

asgi: Send http.disconnect message on receive() after response complete (#909)Jamie Hewlandbefore adoption8710079

lines 111–133why, one step back
111>>> url = URL("https://example.org/")
112>>> url.host113'example.org'114```115116* `def __init__(url, allow_relative=False, params=None)`117* `.scheme` - **str**118* `.authority` - **str**119* `.host` - **str**120* `.port` - **int**121* `.path` - **str**122* `.query` - **str**123* `.full_path` - **str**124* `.fragment` - **str**125* `.is_ssl` - **bool**126* `.is_absolute_url` - **bool**127* `.is_relative_url` - **bool**128* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**129130## `Headers`131132*A case-insensitive multi-dict.*133

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

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

asgi: Send http.disconnect message on receive() after response complete (#909)Jamie Hewlandbefore adoption8710079

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

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

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

asgi: Send http.disconnect message on receive() after response complete (#909)Jamie Hewlandbefore adoption8710079

lines 142–146why, one step back
142
143## `Cookies`144145*A dict-like cookie store.*146

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

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

asgi: Send http.disconnect message on receive() after response complete (#909)Jamie Hewlandbefore adoption8710079

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