README.md
This file
Path
README.md
250 lines · 6.9 KiB · Markdown
Last changed by
TweakTom Christiebefore adoption52372ad
History of this fileTake it
StuffTom Christiebefore adoption30530d4
lines 1–2why, one step back1# HTTPCore2Merge pull request #43 from encode/badgesTom Christiebefore adoption3553625
lines 3–12why, one step back3<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>12Truckin' onTom Christiebefore adoption6b60d95
line 13why, one step back13## Feature supportUpdate READMETom Christiebefore adoption665743a
line 14why, one step back14Add cookie interfacesTom Christiebefore adoption0717998
line 15why, one step back15* `HTTP/2` and `HTTP/1.1` support.Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 16–17why, one step back16* `async`/`await` support for non-blocking HTTP requests.17* Strict timeouts everywhere by default.Truckin' onTom Christiebefore adoption6b60d95
line 18why, one step back18* Fully type annotated.Update README.mdTom Christiebefore adoption23e0786
line 19why, one step back19* 100% test coverage.Update READMETom Christiebefore adoption665743a
line 20why, one step back20Truckin' onTom Christiebefore adoption6b60d95
line 21why, one step back21Plus all the standard features of requests...Update READMETom Christiebefore adoption665743a
line 22why, one step back22Truckin' onTom Christiebefore adoption6b60d95
lines 23–24why, one step back23* International Domains and URLs24* Keep-Alive & Connection PoolingAdd cookie interfacesTom Christiebefore adoption0717998
line 25why, one step back25* Sessions with Cookie PersistenceTruckin' onTom Christiebefore adoption6b60d95
line 26why, one step back26* Browser-style SSL VerificationUpdate README.mdTom Christiebefore adoption144ce4f
line 27why, one step back27* Basic/Digest Authentication *TODO - We have Basic, but not Digest yet.*Add cookie interfacesTom Christiebefore adoption0717998
line 28why, one step back28* Elegant Key/Value CookiesTruckin' onTom Christiebefore adoption6b60d95
lines 29–31why, one step back29* Automatic Decompression30* Automatic Content Decoding31* Unicode Response BodiesUpdate README.mdTom Christiebefore adoption3408d7b
line 32why, one step back32* 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 back33* HTTP(S) Proxy Support *TODO*34* Connection Timeouts35* Streaming DownloadsUpdate READMETom Christiebefore adoption58461d4
line 36why, one step back36* .netrc Support *TODO*Truckin' onTom Christiebefore adoption6b60d95
line 37why, one step back37* Chunked RequestsUpdate READMETom Christiebefore adoption665743a
line 38why, one step back38Update README.mdTom Christiebefore adoption0d3eb0e
line 39why, one step back39## UsageUpdate README.mdTom Christiebefore adoption01a3c09
line 40why, one step back40Update README.mdTom Christiebefore adoption337eb70
lines 41–42why, one step back41Making a request:42StuffTom Christiebefore adoption30530d4
line 43why, one step back43```pythonTruckin' onTom Christiebefore adoption6b60d95
lines 44–45why, one step back44>>> import httpcore45>>> client = httpcore.Client()Update READMETom Christiebefore adoption58461d4
line 46why, one step back46>>> response = client.get('https://example.com')Truckin' onTom Christiebefore adoption6b60d95
line 47why, one step back47>>> response.status_codeMinor README tweakTom Christiebefore adoption813bb7c
line 48why, one step back48<HTTPStatus.OK: 200>Still truckin' onTom Christiebefore adoption6cb5c0d
lines 49–50why, one step back49>>> response.protocol50'HTTP/2'Truckin' onTom Christiebefore adoption6b60d95
lines 51–52why, one step back51>>> response.text52'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'StuffTom Christiebefore adoption30530d4
lines 53–54why, one step back53```54Update READMETom Christiebefore adoption58461d4
line 55why, one step back55Alternatively, async requests:StuffTom Christiebefore adoption30530d4
line 56why, one step back56Update READMETom Christiebefore adoption58461d4
lines 57–58why, one step back57**Note**: Use `ipython` to try this from the console, since it supports `await`.58StuffTom Christiebefore adoption30530d4
line 59why, one step back59```pythonTruckin' onTom Christiebefore adoption6b60d95
line 60why, one step back60>>> import httpcoreUpdate READMETom Christiebefore adoption58461d4
lines 61–62why, one step back61>>> client = httpcore.AsyncClient()62>>> response = await client.get('https://example.com')Truckin' onTom Christiebefore adoption6b60d95
line 63why, one step back63>>> response.status_codeMinor README tweakTom Christiebefore adoption813bb7c
line 64why, one step back64<HTTPStatus.OK: 200>Still truckin' onTom Christiebefore adoption6cb5c0d
lines 65–66why, one step back65>>> response.protocol66'HTTP/2'Truckin' onTom Christiebefore adoption6b60d95
lines 67–68why, one step back67>>> response.text68'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'StuffTom Christiebefore adoption30530d4
lines 69–70why, one step back69```70Truckin' onTom Christiebefore adoption6b60d95
line 71why, one step back71---StuffTom Christiebefore adoption30530d4
line 72why, one step back72Update READMETom Christiebefore adoption4fe2f69
lines 73–75why, one step back73## Dependencies7475* `h2` - HTTP/2 support.Add cookie interfacesTom Christiebefore adoption0717998
line 76why, one step back76* `h11` - HTTP/1.1 support.Update READMETom Christiebefore adoption4fe2f69
lines 77–82why, one step back77* `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)*82Update READMETom Christiebefore adoption58461d4
line 83why, one step back83A huge amount of credit is due to `requests` for the API layout thatUpdate README.mdTom Christiebefore adoption84b9691
lines 84–85why, one step back84much of this work follows, as well as to `urllib3` for plenty of design85inspiration around the lower level networking details.Update READMETom Christiebefore adoption4fe2f69
lines 86–88why, one step back8687---88Truckin' onTom Christiebefore adoption6b60d95
line 89why, one step back89## API ReferenceUpdate READMETom Christiebefore adoption68b80dc
line 90why, one step back90Reorganise structureTom Christiebefore adoption0c6f618
line 91why, one step back91### `Client`Update READMETom Christiebefore adoption68b80dc
line 92why, one step back92Update READMETom Christiebefore adoption891548e
lines 93–96why, one step back93*An HTTP client, with connection pooling, redirects, cookie persistence, etc.*9495```python96>>> client = Client()Update READMETom Christiebefore adoption441a1f6
line 97why, one step back97>>> response = client.get('https://example.org')Update READMETom Christiebefore adoption891548e
lines 98–99why, one step back98```99Add cookie interfacesTom Christiebefore adoption0717998
line 100why, one step back100* `def __init__([auth], [cookies], [ssl], [timeout], [pool_limits], [max_redirects], [dispatch])`TweakTom Christiebefore adoption52372ad
line 101why, one step back101* `def .request(method, url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`query_params -> paramsTom Christiebefore adoptionbb70377
lines 102–104why, one step back102* `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])`TweakTom Christiebefore adoption52372ad
lines 105–108why, one step back105* `def .post(url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`106* `def .put(url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`107* `def .patch(url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`108* `def .delete(url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [ssl], [timeout])`Still truckin' onTom Christiebefore adoption6cb5c0d
line 109why, one step back109* `def .prepare_request(request)`Update READMETom Christiebefore adoption58461d4
lines 110–111why, one step back110* `def .send(request, [stream], [allow_redirects], [ssl], [timeout])`111* `def .close()`Update README.mdTom Christiebefore adoption01a3c09
line 112why, one step back112Reorganise structureTom Christiebefore adoption0c6f618
line 113why, one step back113### `Response`README tweaksTom Christiebefore adoption8e1a263
line 114why, one step back114Update READMETom Christiebefore adoption4fe2f69
line 115why, one step back115*An HTTP response.*Still truckin' onTom Christiebefore adoption6cb5c0d
line 116why, one step back116Update READMETom Christiebefore adoption2de053e
line 117why, one step back117* `def __init__(...)`Truckin' onTom Christiebefore adoption6b60d95
lines 118–127why, one step back118* `.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 back128* `.cookies` - **Cookies**Truckin' onTom Christiebefore adoption6b60d95
line 129why, one step back129* `.history` - **List[Response]**Update README.mdTom Christiebefore adoption93d7ba3
line 130why, one step back130* `def .raise_for_status()` - **None**Update READMETom Christiebefore adoptionfa8d296
line 131why, one step back131* `def .json()` - **Any** *TODO*Update READMETom Christiebefore adoption58461d4
lines 132–136why, one step back132* `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 back137Reorganise structureTom Christiebefore adoption0c6f618
line 138why, one step back138### `Request`Truckin' onTom Christiebefore adoption6b60d95
line 139why, one step back139Still truckin' onTom Christiebefore adoption6cb5c0d
lines 140–143why, one step back140*An HTTP request. Can be constructed explicitly for more control over exactly141what gets sent over the wire.*142143```pythonUpdate READMETom Christiebefore adoption891548e
line 144why, one step back144>>> request = Request("GET", "https://example.org", headers={'host': 'example.org'})Update READMETom Christiebefore adoptiona5eb829
line 145why, one step back145>>> response = client.send(request)Still truckin' onTom Christiebefore adoption6cb5c0d
lines 146–147why, one step back146```147TweakTom Christiebefore adoption52372ad
line 148why, one step back148* `def __init__(method, url, [params], [data], [headers], [cookies])`TweakTom Christiebefore adoptionf6a2aef
line 149why, one step back149* `.method` - **str**Update READMETom Christiebefore adoptionfa8d296
lines 150–152why, one step back150* `.url` - **URL**151* `.content` - **byte** or **byte async iterator**152* `.headers` - **Headers**Add cookie interfacesTom Christiebefore adoption0717998
line 153why, one step back153* `.cookies` - **Cookies**Truckin' onTom Christiebefore adoption6b60d95
line 154why, one step back154Reorganise structureTom Christiebefore adoption0c6f618
line 155why, one step back155### `URL`Truckin' onTom Christiebefore adoption6b60d95
lines 156–157why, one step back156157*A normalized, IDNA supporting URL.*Update READMETom Christiebefore adoption891548e
lines 158–163why, one step back158159```python160>>> url = URL("https://example.org/")161>>> url.host162'example.org'163```Truckin' onTom Christiebefore adoption6b60d95
line 164why, one step back164query_params -> paramsTom Christiebefore adoptionbb70377
line 165why, one step back165* `def __init__(url, allow_relative=False, params=None)`Truckin' onTom Christiebefore adoption6b60d95
lines 166–177why, one step back166* `.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 back178* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**179* `def .resolve_with(url)` - **URL**Truckin' onTom Christiebefore adoption6b60d95
line 180why, one step back180Reorganise structureTom Christiebefore adoption0c6f618
line 181why, one step back181### `Origin`Truckin' onTom Christiebefore adoption6b60d95
lines 182–184why, one step back182183*A normalized, IDNA supporting set of scheme/host/port info.*184Update README for 0.2.0Tom Christiebefore adoptionbb3d452
line 185why, one step back185```pythonTruckin' onTom Christiebefore adoption6b60d95
lines 186–187why, one step back186>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')187TrueREADME tweaksTom Christiebefore adoption8e1a263
lines 188–189why, one step back188```189Update READMETom Christiebefore adoption2de053e
line 190why, one step back190* `def __init__(url)`Truckin' onTom Christiebefore adoption6b60d95
lines 191–193why, one step back191* `.is_ssl` - **bool**192* `.host` - **str**193* `.port` - **int**Added proxy exampleTom Christiebefore adoption87b21b0
line 194why, one step back194Reorganise structureTom Christiebefore adoption0c6f618
line 195why, one step back195### `Headers`Added proxy exampleTom Christiebefore adoption87b21b0
line 196why, one step back196Truckin' onTom Christiebefore adoption6b60d95
lines 197–198why, one step back197*A case-insensitive multi-dict.*198Added proxy exampleTom Christiebefore adoption87b21b0
line 199why, one step back199```pythonTruckin' onTom Christiebefore adoption6b60d95
lines 200–203why, one step back200>>> headers = Headers({'Content-Type': 'application/json'})201>>> headers['content-type']202'application/json'203```Update READMETom Christiebefore adoption2de053e
line 204why, one step back204Add cookie interfacesTom Christiebefore adoption0717998
lines 205–216why, one step back205* `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])`TweakTom Christiebefore adoption33a2249
line 217why, one step back217* `.jar` - **CookieJar**Add cookie interfacesTom Christiebefore adoption0717998
lines 218–224why, one step back218* `def extract_cookies(response)`219* `def set_cookie_header(request)`220* `def set(name, value, [domain], [path])`221* `def get(name, [domain], [path])`222* `def delete(name, [domain], [path])`223* `def clear([domain], [path])`224* *Standard mutable mapping interface*Added proxy exampleTom Christiebefore adoption87b21b0
line 225why, one step back225Truckin' onTom Christiebefore adoption6b60d95
line 226why, one step back226___Added proxy exampleTom Christiebefore adoption87b21b0
line 227why, one step back227Truckin' onTom Christiebefore adoption6b60d95
line 228why, one step back228## Alternate backendsAdded proxy exampleTom Christiebefore adoption87b21b0
line 229why, one step back229Update READMETom Christiebefore adoption58461d4
line 230why, one step back230### `AsyncClient`Added proxy exampleTom Christiebefore adoption87b21b0
line 231why, one step back231Update READMETom Christiebefore adoption58461d4
line 232why, one step back232An asyncio client.Added proxy exampleTom Christiebefore adoption87b21b0
line 233why, one step back233Truckin' onTom Christiebefore adoption6b60d95
line 234why, one step back234### `TrioClient`Added proxy exampleTom Christiebefore adoption87b21b0
line 235why, one step back235Truckin' onTom Christiebefore adoption6b60d95
line 236why, one step back236*TODO*Added proxy exampleTom Christiebefore adoption87b21b0
line 237why, one step back237Truckin' onTom Christiebefore adoption6b60d95
line 238why, one step back238---Added proxy exampleTom Christiebefore adoption87b21b0
line 239why, one step back239Truckin' onTom Christiebefore adoption6b60d95
line 240why, one step back240## The StackImprove GatewayService exampleTom Christiebefore adoption9d59a5a
line 241why, one step back241Update READMETom Christiebefore adoption58461d4
lines 242–244why, one step back242There are two main layers in the stack. The client handles redirection,243cookie persistence (TODO), and authentication (TODO). The dispatcher244handles sending the actual request and getting the response.Improve GatewayService exampleTom Christiebefore adoption9d59a5a
line 245why, one step back245Update READMETom Christiebefore adoption58461d4
lines 246–247why, one step back246* `Client` - Redirect, authentication, cookies etc.247* `ConnectionPool(Dispatcher)` - Connection pooling & keep alive.Truckin' onTom Christiebefore adoption6b60d95
lines 248–250why, one step back248 * `HTTPConnection` - A single connection.249 * `HTTP11Connection` - A single HTTP/1.1 connection.250 * `HTTP2Connection` - A single HTTP/2 connection, with multiple streams.