api.md
This file
Path
docs/api.md
160 lines · 3.8 KiB · Markdown
Last changed by
stream -> stream_bytes, raw -> stream_raw (#599)Tom Christiebefore adoptionfc95c7e
History of this fileTake it
The walk stopped after 200 commits: lines older than 9e420a5 point at it.
Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5
lines 1–10why, one step back1# Developer Interface23## 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.10First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 11–12why, one step back11::: httpx.request12 :docstring:Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5
line 13why, one step back13First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 14–15why, one step back14::: httpx.get15 :docstring:Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5
line 16why, one step back16First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 17–18why, one step back17::: httpx.options18 :docstring:Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5
line 19why, one step back19First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 20–21why, one step back20::: httpx.head21 :docstring:Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5
line 22why, one step back22First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 23–38why, one step back23::: httpx.post24 :docstring:2526::: httpx.put27 :docstring:2829::: httpx.patch30 :docstring:3132::: httpx.delete33 :docstring:3435## `Client`3637::: httpx.Client38 :docstring:Drop sync (#544)Tom Christiebefore adoption206c537
line 39why, one step back39 :members: headers cookies params request get head options post put patch delete build_request send closeAutomatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5
lines 40–57why, one step back4041## `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]**Add `.elapsed` onto Response objects tracking how long a request took. (#351)Roy Williamsbefore adoption05ac117
lines 58–62why, one step back58* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**59 * The amount of time elapsed between sending the first byte and parsing the headers (not including time spent reading60 the response). Use61 [total_seconds()](https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds) to correctly get62 the total elapsed seconds.Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5
lines 63–65why, one step back63* `def .raise_for_status()` - **None**64* `def .json()` - **Any**65* `def .read()` - **bytes**stream -> stream_bytes, raw -> stream_raw (#599)Tom Christiebefore adoptionfc95c7e
lines 66–69why, one step back66* `def .stream_raw()` - **async bytes iterator**67* `def .stream_bytes()` - **async bytes iterator**68* `def .stream_text()` - **async text iterator**69* `def .stream_lines()` - **async text iterator**Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5
lines 70–79why, one step back70* `def .close()` - **None**71* `def .next()` - **Response**7273## `Request`7475*An HTTP request. Can be constructed explicitly for more control over exactly76what gets sent over the wire.*7778```python79>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})Drop sync (#544)Tom Christiebefore adoption206c537
line 80why, one step back80>>> response = await client.send(request)Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5
lines 81–160why, one step back81```8283* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`84* `.method` - **str**85* `.url` - **URL**86* `.content` - **byte** or **byte async iterator**87* `.headers` - **Headers**88* `.cookies` - **Cookies**8990## `URL`9192*A normalized, IDNA supporting URL.*9394```python95>>> url = URL("https://example.org/")96>>> url.host97'example.org'98```99100* `def __init__(url, allow_relative=False, params=None)`101* `.scheme` - **str**102* `.authority` - **str**103* `.host` - **str**104* `.port` - **int**105* `.path` - **str**106* `.query` - **str**107* `.full_path` - **str**108* `.fragment` - **str**109* `.is_ssl` - **bool**110* `.origin` - **Origin**111* `.is_absolute_url` - **bool**112* `.is_relative_url` - **bool**113* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**114* `def .resolve_with(url)` - **URL**115116## `Origin`117118*A normalized, IDNA supporting set of scheme/host/port info.*119120```python121>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')122True123```124125* `def __init__(url)`126* `.scheme` - **str**127* `.is_ssl` - **bool**128* `.host` - **str**129* `.port` - **int**130131## `Headers`132133*A case-insensitive multi-dict.*134135```python136>>> headers = Headers({'Content-Type': 'application/json'})137>>> headers['content-type']138'application/json'139```140141* `def __init__(self, headers)`142143## `Cookies`144145*A dict-like cookie store.*146147```python148>>> 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*