README.md
This file
Path
README.md
228 lines · 6.3 KiB · Markdown
Last changed by
Update READMETom Christiebefore adoption2de053e
History of this fileTake it
StuffTom Christiebefore adoption30530d4
lines 1–2why, one step back1# HTTPCore2Truckin' onTom Christiebefore adoption6b60d95
line 3why, one step back3A proposal for [requests III](https://github.com/kennethreitz/requests3).Update READMETom Christiebefore adoption665743a
line 4why, one step back4Truckin' onTom Christiebefore adoption6b60d95
line 5why, one step back5## Feature supportUpdate READMETom Christiebefore adoption665743a
line 6why, one step back6Truckin' onTom Christiebefore adoption6b60d95
lines 7–10why, one step back7* `HTTP/1.1` and `HTTP/2` Support.8* `async`/`await` support for non-thread-blocking HTTP requests.9* Fully type annotated.10* 100% test coverage. *TODO - We're on ~97% right now*Update READMETom Christiebefore adoption665743a
line 11why, one step back11Truckin' onTom Christiebefore adoption6b60d95
line 12why, one step back12Plus all the standard features of requests...Update READMETom Christiebefore adoption665743a
line 13why, one step back13Truckin' onTom Christiebefore adoption6b60d95
lines 14–15why, one step back14* International Domains and URLs15* Keep-Alive & Connection PoolingUpdate READMETom Christiebefore adoptionfa8d296
line 16why, one step back16* Sessions with Cookie Persistence *TODO - Requires `adapters/cookies.py` implementation.*Truckin' onTom Christiebefore adoption6b60d95
line 17why, one step back17* Browser-style SSL VerificationUpdate READMETom Christiebefore adoptionfa8d296
line 18why, one step back18* Basic/Digest Authentication *TODO - Requires `adapters/authentication.py` implementation.*Truckin' onTom Christiebefore adoption6b60d95
lines 19–22why, one step back19* Elegant Key/Value Cookies *TODO*20* Automatic Decompression21* Automatic Content Decoding22* Unicode Response BodiesUpdate READMETom Christiebefore adoptionfa8d296
line 23why, one step back23* Multipart File Uploads *TODO - Request content currently supports bytes or async byte iterators.*Truckin' onTom Christiebefore adoption6b60d95
lines 24–26why, one step back24* HTTP(S) Proxy Support *TODO*25* Connection Timeouts26* Streaming DownloadsUpdate READMETom Christiebefore adoptionfa8d296
line 27why, one step back27* .netrc Support *TODO - Requires `adapters/environment.py` implementation.*Truckin' onTom Christiebefore adoption6b60d95
line 28why, one step back28* Chunked RequestsUpdate READMETom Christiebefore adoption665743a
line 29why, one step back29Update README.mdTom Christiebefore adoption0d3eb0e
line 30why, one step back30## UsageUpdate README.mdTom Christiebefore adoption01a3c09
line 31why, one step back31Update READMETom Christiebefore adoptionfa8d296
lines 32–33why, one step back32**Note**: Use `ipython` to try this from the console, since it supports `await`.33Update README.mdTom Christiebefore adoption337eb70
lines 34–35why, one step back34Making a request:35StuffTom Christiebefore adoption30530d4
line 36why, one step back36```pythonTruckin' onTom Christiebefore adoption6b60d95
lines 37–38why, one step back37>>> import httpcore38>>> client = httpcore.Client()Still truckin' onTom Christiebefore adoption6cb5c0d
line 39why, one step back39>>> response = await client.get('https://example.com')Truckin' onTom Christiebefore adoption6b60d95
lines 40–41why, one step back40>>> response.status_code41<StatusCode.ok: 200>Still truckin' onTom Christiebefore adoption6cb5c0d
lines 42–43why, one step back42>>> response.protocol43'HTTP/2'Truckin' onTom Christiebefore adoption6b60d95
lines 44–45why, one step back44>>> response.text45'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'StuffTom Christiebefore adoption30530d4
lines 46–47why, one step back46```47Truckin' onTom Christiebefore adoption6b60d95
line 48why, one step back48Alternatively, thread-synchronous requests:StuffTom Christiebefore adoption30530d4
lines 49–50why, one step back4950```pythonTruckin' onTom Christiebefore adoption6b60d95
lines 51–52why, one step back51>>> import httpcore52>>> client = httpcore.SyncClient()Still truckin' onTom Christiebefore adoption6cb5c0d
line 53why, one step back53>>> response = client.get('https://example.com')Truckin' onTom Christiebefore adoption6b60d95
lines 54–55why, one step back54>>> response.status_code55<StatusCode.ok: 200>Still truckin' onTom Christiebefore adoption6cb5c0d
lines 56–57why, one step back56>>> response.protocol57'HTTP/2'Truckin' onTom Christiebefore adoption6b60d95
lines 58–59why, one step back58>>> response.text59'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'StuffTom Christiebefore adoption30530d4
lines 60–61why, one step back60```61Truckin' onTom Christiebefore adoption6b60d95
line 62why, one step back62---StuffTom Christiebefore adoption30530d4
line 63why, one step back63Update READMETom Christiebefore adoption4fe2f69
lines 64–77why, one step back64## Dependencies6566* `h11` - HTTP/1.1 support.67* `h2` - HTTP/2 support.68* `certifi` - SSL certificates.69* `chardet` - Fallback auto-detection for response encoding.70* `idna` - Internationalized domain name support.71* `rfc3986` - URL parsing & normalization.72* `brotlipy` - Decoding for "brotli" compressed responses. *(Optional)*7374Additionally, credit is due to for `urllib3` for plenty of design inspiration.7576---77Truckin' onTom Christiebefore adoption6b60d95
line 78why, one step back78## API ReferenceUpdate READMETom Christiebefore adoption68b80dc
line 79why, one step back79Update READMETom Christiebefore adoption2de053e
line 80why, one step back80#### ClientUpdate READMETom Christiebefore adoption68b80dc
line 81why, one step back81Update READMETom Christiebefore adoption891548e
lines 82–88why, one step back82*An HTTP client, with connection pooling, redirects, cookie persistence, etc.*8384```python85>>> client = Client()86>>> response = await client.get('https://example.org')87```88Update READMETom Christiebefore adoption2de053e
line 89why, one step back89* `def __init__([ssl], [timeout], [pool_limits], [max_redirects])`Update READMETom Christiebefore adoption4fe2f69
lines 90–97why, one step back90* `async def .request(method, url, [content], [headers], [stream], [allow_redirects], [ssl], [timeout])`91* `async def .get(url, [headers], [stream], [allow_redirects], [ssl], [timeout])`92* `async def .options(url, [headers], [stream], [allow_redirects], [ssl], [timeout])`93* `async def .head(url, [headers], [stream], [allow_redirects], [ssl], [timeout])`94* `async def .post(url, [content], [headers], [stream], [allow_redirects], [ssl], [timeout])`95* `async def .put(url, [content], [headers], [stream], [allow_redirects], [ssl], [timeout])`96* `async def .patch(url, [content], [headers], [stream], [allow_redirects], [ssl], [timeout])`97* `async def .delete(url, [content], [headers], [stream], [allow_redirects], [ssl], [timeout])`Still truckin' onTom Christiebefore adoption6cb5c0d
line 98why, one step back98* `def .prepare_request(request)`Update READMETom Christiebefore adoption4fe2f69
line 99why, one step back99* `async def .send(request, [stream], [allow_redirects], [ssl], [timeout])`Still truckin' onTom Christiebefore adoption6cb5c0d
line 100why, one step back100* `async def .close()`Update README.mdTom Christiebefore adoption01a3c09
line 101why, one step back101Truckin' onTom Christiebefore adoption6b60d95
line 102why, one step back102### ModelsREADME tweaksTom Christiebefore adoption8e1a263
line 103why, one step back103Update READMETom Christiebefore adoption891548e
lines 104–105why, one step back104*Data-structures for HTTP primitives...*105Update READMETom Christiebefore adoption2de053e
line 106why, one step back106#### ResponseUpdate README for 0.2.0Tom Christiebefore adoptionbb3d452
line 107why, one step back107Update READMETom Christiebefore adoption4fe2f69
line 108why, one step back108*An HTTP response.*Still truckin' onTom Christiebefore adoption6cb5c0d
line 109why, one step back109Update READMETom Christiebefore adoption2de053e
line 110why, one step back110* `def __init__(...)`Truckin' onTom Christiebefore adoption6b60d95
lines 111–122why, one step back111* `.status_code` - **int**112* `.reason_phrase` - **str**113* `.protocol` - `"HTTP/2"` or `"HTTP/1.1"`114* `.url` - **URL**115* `.headers` - **Headers**116* `.content` - **bytes**117* `.text` - **str**118* `.encoding` - **str**119* `.is_redirect` - **bool**120* `.request` - **Request**121* `.cookies` - **Cookies** *TODO*122* `.history` - **List[Response]**Update READMETom Christiebefore adoptionfa8d296
lines 123–130why, one step back123* `def .raise_for_status()` - **Response** *TODO*124* `def .json()` - **Any** *TODO*125* `async def .read()` - **bytes**126* `async def .stream()` - **bytes iterator**127* `async def .raw()` - **bytes iterator**128* `async def .close()` - **None**129* `async def .next()` - **Response**130Update READMETom Christiebefore adoption2de053e
line 131why, one step back131#### RequestTruckin' onTom Christiebefore adoption6b60d95
line 132why, one step back132Still truckin' onTom Christiebefore adoption6cb5c0d
lines 133–136why, one step back133*An HTTP request. Can be constructed explicitly for more control over exactly134what gets sent over the wire.*135136```pythonUpdate READMETom Christiebefore adoption891548e
line 137why, one step back137>>> request = Request("GET", "https://example.org", headers={'host': 'example.org'})Still truckin' onTom Christiebefore adoption6cb5c0d
lines 138–140why, one step back138>>> response = await client.send(request)139```140Update READMETom Christiebefore adoption2de053e
line 141why, one step back141* `def __init__(method, url, content, headers)`Update READMETom Christiebefore adoptionfa8d296
lines 142–145why, one step back142* `.method` - **str** (Uppercased)143* `.url` - **URL**144* `.content` - **byte** or **byte async iterator**145* `.headers` - **Headers**Truckin' onTom Christiebefore adoption6b60d95
line 146why, one step back146Update READMETom Christiebefore adoption2de053e
line 147why, one step back147#### URLTruckin' onTom Christiebefore adoption6b60d95
lines 148–149why, one step back148149*A normalized, IDNA supporting URL.*Update READMETom Christiebefore adoption891548e
lines 150–155why, one step back150151```python152>>> url = URL("https://example.org/")153>>> url.host154'example.org'155```Truckin' onTom Christiebefore adoption6b60d95
line 156why, one step back156Update READMETom Christiebefore adoption2de053e
line 157why, one step back157* `def __init__(url, allow_relative=False)`Truckin' onTom Christiebefore adoption6b60d95
lines 158–169why, one step back158* `.scheme` - **str**159* `.authority` - **str**160* `.host` - **str**161* `.port` - **int**162* `.path` - **str**163* `.query` - **str**164* `.full_path` - **str**165* `.fragment` - **str**166* `.is_ssl` - **bool**167* `.origin` - **Origin**168* `.is_absolute_url` - **bool**169* `.is_relative_url` - **bool**Update READMETom Christiebefore adoptionfa8d296
lines 170–171why, one step back170* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**171* `def .resolve_with(url)` - **URL**Truckin' onTom Christiebefore adoption6b60d95
line 172why, one step back172Update READMETom Christiebefore adoption2de053e
line 173why, one step back173#### OriginTruckin' onTom Christiebefore adoption6b60d95
lines 174–176why, one step back174175*A normalized, IDNA supporting set of scheme/host/port info.*176Update README for 0.2.0Tom Christiebefore adoptionbb3d452
line 177why, one step back177```pythonTruckin' onTom Christiebefore adoption6b60d95
lines 178–179why, one step back178>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')179TrueREADME tweaksTom Christiebefore adoption8e1a263
lines 180–181why, one step back180```181Update READMETom Christiebefore adoption2de053e
line 182why, one step back182* `def __init__(url)`Truckin' onTom Christiebefore adoption6b60d95
lines 183–185why, one step back183* `.is_ssl` - **bool**184* `.host` - **str**185* `.port` - **int**Added proxy exampleTom Christiebefore adoption87b21b0
line 186why, one step back186Update READMETom Christiebefore adoption2de053e
line 187why, one step back187#### `Headers`Added proxy exampleTom Christiebefore adoption87b21b0
line 188why, one step back188Truckin' onTom Christiebefore adoption6b60d95
lines 189–190why, one step back189*A case-insensitive multi-dict.*190Added proxy exampleTom Christiebefore adoption87b21b0
line 191why, one step back191```pythonTruckin' onTom Christiebefore adoption6b60d95
lines 192–195why, one step back192>>> headers = Headers({'Content-Type': 'application/json'})193>>> headers['content-type']194'application/json'195```Update READMETom Christiebefore adoption2de053e
lines 196–197why, one step back196197* `def __init__(headers)`Added proxy exampleTom Christiebefore adoption87b21b0
line 198why, one step back198Truckin' onTom Christiebefore adoption6b60d95
line 199why, one step back199___Added proxy exampleTom Christiebefore adoption87b21b0
line 200why, one step back200Truckin' onTom Christiebefore adoption6b60d95
line 201why, one step back201## Alternate backendsAdded proxy exampleTom Christiebefore adoption87b21b0
line 202why, one step back202Truckin' onTom Christiebefore adoption6b60d95
line 203why, one step back203### `SyncClient`Added proxy exampleTom Christiebefore adoption87b21b0
line 204why, one step back204Truckin' onTom Christiebefore adoption6b60d95
line 205why, one step back205A thread-synchronous client.Added proxy exampleTom Christiebefore adoption87b21b0
line 206why, one step back206Truckin' onTom Christiebefore adoption6b60d95
line 207why, one step back207### `TrioClient`Added proxy exampleTom Christiebefore adoption87b21b0
line 208why, one step back208Truckin' onTom Christiebefore adoption6b60d95
line 209why, one step back209*TODO*Added proxy exampleTom Christiebefore adoption87b21b0
line 210why, one step back210Truckin' onTom Christiebefore adoption6b60d95
line 211why, one step back211---Added proxy exampleTom Christiebefore adoption87b21b0
line 212why, one step back212Truckin' onTom Christiebefore adoption6b60d95
line 213why, one step back213## The StackImprove GatewayService exampleTom Christiebefore adoption9d59a5a
line 214why, one step back214Truckin' onTom Christiebefore adoption6b60d95
line 215why, one step back215The `httpcore` client builds up behavior in a modular way.Improve GatewayService exampleTom Christiebefore adoption9d59a5a
line 216why, one step back216Truckin' onTom Christiebefore adoption6b60d95
line 217why, one step back217This 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 218why, one step back218Truckin' onTom Christiebefore adoption6b60d95
line 219why, one step back219You 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 220why, one step back220Truckin' onTom Christiebefore adoption6b60d95
lines 221–228why, one step back221* `RedirectAdapter` - Adds redirect support.222* `EnvironmentAdapter` - Adds `.netrc` and envvars such as `REQUESTS_CA_BUNDLE`.223* `CookieAdapter` - Adds cookie persistence.224* `AuthAdapter` - Adds authentication support.225* `ConnectionPool` - Connection pooling & keep alive.226 * `HTTPConnection` - A single connection.227 * `HTTP11Connection` - A single HTTP/1.1 connection.228 * `HTTP2Connection` - A single HTTP/2 connection, with multiple streams.