Skip to content
Myr

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 file

Take it

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

Drop Protocol str enum class in favor of plain old strings (#251)Tom Christiebefore adoptione69ee77

lines 1–2why, one step back
1# Developer Interface
2

Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6

line 3why, one step back
3## Helper Functions

Drop Protocol str enum class in favor of plain old strings (#251)Tom Christiebefore adoptione69ee77

line 4why, one step back
4

Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6

lines 5–10why, one step back
5!!! note
6 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:

Drop Protocol str enum class in favor of plain old strings (#251)Tom Christiebefore adoptione69ee77

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:

Drop Protocol str enum class in favor of plain old strings (#251)Tom Christiebefore adoptione69ee77

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:

Drop Protocol str enum class in favor of plain old strings (#251)Tom Christiebefore adoptione69ee77

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:

Drop Protocol str enum class in favor of plain old strings (#251)Tom Christiebefore adoptione69ee77

line 22why, one step back
22

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

lines 23–38why, one step back
23::: httpx.post
24 :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 back
39 :members: headers cookies params request get head options post put patch delete build_request send close

Drop Protocol str enum class in favor of plain old strings (#251)Tom Christiebefore adoptione69ee77

lines 40–57why, 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]**

Add `.elapsed` onto Response objects tracking how long a request took. (#351)Roy Williamsbefore adoption05ac117

lines 58–62why, one step back
58* `.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.

Drop Protocol str enum class in favor of plain old strings (#251)Tom Christiebefore adoptione69ee77

lines 63–65why, one step back
63* `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 back
66* `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**

Drop Protocol str enum class in favor of plain old strings (#251)Tom Christiebefore adoptione69ee77

lines 70–79why, one step back
70* `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 back
80>>> response = await client.send(request)

Drop Protocol str enum class in favor of plain old strings (#251)Tom Christiebefore adoptione69ee77

lines 81–160why, one step back
81```
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*