Skip to content
Myr

api.md

This file

Path

docs/api.md

159 lines · 3.8 KiB · Markdown

Last changed by

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

History of this file

Take it

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

Document supported async libraries (#387)Florimond Mancabefore adoption3496525

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:

Document supported async libraries (#387)Florimond Mancabefore adoption3496525

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:

Document supported async libraries (#387)Florimond Mancabefore adoption3496525

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:

Document supported async libraries (#387)Florimond Mancabefore adoption3496525

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:

Document supported async libraries (#387)Florimond Mancabefore adoption3496525

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

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

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

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

line 36why, one step back
36

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

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

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

line 38why, one step back
38 :docstring:

Rename 'close' to 'aclose' on Client (#675)Florimond Mancabefore adoptiond5da743

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

Document supported async libraries (#387)Florimond Mancabefore adoption3496525

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.

Document supported async libraries (#387)Florimond Mancabefore adoption3496525

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**

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

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

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

lines 65–68why, one step back
65* `def .aiter_raw()` - **async bytes iterator**
66* `def .aiter_bytes()` - **async bytes iterator**67* `def .aiter_text()` - **async text iterator**68* `def .aiter_lines()` - **async text iterator**

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

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

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

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

Document supported async libraries (#387)Florimond Mancabefore adoption3496525

lines 71–78why, one step back
71
72## `Request`7374*An HTTP request. Can be constructed explicitly for more control over exactly75what gets sent over the wire.*7677```python78>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})

Drop sync (#544)Tom Christiebefore adoption206c537

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

Document supported async libraries (#387)Florimond Mancabefore adoption3496525

lines 80–159why, one step back
80```
8182* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`83* `.method` - **str**84* `.url` - **URL**85* `.content` - **byte** or **byte async iterator**86* `.headers` - **Headers**87* `.cookies` - **Cookies**8889## `URL`9091*A normalized, IDNA supporting URL.*9293```python94>>> url = URL("https://example.org/")95>>> url.host96'example.org'97```9899* `def __init__(url, allow_relative=False, params=None)`100* `.scheme` - **str**101* `.authority` - **str**102* `.host` - **str**103* `.port` - **int**104* `.path` - **str**105* `.query` - **str**106* `.full_path` - **str**107* `.fragment` - **str**108* `.is_ssl` - **bool**109* `.origin` - **Origin**110* `.is_absolute_url` - **bool**111* `.is_relative_url` - **bool**112* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**113* `def .resolve_with(url)` - **URL**114115## `Origin`116117*A normalized, IDNA supporting set of scheme/host/port info.*118119```python120>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')121True122```123124* `def __init__(url)`125* `.scheme` - **str**126* `.is_ssl` - **bool**127* `.host` - **str**128* `.port` - **int**129130## `Headers`131132*A case-insensitive multi-dict.*133134```python135>>> headers = Headers({'Content-Type': 'application/json'})136>>> headers['content-type']137'application/json'138```139140* `def __init__(self, headers)`141142## `Cookies`143144*A dict-like cookie store.*145146```python147>>> cookies = Cookies()148>>> cookies.set("name", "value", domain="example.org")149```150151* `def __init__(cookies: [dict, Cookies, CookieJar])`152* `.jar` - **CookieJar**153* `def extract_cookies(response)`154* `def set_cookie_header(request)`155* `def set(name, value, [domain], [path])`156* `def get(name, [domain], [path])`157* `def delete(name, [domain], [path])`158* `def clear([domain], [path])`159* *Standard mutable mapping interface*