Skip to content
Myr

README.md

This file

Path

README.md

234 lines · 6.8 KiB · Markdown

Last changed by

Update README.mdTom Christiebefore adoption3408d7b

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
13A proposal for [requests III](https://github.com/kennethreitz/requests3).

Update READMETom Christiebefore adoption665743a

line 14why, one step back
14

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoption665743a

line 16why, one step back
16

Truckin' onTom Christiebefore adoption6b60d95

lines 17–19why, one step back
17* `HTTP/1.1` and `HTTP/2` Support.
18* `async`/`await` support for non-thread-blocking HTTP requests.19* Fully type annotated.

Update README.mdTom Christiebefore adoptiond7f2478

line 20why, one step back
20* 100% test coverage. *TODO - Almost there.*

Update READMETom Christiebefore adoption665743a

line 21why, one step back
21

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoption665743a

line 23why, one step back
23

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoptionfa8d296

line 26why, one step back
26* Sessions with Cookie Persistence *TODO - Requires `adapters/cookies.py` implementation.*

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoptionfa8d296

line 28why, one step back
28* Basic/Digest Authentication *TODO - Requires `adapters/authentication.py` implementation.*

Truckin' onTom Christiebefore adoption6b60d95

lines 29–32why, one step back
29* Elegant Key/Value Cookies *TODO*
30* Automatic Decompression31* Automatic Content Decoding32* Unicode Response Bodies

Update README.mdTom Christiebefore adoption3408d7b

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

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoptionfa8d296

line 37why, one step back
37* .netrc Support *TODO - Requires `adapters/environment.py` implementation.*

Truckin' onTom Christiebefore adoption6b60d95

line 38why, one step back
38* Chunked Requests

Update READMETom Christiebefore adoption665743a

line 39why, one step back
39

Update README.mdTom Christiebefore adoption0d3eb0e

line 40why, one step back
40## Usage

Update README.mdTom Christiebefore adoption01a3c09

line 41why, one step back
41

Update READMETom Christiebefore adoptionfa8d296

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

Update README.mdTom Christiebefore adoption337eb70

lines 44–45why, one step back
44Making a request:
45

StuffTom Christiebefore adoption30530d4

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

Truckin' onTom Christiebefore adoption6b60d95

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

Still truckin' onTom Christiebefore adoption6cb5c0d

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

Truckin' onTom Christiebefore adoption6b60d95

lines 50–51why, one step back
50>>> response.status_code
51<StatusCode.ok: 200>

Still truckin' onTom Christiebefore adoption6cb5c0d

lines 52–53why, one step back
52>>> response.protocol
53'HTTP/2'

Truckin' onTom Christiebefore adoption6b60d95

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

StuffTom Christiebefore adoption30530d4

lines 56–57why, one step back
56```
57

Truckin' onTom Christiebefore adoption6b60d95

line 58why, one step back
58Alternatively, thread-synchronous requests:

StuffTom Christiebefore adoption30530d4

lines 59–60why, one step back
59
60```python

Truckin' onTom Christiebefore adoption6b60d95

lines 61–62why, one step back
61>>> import httpcore
62>>> client = httpcore.SyncClient()

Still truckin' onTom Christiebefore adoption6cb5c0d

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

Truckin' onTom Christiebefore adoption6b60d95

lines 64–65why, one step back
64>>> response.status_code
65<StatusCode.ok: 200>

Still truckin' onTom Christiebefore adoption6cb5c0d

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

Truckin' onTom Christiebefore adoption6b60d95

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

StuffTom Christiebefore adoption30530d4

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

Truckin' onTom Christiebefore adoption6b60d95

line 72why, one step back
72---

StuffTom Christiebefore adoption30530d4

line 73why, one step back
73

Update READMETom Christiebefore adoption4fe2f69

lines 74–87why, one step back
74## Dependencies
7576* `h11` - HTTP/1.1 support.77* `h2` - HTTP/2 support.78* `certifi` - SSL certificates.79* `chardet` - Fallback auto-detection for response encoding.80* `idna` - Internationalized domain name support.81* `rfc3986` - URL parsing & normalization.82* `brotlipy` - Decoding for "brotli" compressed responses. *(Optional)*8384Additionally, credit is due to for `urllib3` for plenty of design inspiration.8586---87

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoption68b80dc

line 89why, one step back
89

Reorganise structureTom Christiebefore adoption0c6f618

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

Update READMETom Christiebefore adoption68b80dc

line 91why, one step back
91

Update READMETom Christiebefore adoption891548e

lines 92–98why, one step back
92*An HTTP client, with connection pooling, redirects, cookie persistence, etc.*
9394```python95>>> client = Client()96>>> response = await client.get('https://example.org')97```98

Update READMETom Christiebefore adoption2de053e

line 99why, one step back
99* `def __init__([ssl], [timeout], [pool_limits], [max_redirects])`

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

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

Still truckin' onTom Christiebefore adoption6cb5c0d

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

Update READMETom Christiebefore adoption4fe2f69

line 109why, one step back
109* `async def .send(request, [stream], [allow_redirects], [ssl], [timeout])`

Still truckin' onTom Christiebefore adoption6cb5c0d

line 110why, one step back
110* `async def .close()`

Update README.mdTom Christiebefore adoption01a3c09

line 111why, one step back
111

Reorganise structureTom Christiebefore adoption0c6f618

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

README tweaksTom Christiebefore adoption8e1a263

line 113why, one step back
113

Update READMETom Christiebefore adoption4fe2f69

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

Still truckin' onTom Christiebefore adoption6cb5c0d

line 115why, one step back
115

Update READMETom Christiebefore adoption2de053e

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

Truckin' onTom Christiebefore adoption6b60d95

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

Update README.mdTom Christiebefore adoption93d7ba3

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

Update READMETom Christiebefore adoptionfa8d296

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

Reorganise structureTom Christiebefore adoption0c6f618

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

Truckin' onTom Christiebefore adoption6b60d95

line 138why, one step back
138

Still truckin' onTom Christiebefore adoption6cb5c0d

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

Update READMETom Christiebefore adoption891548e

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

Still truckin' onTom Christiebefore adoption6cb5c0d

lines 144–146why, one step back
144>>> response = await client.send(request)
145```146

Add query_params to URL and Request constructorsTom Christiebefore adoption6165459

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

Update READMETom Christiebefore adoptionfa8d296

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

Truckin' onTom Christiebefore adoption6b60d95

line 152why, one step back
152

Reorganise structureTom Christiebefore adoption0c6f618

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

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoption891548e

lines 156–161why, one step back
156
157```python158>>> url = URL("https://example.org/")159>>> url.host160'example.org'161```

Truckin' onTom Christiebefore adoption6b60d95

line 162why, one step back
162

Add query_params to URL and Request constructorsTom Christiebefore adoption6165459

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

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoptionfa8d296

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

Truckin' onTom Christiebefore adoption6b60d95

line 178why, one step back
178

Reorganise structureTom Christiebefore adoption0c6f618

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

Truckin' onTom Christiebefore adoption6b60d95

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

Update README for 0.2.0Tom Christiebefore adoptionbb3d452

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

Truckin' onTom Christiebefore adoption6b60d95

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

README tweaksTom Christiebefore adoption8e1a263

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

Update READMETom Christiebefore adoption2de053e

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

Truckin' onTom Christiebefore adoption6b60d95

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 192why, one step back
192

Reorganise structureTom Christiebefore adoption0c6f618

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 194why, one step back
194

Truckin' onTom Christiebefore adoption6b60d95

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

Added proxy exampleTom Christiebefore adoption87b21b0

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

Truckin' onTom Christiebefore adoption6b60d95

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

Update READMETom Christiebefore adoption2de053e

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 204why, one step back
204

Truckin' onTom Christiebefore adoption6b60d95

line 205why, one step back
205___

Added proxy exampleTom Christiebefore adoption87b21b0

line 206why, one step back
206

Truckin' onTom Christiebefore adoption6b60d95

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 208why, one step back
208

Truckin' onTom Christiebefore adoption6b60d95

line 209why, one step back
209### `SyncClient`

Added proxy exampleTom Christiebefore adoption87b21b0

line 210why, one step back
210

Truckin' onTom Christiebefore adoption6b60d95

line 211why, one step back
211A thread-synchronous client.

Added proxy exampleTom Christiebefore adoption87b21b0

line 212why, one step back
212

Truckin' onTom Christiebefore adoption6b60d95

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

Added proxy exampleTom Christiebefore adoption87b21b0

line 214why, one step back
214

Truckin' onTom Christiebefore adoption6b60d95

line 215why, one step back
215*TODO*

Added proxy exampleTom Christiebefore adoption87b21b0

line 216why, one step back
216

Truckin' onTom Christiebefore adoption6b60d95

line 217why, one step back
217---

Added proxy exampleTom Christiebefore adoption87b21b0

line 218why, one step back
218

Truckin' onTom Christiebefore adoption6b60d95

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

Improve GatewayService exampleTom Christiebefore adoption9d59a5a

line 220why, one step back
220

Truckin' onTom Christiebefore adoption6b60d95

line 221why, one step back
221The `httpcore` client builds up behavior in a modular way.

Improve GatewayService exampleTom Christiebefore adoption9d59a5a

line 222why, one step back
222

Truckin' onTom Christiebefore adoption6b60d95

line 223why, one step back
223This makes it easier to dig into an understand the behaviour of any one aspect in isolation, as well as making it easier to test or to adapt for custom behaviors.

Added proxy exampleTom Christiebefore adoption87b21b0

line 224why, one step back
224

Truckin' onTom Christiebefore adoption6b60d95

line 225why, one step back
225You can also use lower level components in isolation if required, eg. Use a `ConnectionPool` without providing sessions, redirects etc...

Added proxy exampleTom Christiebefore adoption87b21b0

line 226why, one step back
226

Truckin' onTom Christiebefore adoption6b60d95

lines 227–234why, one step back
227* `RedirectAdapter` - Adds redirect support.
228* `EnvironmentAdapter` - Adds `.netrc` and envvars such as `REQUESTS_CA_BUNDLE`.229* `CookieAdapter` - Adds cookie persistence.230* `AuthAdapter` - Adds authentication support.231* `ConnectionPool` - Connection pooling & keep alive.232 * `HTTPConnection` - A single connection.233 * `HTTP11Connection` - A single HTTP/1.1 connection.234 * `HTTP2Connection` - A single HTTP/2 connection, with multiple streams.