Skip to content

Commit 3db3087

Browse files
Migrate docs to Sphinx + MyST
1 parent ebfaaa5 commit 3db3087

File tree

11 files changed

+269
-226
lines changed

11 files changed

+269
-226
lines changed

docs/api.md

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,68 @@
22

33
## Async API Overview
44

5+
### Base interfaces
6+
57
The `AsyncHTTPTransport` and `AsyncByteStream` classes provide the base
68
interface which transport classes need to implement.
79

8-
::: httpcore.AsyncHTTPTransport
9-
:docstring:
10-
:members: arequest aclose
10+
<!-- See: https://myst-parser.readthedocs.io/en/latest/using/howto.html#use-sphinx-ext-autodoc-in-markdown-files -->
11+
12+
```{eval-rst}
13+
.. autoclass:: httpcore.AsyncHTTPTransport
14+
:members: arequest, aclose
1115
12-
::: httpcore.AsyncByteStream
13-
:docstring:
14-
:members: __aiter__ aclose
16+
.. autoclass:: httpcore.AsyncByteStream
17+
:members: __aiter__, aclose
18+
```
1519

16-
The `AsyncConnectionPool` class is a concrete implementation of `AsyncHTTPTransport`.
20+
### Connection pool
1721

18-
::: httpcore.AsyncConnectionPool
19-
:docstring:
22+
The {class}`AsyncConnectionPool <httpcore.AsyncConnectionPool>` class is a concrete implementation of {class}`AsyncHTTPTransport <httpcore.AsyncHTTPTransport>`.
2023

24+
```{eval-rst}
25+
.. autoclass:: httpcore.AsyncConnectionPool
26+
```
2127

22-
The `PlainByteStream` and `AsyncIteratorByteStream` classes are concrete implementations of `AsyncByteStream`.
28+
### Byte streams
2329

24-
::: httpcore.PlainByteStream
25-
:docstring:
30+
The {class}`PlainByteStream <httpcore.PlainByteStream>` and {class}`AsyncIteratorByteStream <httpcore.AsyncIteratorByteStream>` classes are concrete implementations of `AsyncByteStream`.
2631

27-
::: httpcore.AsyncIteratorByteStream
28-
:docstring:
32+
```{eval-rst}
33+
.. autoclass:: httpcore.PlainByteStream
2934
30-
---
35+
.. autoclass:: httpcore.AsyncIteratorByteStream
36+
```
3137

3238
## Sync API Overview
3339

34-
The `SyncHTTPTransport` and `SyncByteStream` classes provide the base
35-
interface which transport classes need to implement.
40+
### Base interfaces
41+
42+
The {class}`SyncHTTPTransport <httpcore.SyncHTTPTransport>` and {class}`SyncByteStream <httpcore.SyncByteStream>` classes provide the base interface which transport classes need to implement.
43+
44+
```{eval-rst}
45+
.. autoclass:: httpcore.SyncHTTPTransport
46+
:members: request, close
47+
48+
.. autoclass:: httpcore.SyncByteStream
49+
:members: __iter__, close
50+
```
3651

37-
::: httpcore.SyncHTTPTransport
38-
:docstring:
39-
:members: request close
52+
### Connection pool
4053

41-
::: httpcore.SyncByteStream
42-
:docstring:
43-
:members: __iter__ close
54+
The {class}`SyncConnectionPool <httpcore.SyncConnectionPool>` class is a concrete implementation of {class}`SyncHTTPTransport <httpcore.SyncHTTPTransport>`.
4455

45-
The `SyncConnectionPool` class is a concrete implementation of `SyncHTTPTransport`.
56+
```{eval-rst}
57+
.. autoclass:: httpcore.SyncConnectionPool
58+
```
4659

47-
::: httpcore.SyncConnectionPool
48-
:docstring:
60+
### Byte streams
4961

50-
The `PlainByteStream` and `IteratorByteStream` classes are concrete implementations of `SyncByteStream`.
62+
The {class}`PlainByteStream <httpcore.PlainByteStream>` and {class}`IteratorByteStream <httpcore.IteratorByteStream>` classes are concrete implementations of `SyncByteStream`.
5163

52-
::: httpcore.PlainByteStream
53-
:docstring:
64+
```{eval-rst}
65+
.. autoclass:: httpcore.PlainByteStream
66+
:noindex:
5467
55-
::: httpcore.IteratorByteStream
56-
:docstring:
68+
.. autoclass:: httpcore.IteratorByteStream
69+
```

docs/conf.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
import os
14+
import sys
15+
sys.path.insert(0, os.path.abspath('.'))
16+
17+
# -- Project information -----------------------------------------------------
18+
19+
project = "HTTPCore"
20+
copyright = "2021, Encode"
21+
author = "Encode"
22+
23+
# -- General configuration ---------------------------------------------------
24+
25+
# Add any Sphinx extension module names here, as strings. They can be
26+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
27+
# ones.
28+
extensions = ["myst_parser", "sphinx.ext.autodoc", "sphinx.ext.napoleon"]
29+
30+
# Prevent sphinx-autodoc from ordering autodoc members alphabetically.
31+
# Instead use whichever order is defined by :members:.
32+
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_member_order
33+
autodoc_member_order = "bysource"
34+
35+
# Add any paths that contain templates here, relative to this directory.
36+
templates_path = ["_templates"]
37+
38+
# List of patterns, relative to source directory, that match files and
39+
# directories to ignore when looking for source files.
40+
# This pattern also affects html_static_path and html_extra_path.
41+
exclude_patterns = []
42+
43+
# -- Options for HTML output -------------------------------------------------
44+
45+
# The theme to use for HTML and HTML Help pages. See the documentation for
46+
# a list of builtin themes.
47+
#
48+
html_theme = "furo"
49+
50+
# Add any paths that contain custom static files (such as style sheets) here,
51+
# relative to this directory. They are copied after the builtin static files,
52+
# so a file named "default.css" will overwrite the builtin "default.css".
53+
html_static_path = []

docs/css/custom.css

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/index.md

Lines changed: 13 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,21 @@
1-
# HTTP Core
2-
3-
[![Test Suite](https://github.com/encode/httpcore/workflows/Test%20Suite/badge.svg)](https://github.com/encode/httpcore/actions)
4-
[![Package version](https://badge.fury.io/py/httpcore.svg)](https://pypi.org/project/httpcore/)
5-
6-
> *Do one thing, and do it well.*
7-
8-
The HTTP Core package provides a minimal low-level HTTP client, which does
9-
one thing only. Sending HTTP requests.
10-
11-
It does not provide any high level model abstractions over the API,
12-
does not handle redirects, multipart uploads, building authentication headers,
13-
transparent HTTP caching, URL parsing, session cookie handling,
14-
content or charset decoding, handling JSON, environment based configuration
15-
defaults, or any of that Jazz.
16-
17-
Some things HTTP Core does do:
18-
19-
* Sending HTTP requests.
20-
* Provides both sync and async interfaces.
21-
* Supports HTTP/1.1 and HTTP/2.
22-
* Async backend support for `asyncio`, `trio` and `curio`.
23-
* Automatic connection pooling.
24-
* HTTP(S) proxy support.
25-
26-
## Installation
27-
28-
For HTTP/1.1 only support, install with...
29-
30-
```shell
31-
$ pip install httpcore
32-
```
33-
34-
For HTTP/1.1 and HTTP/2 support, install with...
35-
36-
```shell
37-
$ pip install httpcore[http2]
1+
```{include} ../README.md
382
```
393

40-
## Quickstart
41-
42-
Here's an example of making an HTTP GET request using `httpcore`...
4+
<!-- Table of Content entries, shown in left sidebar. -->
435

44-
```python
45-
with httpcore.SyncConnectionPool() as http:
46-
status_code, headers, stream, ext = http.request(
47-
method=b'GET',
48-
url=(b'https', b'example.org', 443, b'/'),
49-
headers=[(b'host', b'example.org'), (b'user-agent', 'httpcore')]
50-
)
6+
```{toctree}
7+
:hidden:
8+
:caption: Usage
519
52-
try:
53-
body = b''.join([chunk for chunk in stream])
54-
finally:
55-
stream.close()
56-
57-
print(status_code, body)
10+
api
5811
```
5912

60-
Or, using async...
61-
62-
```python
63-
async with httpcore.AsyncConnectionPool() as http:
64-
status_code, headers, stream, ext = await http.arequest(
65-
method=b'GET',
66-
url=(b'https', b'example.org', 443, b'/'),
67-
headers=[(b'host', b'example.org'), (b'user-agent', 'httpcore')]
68-
)
13+
```{toctree}
14+
:hidden:
15+
:caption: Development
6916
70-
try:
71-
body = b''.join([chunk async for chunk in stream])
72-
finally:
73-
await stream.aclose()
74-
75-
print(status_code, body)
17+
contributing
18+
Changelog <https://github.com/encode/httpcore/blob/master/CHANGELOG.md>
19+
License <https://github.com/encode/httpcore/blob/master/LICENSE.md>
20+
Source Code <https://github.com/encode/httpcore>
7621
```
77-
78-
## Motivation
79-
80-
You probably don't want to be using HTTP Core directly. It might make sense if
81-
you're writing something like a proxy service in Python, and you just want
82-
something at the lowest possible level, but more typically you'll want to use
83-
a higher level client library, such as `httpx`.
84-
85-
The motivation for `httpcore` is:
86-
87-
* To provide a reusable low-level client library, that other packages can then build on top of.
88-
* To provide a *really clear interface split* between the networking code and client logic,
89-
so that each is easier to understand and reason about in isolation.

httpcore/_async/base.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AsyncByteStream:
3737
The base interface for request and response bodies.
3838
3939
Concrete implementations should subclass this class, and implement
40-
the `\\__aiter__` method, and optionally the `aclose` method.
40+
the :meth:`__aiter__` method, and optionally the :meth:`aclose` method.
4141
"""
4242

4343
async def __aiter__(self) -> AsyncIterator[bytes]:
@@ -57,8 +57,8 @@ class AsyncHTTPTransport:
5757
"""
5858
The base interface for sending HTTP requests.
5959
60-
Concete implementations should subclass this class, and implement
61-
the `request` method, and optionally the `close` method.
60+
Concrete implementations should subclass this class, and implement
61+
the :meth:`arequest` method, and optionally the :meth:`aclose` method.
6262
"""
6363

6464
async def arequest(
@@ -72,25 +72,29 @@ async def arequest(
7272
"""
7373
The interface for sending a single HTTP request, and returning a response.
7474
75-
**Parameters:**
76-
77-
* **method** - `bytes` - The HTTP method, such as `b'GET'`.
78-
* **url** - `Tuple[bytes, bytes, Optional[int], bytes]` - The URL as a 4-tuple
79-
of (scheme, host, port, path).
80-
* **headers** - `Optional[List[Tuple[bytes, bytes]]]` - Any HTTP headers
81-
to send with the request.
82-
* **stream** - `Optional[AsyncByteStream]` - The body of the HTTP request.
83-
* **ext** - `Optional[dict]` - A dictionary of optional extensions.
84-
85-
** Returns:**
86-
87-
A four-tuple of:
88-
89-
* **status_code** - `int` - The HTTP status code, such as `200`.
90-
* **headers** - `List[Tuple[bytes, bytes]]` - Any HTTP headers included
91-
on the response.
92-
* **stream** - `AsyncByteStream` - The body of the HTTP response.
93-
* **ext** - `dict` - A dictionary of optional extensions.
75+
Parameters
76+
----------
77+
method: bytes
78+
The HTTP method, such as `b'GET'`.
79+
url: Tuple[bytes, bytes, Optional[int], bytes]
80+
The URL as a 4-tuple of (scheme, host, port, path).
81+
headers: List[Tuple[bytes, bytes]]
82+
Any HTTP headers to send with the request.
83+
stream: :class:`AsyncByteStream`
84+
The body of the HTTP request.
85+
ext: dict
86+
A dictionary of optional extensions.
87+
88+
Returns
89+
-------
90+
status_code: int
91+
The HTTP status code, such as `200`.
92+
headers: List[Tuple[bytes, bytes]]
93+
Any HTTP headers included on the response.
94+
stream: :class:`AsyncByteStream`
95+
The body of the HTTP response.
96+
ext: dict
97+
A dictionary of optional extensions.
9498
"""
9599
raise NotImplementedError() # pragma: nocover
96100

httpcore/_async/connection_pool.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,30 @@ class AsyncConnectionPool(AsyncHTTPTransport):
7777
"""
7878
A connection pool for making HTTP requests.
7979
80-
**Parameters:**
81-
82-
* **ssl_context** - `Optional[SSLContext]` - An SSL context to use for
83-
verifying connections.
84-
* **max_connections** - `Optional[int]` - The maximum number of concurrent
85-
connections to allow.
86-
* **max_keepalive_connections** - `Optional[int]` - The maximum number of
87-
connections to allow before closing keep-alive connections.
88-
* **keepalive_expiry** - `Optional[float]` - The maximum time to allow
89-
before closing a keep-alive connection.
90-
* **http2** - `bool` - Enable HTTP/2 support.
91-
* **uds** - `str` - Path to a Unix Domain Socket to use instead of TCP sockets.
92-
* **local_address** - `Optional[str]` - Local address to connect from. Can
93-
also be used to connect using a particular address family. Using
94-
`local_address="0.0.0.0"` will connect using an `AF_INET` address (IPv4),
95-
while using `local_address="::"` will connect using an `AF_INET6` address
96-
(IPv6).
97-
* **retries** - `int` - The maximum number of retries when trying to establish a
98-
connection.
99-
* **backend** - `str` - A name indicating which concurrency backend to use.
80+
Parameters
81+
----------
82+
ssl_context: Optional[SSLContext]
83+
An SSL context to use for verifying connections.
84+
max_connections: Optional[int]
85+
The maximum number of concurrent connections to allow.
86+
max_keepalive_connections: Optional[int]
87+
The maximum number of connections to allow before closing keep-alive
88+
connections.
89+
keepalive_expiry: Optional[float]
90+
The maximum time to allow before closing a keep-alive connection.
91+
http2: bool
92+
Enable HTTP/2 support.
93+
uds: str
94+
Path to a Unix Domain Socket to use instead of TCP sockets.
95+
local_address: Optional[str]
96+
Local address to connect from. Can also be used to connect using a particular
97+
address family. Using `local_address="0.0.0.0"` will connect using an `AF_INET`
98+
address (IPv4), while using `local_address="::"` will connect using an
99+
`AF_INET6` address (IPv6).
100+
retries: int
101+
The maximum number of retries when trying to establish a connection.
102+
backend: str
103+
A name indicating which concurrency backend to use.
100104
"""
101105

102106
def __init__(

0 commit comments

Comments
 (0)