Skip to content
Myr

README.md

This file

Path

README.md

249 lines · 6.9 KiB · Markdown

Last changed by

TweakTom Christiebefore adoptionf6a2aef

History of this file

Take it

StuffTom Christiebefore adoption30530d4

lines 1–2why, one step back
1# HTTPCore
2

Merge pull request #43 from encode/badgesTom Christiebefore adoption3553625

lines 3–12why, one step back
3<a href="https://travis-ci.org/encode/httpcore">
4 <img src="https://travis-ci.org/encode/httpcore.svg?branch=master" alt="Build Status">5</a>6<a href="https://codecov.io/gh/encode/httpcore">7 <img src="https://codecov.io/gh/encode/httpcore/branch/master/graph/badge.svg" alt="Coverage">8</a>9<a href="https://pypi.org/project/httpcore/">10 <img src="https://badge.fury.io/py/httpcore.svg" alt="Package version">11</a>12

Truckin' onTom Christiebefore adoption6b60d95

line 13why, one step back
13## Feature support

Update READMETom Christiebefore adoption665743a

line 14why, one step back
14

Add cookie interfacesTom Christiebefore adoption0717998

line 15why, one step back
15* `HTTP/2` and `HTTP/1.1` support.

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 16–17why, one step back
16* `async`/`await` support for non-blocking HTTP requests.
17* Strict timeouts everywhere by default.

Truckin' onTom Christiebefore adoption6b60d95

line 18why, one step back
18* Fully type annotated.

Update README.mdTom Christiebefore adoption23e0786

line 19why, one step back
19* 100% test coverage.

Update READMETom Christiebefore adoption665743a

line 20why, one step back
20

Truckin' onTom Christiebefore adoption6b60d95

line 21why, one step back
21Plus all the standard features of requests...

Update READMETom Christiebefore adoption665743a

line 22why, one step back
22

Truckin' onTom Christiebefore adoption6b60d95

lines 23–24why, one step back
23* International Domains and URLs
24* Keep-Alive & Connection Pooling

Add cookie interfacesTom Christiebefore adoption0717998

line 25why, one step back
25* Sessions with Cookie Persistence

Truckin' onTom Christiebefore adoption6b60d95

line 26why, one step back
26* Browser-style SSL Verification

Update README.mdTom Christiebefore adoption144ce4f

line 27why, one step back
27* Basic/Digest Authentication *TODO - We have Basic, but not Digest yet.*

Add cookie interfacesTom Christiebefore adoption0717998

line 28why, one step back
28* Elegant Key/Value Cookies

Truckin' onTom Christiebefore adoption6b60d95

lines 29–31why, one step back
29* Automatic Decompression
30* Automatic Content Decoding31* Unicode Response Bodies

Update README.mdTom Christiebefore adoption3408d7b

line 32why, one step back
32* Multipart File Uploads *TODO - Request content currently supports URL encoded data, bytes, or async byte iterators.*

Truckin' onTom Christiebefore adoption6b60d95

lines 33–35why, one step back
33* HTTP(S) Proxy Support *TODO*
34* Connection Timeouts35* Streaming Downloads

Update READMETom Christiebefore adoption58461d4

line 36why, one step back
36* .netrc Support *TODO*

Truckin' onTom Christiebefore adoption6b60d95

line 37why, one step back
37* Chunked Requests

Update READMETom Christiebefore adoption665743a

line 38why, one step back
38

Update README.mdTom Christiebefore adoption0d3eb0e

line 39why, one step back
39## Usage

Update README.mdTom Christiebefore adoption01a3c09

line 40why, one step back
40

Update README.mdTom Christiebefore adoption337eb70

lines 41–42why, one step back
41Making a request:
42

StuffTom Christiebefore adoption30530d4

line 43why, one step back
43```python

Truckin' onTom Christiebefore adoption6b60d95

lines 44–45why, one step back
44>>> import httpcore
45>>> client = httpcore.Client()

Update READMETom Christiebefore adoption58461d4

line 46why, one step back
46>>> response = client.get('https://example.com')

Truckin' onTom Christiebefore adoption6b60d95

line 47why, one step back
47>>> response.status_code

Minor README tweakTom Christiebefore adoption813bb7c

line 48why, one step back
48<HTTPStatus.OK: 200>

Still truckin' onTom Christiebefore adoption6cb5c0d

lines 49–50why, one step back
49>>> response.protocol
50'HTTP/2'

Truckin' onTom Christiebefore adoption6b60d95

lines 51–52why, one step back
51>>> response.text
52'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'

StuffTom Christiebefore adoption30530d4

lines 53–54why, one step back
53```
54

Update READMETom Christiebefore adoption58461d4

line 55why, one step back
55Alternatively, async requests:

StuffTom Christiebefore adoption30530d4

line 56why, one step back
56

Update READMETom Christiebefore adoption58461d4

lines 57–58why, one step back
57**Note**: Use `ipython` to try this from the console, since it supports `await`.
58

StuffTom Christiebefore adoption30530d4

line 59why, one step back
59```python

Truckin' onTom Christiebefore adoption6b60d95

line 60why, one step back
60>>> import httpcore

Update READMETom Christiebefore adoption58461d4

lines 61–62why, one step back
61>>> client = httpcore.AsyncClient()
62>>> response = await client.get('https://example.com')

Truckin' onTom Christiebefore adoption6b60d95

line 63why, one step back
63>>> response.status_code

Minor README tweakTom Christiebefore adoption813bb7c

line 64why, one step back
64<HTTPStatus.OK: 200>

Still truckin' onTom Christiebefore adoption6cb5c0d

lines 65–66why, one step back
65>>> response.protocol
66'HTTP/2'

Truckin' onTom Christiebefore adoption6b60d95

lines 67–68why, one step back
67>>> response.text
68'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'

StuffTom Christiebefore adoption30530d4

lines 69–70why, one step back
69```
70

Truckin' onTom Christiebefore adoption6b60d95

line 71why, one step back
71---

StuffTom Christiebefore adoption30530d4

line 72why, one step back
72

Update READMETom Christiebefore adoption4fe2f69

lines 73–75why, one step back
73## Dependencies
7475* `h2` - HTTP/2 support.

Add cookie interfacesTom Christiebefore adoption0717998

line 76why, one step back
76* `h11` - HTTP/1.1 support.

Update READMETom Christiebefore adoption4fe2f69

lines 77–82why, one step back
77* `certifi` - SSL certificates.
78* `chardet` - Fallback auto-detection for response encoding.79* `idna` - Internationalized domain name support.80* `rfc3986` - URL parsing & normalization.81* `brotlipy` - Decoding for "brotli" compressed responses. *(Optional)*82

Update READMETom Christiebefore adoption58461d4

line 83why, one step back
83A huge amount of credit is due to `requests` for the API layout that

Update README.mdTom Christiebefore adoption84b9691

lines 84–85why, one step back
84much of this work follows, as well as to `urllib3` for plenty of design
85inspiration around the lower level networking details.

Update READMETom Christiebefore adoption4fe2f69

lines 86–88why, one step back
86
87---88

Truckin' onTom Christiebefore adoption6b60d95

line 89why, one step back
89## API Reference

Update READMETom Christiebefore adoption68b80dc

line 90why, one step back
90

Reorganise structureTom Christiebefore adoption0c6f618

line 91why, one step back
91### `Client`

Update READMETom Christiebefore adoption68b80dc

line 92why, one step back
92

Update READMETom Christiebefore adoption891548e

lines 93–96why, one step back
93*An HTTP client, with connection pooling, redirects, cookie persistence, etc.*
9495```python96>>> client = Client()

Update READMETom Christiebefore adoption441a1f6

line 97why, one step back
97>>> response = client.get('https://example.org')

Update READMETom Christiebefore adoption891548e

lines 98–99why, one step back
98```
99

Add cookie interfacesTom Christiebefore adoption0717998

line 100why, one step back
100* `def __init__([auth], [cookies], [ssl], [timeout], [pool_limits], [max_redirects], [dispatch])`

query_params -> paramsTom Christiebefore adoptionbb70377

lines 101–108why, one step back
101* `def .request(method, url, [content], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`
102* `def .get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`103* `def .options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`104* `def .head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`105* `def .post(url, [content], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`106* `def .put(url, [content], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`107* `def .patch(url, [content], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`108* `def .delete(url, [content], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`

Still truckin' onTom Christiebefore adoption6cb5c0d

line 109why, one step back
109* `def .prepare_request(request)`

Update READMETom Christiebefore adoption58461d4

lines 110–111why, one step back
110* `def .send(request, [stream], [allow_redirects], [ssl], [timeout])`
111* `def .close()`

Update README.mdTom Christiebefore adoption01a3c09

line 112why, one step back
112

Reorganise structureTom Christiebefore adoption0c6f618

line 113why, one step back
113### `Response`

README tweaksTom Christiebefore adoption8e1a263

line 114why, one step back
114

Update READMETom Christiebefore adoption4fe2f69

line 115why, one step back
115*An HTTP response.*

Still truckin' onTom Christiebefore adoption6cb5c0d

line 116why, one step back
116

Update READMETom Christiebefore adoption2de053e

line 117why, one step back
117* `def __init__(...)`

Truckin' onTom Christiebefore adoption6b60d95

lines 118–127why, one step back
118* `.status_code` - **int**
119* `.reason_phrase` - **str**120* `.protocol` - `"HTTP/2"` or `"HTTP/1.1"`121* `.url` - **URL**122* `.headers` - **Headers**123* `.content` - **bytes**124* `.text` - **str**125* `.encoding` - **str**126* `.is_redirect` - **bool**127* `.request` - **Request**

Add cookie interfacesTom Christiebefore adoption0717998

line 128why, one step back
128* `.cookies` - **Cookies**

Truckin' onTom Christiebefore adoption6b60d95

line 129why, one step back
129* `.history` - **List[Response]**

Update README.mdTom Christiebefore adoption93d7ba3

line 130why, one step back
130* `def .raise_for_status()` - **None**

Update READMETom Christiebefore adoptionfa8d296

line 131why, one step back
131* `def .json()` - **Any** *TODO*

Update READMETom Christiebefore adoption58461d4

lines 132–136why, one step back
132* `def .read()` - **bytes**
133* `def .stream()` - **bytes iterator**134* `def .raw()` - **bytes iterator**135* `def .close()` - **None**136* `def .next()` - **Response**

Update READMETom Christiebefore adoptionfa8d296

line 137why, one step back
137

Reorganise structureTom Christiebefore adoption0c6f618

line 138why, one step back
138### `Request`

Truckin' onTom Christiebefore adoption6b60d95

line 139why, one step back
139

Still truckin' onTom Christiebefore adoption6cb5c0d

lines 140–143why, one step back
140*An HTTP request. Can be constructed explicitly for more control over exactly
141what gets sent over the wire.*142143```python

Update READMETom Christiebefore adoption891548e

line 144why, one step back
144>>> request = Request("GET", "https://example.org", headers={'host': 'example.org'})

Update READMETom Christiebefore adoptiona5eb829

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

Still truckin' onTom Christiebefore adoption6cb5c0d

lines 146–147why, one step back
146```
147

query_params -> paramsTom Christiebefore adoptionbb70377

line 148why, one step back
148* `def __init__(method, url, params, [content], [headers], [cookies])`

TweakTom Christiebefore adoptionf6a2aef

line 149why, one step back
149* `.method` - **str**

Update READMETom Christiebefore adoptionfa8d296

lines 150–152why, one step back
150* `.url` - **URL**
151* `.content` - **byte** or **byte async iterator**152* `.headers` - **Headers**

Add cookie interfacesTom Christiebefore adoption0717998

line 153why, one step back
153* `.cookies` - **Cookies**

Truckin' onTom Christiebefore adoption6b60d95

line 154why, one step back
154

Reorganise structureTom Christiebefore adoption0c6f618

line 155why, one step back
155### `URL`

Truckin' onTom Christiebefore adoption6b60d95

lines 156–157why, one step back
156
157*A normalized, IDNA supporting URL.*

Update READMETom Christiebefore adoption891548e

lines 158–163why, one step back
158
159```python160>>> url = URL("https://example.org/")161>>> url.host162'example.org'163```

Truckin' onTom Christiebefore adoption6b60d95

line 164why, one step back
164

query_params -> paramsTom Christiebefore adoptionbb70377

line 165why, one step back
165* `def __init__(url, allow_relative=False, params=None)`

Truckin' onTom Christiebefore adoption6b60d95

lines 166–177why, one step back
166* `.scheme` - **str**
167* `.authority` - **str**168* `.host` - **str**169* `.port` - **int**170* `.path` - **str**171* `.query` - **str**172* `.full_path` - **str**173* `.fragment` - **str**174* `.is_ssl` - **bool**175* `.origin` - **Origin**176* `.is_absolute_url` - **bool**177* `.is_relative_url` - **bool**

Update READMETom Christiebefore adoptionfa8d296

lines 178–179why, one step back
178* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**
179* `def .resolve_with(url)` - **URL**

Truckin' onTom Christiebefore adoption6b60d95

line 180why, one step back
180

Reorganise structureTom Christiebefore adoption0c6f618

line 181why, one step back
181### `Origin`

Truckin' onTom Christiebefore adoption6b60d95

lines 182–184why, one step back
182
183*A normalized, IDNA supporting set of scheme/host/port info.*184

Update README for 0.2.0Tom Christiebefore adoptionbb3d452

line 185why, one step back
185```python

Truckin' onTom Christiebefore adoption6b60d95

lines 186–187why, one step back
186>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')
187True

README tweaksTom Christiebefore adoption8e1a263

lines 188–189why, one step back
188```
189

Update READMETom Christiebefore adoption2de053e

line 190why, one step back
190* `def __init__(url)`

Truckin' onTom Christiebefore adoption6b60d95

lines 191–193why, one step back
191* `.is_ssl` - **bool**
192* `.host` - **str**193* `.port` - **int**

Added proxy exampleTom Christiebefore adoption87b21b0

line 194why, one step back
194

Reorganise structureTom Christiebefore adoption0c6f618

line 195why, one step back
195### `Headers`

Added proxy exampleTom Christiebefore adoption87b21b0

line 196why, one step back
196

Truckin' onTom Christiebefore adoption6b60d95

lines 197–198why, one step back
197*A case-insensitive multi-dict.*
198

Added proxy exampleTom Christiebefore adoption87b21b0

line 199why, one step back
199```python

Truckin' onTom Christiebefore adoption6b60d95

lines 200–203why, one step back
200>>> headers = Headers({'Content-Type': 'application/json'})
201>>> headers['content-type']202'application/json'203```

Update READMETom Christiebefore adoption2de053e

line 204why, one step back
204

Add cookie interfacesTom Christiebefore adoption0717998

lines 205–223why, one step back
205* `def __init__(self, headers)`
206207### `Cookies`208209*A dict-like cookie store.*210211```python212>>> cookies = Cookies()213>>> cookies.set("name", "value", domain="example.org")214```215216* `def __init__(cookies: [dict, Cookies, CookieJar])`217* `def extract_cookies(response)`218* `def set_cookie_header(request)`219* `def set(name, value, [domain], [path])`220* `def get(name, [domain], [path])`221* `def delete(name, [domain], [path])`222* `def clear([domain], [path])`223* *Standard mutable mapping interface*

Added proxy exampleTom Christiebefore adoption87b21b0

line 224why, one step back
224

Truckin' onTom Christiebefore adoption6b60d95

line 225why, one step back
225___

Added proxy exampleTom Christiebefore adoption87b21b0

line 226why, one step back
226

Truckin' onTom Christiebefore adoption6b60d95

line 227why, one step back
227## Alternate backends

Added proxy exampleTom Christiebefore adoption87b21b0

line 228why, one step back
228

Update READMETom Christiebefore adoption58461d4

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 230why, one step back
230

Update READMETom Christiebefore adoption58461d4

line 231why, one step back
231An asyncio client.

Added proxy exampleTom Christiebefore adoption87b21b0

line 232why, one step back
232

Truckin' onTom Christiebefore adoption6b60d95

line 233why, one step back
233### `TrioClient`

Added proxy exampleTom Christiebefore adoption87b21b0

line 234why, one step back
234

Truckin' onTom Christiebefore adoption6b60d95

line 235why, one step back
235*TODO*

Added proxy exampleTom Christiebefore adoption87b21b0

line 236why, one step back
236

Truckin' onTom Christiebefore adoption6b60d95

line 237why, one step back
237---

Added proxy exampleTom Christiebefore adoption87b21b0

line 238why, one step back
238

Truckin' onTom Christiebefore adoption6b60d95

line 239why, one step back
239## The Stack

Improve GatewayService exampleTom Christiebefore adoption9d59a5a

line 240why, one step back
240

Update READMETom Christiebefore adoption58461d4

lines 241–243why, one step back
241There are two main layers in the stack. The client handles redirection,
242cookie persistence (TODO), and authentication (TODO). The dispatcher243handles sending the actual request and getting the response.

Improve GatewayService exampleTom Christiebefore adoption9d59a5a

line 244why, one step back
244

Update READMETom Christiebefore adoption58461d4

lines 245–246why, one step back
245* `Client` - Redirect, authentication, cookies etc.
246* `ConnectionPool(Dispatcher)` - Connection pooling & keep alive.

Truckin' onTom Christiebefore adoption6b60d95

lines 247–249why, one step back
247 * `HTTPConnection` - A single connection.
248 * `HTTP11Connection` - A single HTTP/1.1 connection.249 * `HTTP2Connection` - A single HTTP/2 connection, with multiple streams.