Skip to content
Myr

README.md

This file

Path

README.md

230 lines · 6.3 KiB · Markdown

Last changed by

Update README.mdTom Christiebefore adoption23e0786

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

Truckin' onTom Christiebefore adoption6b60d95

line 15why, one step back
15* `HTTP/1.1` and `HTTP/2` 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

Update READMETom Christiebefore adoption58461d4

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

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

Truckin' onTom Christiebefore adoption6b60d95

lines 28–31why, one step back
28* Elegant Key/Value Cookies *TODO*
29* Automatic Decompression30* 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–82why, one step back
73## Dependencies
7475* `h11` - HTTP/1.1 support.76* `h2` - HTTP/2 support.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

Update READMETom Christiebefore adoption58461d4

lines 100–108why, one step back
100* `def __init__([ssl], [timeout], [pool_limits], [max_redirects], [dispatch])`
101* `def .request(method, url, [content], [query_params], [headers], [stream], [allow_redirects], [ssl], [timeout])`102* `def .get(url, [query_params], [headers], [stream], [allow_redirects], [ssl], [timeout])`103* `def .options(url, [query_params], [headers], [stream], [allow_redirects], [ssl], [timeout])`104* `def .head(url, [query_params], [headers], [stream], [allow_redirects], [ssl], [timeout])`105* `def .post(url, [content], [query_params], [headers], [stream], [allow_redirects], [ssl], [timeout])`106* `def .put(url, [content], [query_params], [headers], [stream], [allow_redirects], [ssl], [timeout])`107* `def .patch(url, [content], [query_params], [headers], [stream], [allow_redirects], [ssl], [timeout])`108* `def .delete(url, [content], [query_params], [headers], [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–129why, 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**128* `.cookies` - **Cookies** *TODO*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

Add query_params to URL and Request constructorsTom Christiebefore adoption6165459

line 148why, one step back
148* `def __init__(method, url, query_params, content, headers)`

Update READMETom Christiebefore adoptionfa8d296

lines 149–152why, one step back
149* `.method` - **str** (Uppercased)
150* `.url` - **URL**151* `.content` - **byte** or **byte async iterator**152* `.headers` - **Headers**

Truckin' onTom Christiebefore adoption6b60d95

line 153why, one step back
153

Reorganise structureTom Christiebefore adoption0c6f618

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

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoption891548e

lines 157–162why, one step back
157
158```python159>>> url = URL("https://example.org/")160>>> url.host161'example.org'162```

Truckin' onTom Christiebefore adoption6b60d95

line 163why, one step back
163

Add query_params to URL and Request constructorsTom Christiebefore adoption6165459

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

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoptionfa8d296

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

Truckin' onTom Christiebefore adoption6b60d95

line 179why, one step back
179

Reorganise structureTom Christiebefore adoption0c6f618

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

Truckin' onTom Christiebefore adoption6b60d95

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

Update README for 0.2.0Tom Christiebefore adoptionbb3d452

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

Truckin' onTom Christiebefore adoption6b60d95

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

README tweaksTom Christiebefore adoption8e1a263

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

Update READMETom Christiebefore adoption2de053e

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

Truckin' onTom Christiebefore adoption6b60d95

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 193why, one step back
193

Reorganise structureTom Christiebefore adoption0c6f618

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 195why, one step back
195

Truckin' onTom Christiebefore adoption6b60d95

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

Added proxy exampleTom Christiebefore adoption87b21b0

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

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoption2de053e

lines 203–204why, one step back
203
204* `def __init__(headers)`

Added proxy exampleTom Christiebefore adoption87b21b0

line 205why, one step back
205

Truckin' onTom Christiebefore adoption6b60d95

line 206why, one step back
206___

Added proxy exampleTom Christiebefore adoption87b21b0

line 207why, one step back
207

Truckin' onTom Christiebefore adoption6b60d95

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 209why, one step back
209

Update READMETom Christiebefore adoption58461d4

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 211why, one step back
211

Update READMETom Christiebefore adoption58461d4

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 213why, one step back
213

Truckin' onTom Christiebefore adoption6b60d95

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 215why, one step back
215

Truckin' onTom Christiebefore adoption6b60d95

line 216why, one step back
216*TODO*

Added proxy exampleTom Christiebefore adoption87b21b0

line 217why, one step back
217

Truckin' onTom Christiebefore adoption6b60d95

line 218why, one step back
218---

Added proxy exampleTom Christiebefore adoption87b21b0

line 219why, one step back
219

Truckin' onTom Christiebefore adoption6b60d95

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

Improve GatewayService exampleTom Christiebefore adoption9d59a5a

line 221why, one step back
221

Update READMETom Christiebefore adoption58461d4

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

Improve GatewayService exampleTom Christiebefore adoption9d59a5a

line 225why, one step back
225

Update READMETom Christiebefore adoption58461d4

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

Truckin' onTom Christiebefore adoption6b60d95

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