api.md
This file
Path
docs/api.md
176 lines · 4.4 KiB · Markdown
Last changed by
Docs: Add `httpx.Proxy` to api.md (#3512)mv-pythonbefore adoption9e8ab40
History of this fileTake it
The walk stopped after 200 commits: lines older than 9d022c0 point at it.
Bump ruff from 0.0.260 to 0.0.275 (#2753)dependabot[bot]before adoption9d022c0
lines 1–72why, 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.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::: httpx.stream36 :docstring:3738## `Client`3940::: httpx.Client41 :docstring:42 :members: headers cookies params auth request get head options post put patch delete stream build_request send close4344## `AsyncClient`4546::: httpx.AsyncClient47 :docstring:48 :members: headers cookies params auth request get head options post put patch delete stream build_request send aclose495051## `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* `.next_request` - **Optional[Request]**67* `.cookies` - **Cookies**68* `.history` - **List[Response]**69* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**70 * The amount of time elapsed between sending the request and calling `close()` on the corresponding response received for that request.71 [total_seconds()](https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds) to correctly get72 the total elapsed seconds.Make `raise_for_status` chainable (#2776)Trim21before adoption9415af6
line 73why, one step back73* `def .raise_for_status()` - **Response**Bump ruff from 0.0.260 to 0.0.275 (#2753)dependabot[bot]before adoption9d022c0
lines 74–116why, one step back74* `def .json()` - **Any**75* `def .read()` - **bytes**76* `def .iter_raw([chunk_size])` - **bytes iterator**77* `def .iter_bytes([chunk_size])` - **bytes iterator**78* `def .iter_text([chunk_size])` - **text iterator**79* `def .iter_lines()` - **text iterator**80* `def .close()` - **None**81* `def .next()` - **Response**82* `def .aread()` - **bytes**83* `def .aiter_raw([chunk_size])` - **async bytes iterator**84* `def .aiter_bytes([chunk_size])` - **async bytes iterator**85* `def .aiter_text([chunk_size])` - **async text iterator**86* `def .aiter_lines()` - **async text iterator**87* `def .aclose()` - **None**88* `def .anext()` - **Response**8990## `Request`9192*An HTTP request. Can be constructed explicitly for more control over exactly93what gets sent over the wire.*9495```pycon96>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})97>>> response = client.send(request)98```99100* `def __init__(method, url, [params], [headers], [cookies], [content], [data], [files], [json], [stream])`101* `.method` - **str**102* `.url` - **URL**103* `.content` - **byte**, **byte iterator**, or **byte async iterator**104* `.headers` - **Headers**105* `.cookies` - **Cookies**106107## `URL`108109*A normalized, IDNA supporting URL.*110111```pycon112>>> url = URL("https://example.org/")113>>> url.host114'example.org'115```116Update URL.__init__ signature (#3159)Hugo Cachitasbefore adoption5bb2ea0
line 117why, one step back117* `def __init__(url, **kwargs)`Bump ruff from 0.0.260 to 0.0.275 (#2753)dependabot[bot]before adoption9d022c0
lines 118–161why, one step back118* `.scheme` - **str**119* `.authority` - **str**120* `.host` - **str**121* `.port` - **int**122* `.path` - **str**123* `.query` - **str**124* `.raw_path` - **str**125* `.fragment` - **str**126* `.is_ssl` - **bool**127* `.is_absolute_url` - **bool**128* `.is_relative_url` - **bool**129* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**130131## `Headers`132133*A case-insensitive multi-dict.*134135```pycon136>>> headers = Headers({'Content-Type': 'application/json'})137>>> headers['content-type']138'application/json'139```140141* `def __init__(self, headers, encoding=None)`142* `def copy()` - **Headers**143144## `Cookies`145146*A dict-like cookie store.*147148```pycon149>>> cookies = Cookies()150>>> cookies.set("name", "value", domain="example.org")151```152153* `def __init__(cookies: [dict, Cookies, CookieJar])`154* `.jar` - **CookieJar**155* `def extract_cookies(response)`156* `def set_cookie_header(request)`157* `def set(name, value, [domain], [path])`158* `def get(name, [domain], [path])`159* `def delete(name, [domain], [path])`160* `def clear([domain], [path])`161* *Standard mutable mapping interface*Docs: Add `httpx.Proxy` to api.md (#3512)mv-pythonbefore adoption9e8ab40
lines 162–176why, one step back162163## `Proxy`164165*A configuration of the proxy server.*166167```pycon168>>> proxy = Proxy("http://proxy.example.com:8030")169>>> client = Client(proxy=proxy)170```171172* `def __init__(url, [ssl_context], [auth], [headers])`173* `.url` - **URL**174* `.auth` - **tuple[str, str]**175* `.headers` - **Headers**176* `.ssl_context` - **SSLContext**