Skip to content

Commit d10b7cd

Browse files
Use pycon for Python console code blocks (#1187)
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
1 parent 9fa95cc commit d10b7cd

6 files changed

Lines changed: 70 additions & 70 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ release, so that you're able to properly review [API changes between package upd
2323

2424
Let's get started...
2525

26-
```python
26+
```pycon
2727
>>> import httpx
2828
>>> r = httpx.get('https://www.example.org/')
2929
>>> r
@@ -40,7 +40,7 @@ Or, using the async API...
4040

4141
_Use [IPython](https://ipython.readthedocs.io/en/stable/) or Python 3.8+ with `python -m asyncio` to try this code interactively._
4242

43-
```python
43+
```pycon
4444
>>> import httpx
4545
>>> async with httpx.AsyncClient() as client:
4646
>>> r = await client.get('https://www.example.org/')

docs/advanced.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ finally:
5656

5757
Once you have a `Client`, you can send requests using `.get()`, `.post()`, etc. For example:
5858

59-
```python
59+
```pycon
6060
>>> with httpx.Client() as client:
6161
... r = client.get('https://example.com')
6262
...
@@ -68,7 +68,7 @@ These methods accept the same arguments as `httpx.get()`, `httpx.post()`, etc. T
6868

6969
For example, to send a request with custom headers:
7070

71-
```python
71+
```pycon
7272
>>> with httpx.Client() as client:
7373
... headers = {'X-Custom': 'value'}
7474
... r = client.get('https://example.com', headers=headers)
@@ -83,7 +83,7 @@ Clients allow you to apply configuration to all outgoing requests by passing par
8383

8484
For example, to apply a set of custom headers _on every request_:
8585

86-
```python
86+
```pycon
8787
>>> url = 'http://httpbin.org/headers'
8888
>>> headers = {'user-agent': 'my-app/0.0.1'}
8989
>>> with httpx.Client(headers=headers) as client:
@@ -99,7 +99,7 @@ When a configuration option is provided at both the client-level and request-lev
9999

100100
- For headers, query parameters and cookies, the values are combined together. For example:
101101

102-
```python
102+
```pycon
103103
>>> headers = {'X-Auth': 'from-client'}
104104
>>> params = {'client_id': 'client1'}
105105
>>> with httpx.Client(headers=headers, params=params) as client:
@@ -117,7 +117,7 @@ URL('https://example.com?client_id=client1&request_id=request1')
117117

118118
- For all other parameters, the request-level value takes priority. For example:
119119

120-
```python
120+
```pycon
121121
>>> with httpx.Client(auth=('tom', 'mot123')) as client:
122122
... r = client.get('https://example.com', auth=('alice', 'ecila123'))
123123
...
@@ -135,7 +135,7 @@ Additionally, `Client` accepts some configuration options that aren't available
135135

136136
For example, `base_url` allows you to prepend an URL to all outgoing requests:
137137

138-
```python
138+
```pycon
139139
>>> with httpx.Client(base_url='http://httpbin.org') as client:
140140
... r = client.get('/headers')
141141
...
@@ -232,15 +232,15 @@ not defined, HTTPX tries to add auth into request's header from .netrc file.
232232
you should create a new client or restart the interpreter.
233233

234234
As default `trust_env` is true. To set false:
235-
```python
235+
```pycon
236236
>>> httpx.get('https://example.org/', trust_env=False)
237237
```
238238

239239
If `NETRC` environment is empty, HTTPX tries to use default files.
240240
(`~/.netrc`, `~/_netrc`)
241241

242242
To change `NETRC` environment:
243-
```python
243+
```pycon
244244
>>> import os
245245
>>> os.environ["NETRC"] = "my_default_folder/.my_netrc"
246246
```
@@ -572,7 +572,7 @@ As mentioned in the [quickstart](/quickstart#sending-multipart-file-uploads)
572572
multipart file encoding is available by passing a dictionary with the
573573
name of the payloads as keys and either tuple of elements or a file-like object or a string as values.
574574

575-
```python
575+
```pycon
576576
>>> files = {'upload-file': ('report.xls', open('report.xls', 'rb'), 'application/vnd.ms-excel')}
577577
>>> r = httpx.post("https://httpbin.org/post", files=files)
578578
>>> print(r.text)
@@ -597,7 +597,7 @@ on the file name, with unknown file extensions defaulting to "application/octet-
597597
If the file name is explicitly set to `None` then HTTPX will not include a content-type
598598
MIME header field.
599599

600-
```python
600+
```pycon
601601
>>> files = {'upload-file': (None, 'text content', 'text/plain')}
602602
>>> r = httpx.post("https://httpbin.org/post", files=files)
603603
>>> print(r.text)
@@ -620,7 +620,7 @@ You can also send multiple files in one go with a multiple file field form.
620620
To do that, pass a list of `(field, <file>)` items instead of a dictionary, allowing you to pass multiple items with the same `field`.
621621
For instance this request sends 2 files, `foo.png` and `bar.png` in one request on the `images` form field:
622622

623-
```python
623+
```pycon
624624
>>> files = [('images', ('foo.png', open('foo.png', 'rb'), 'image/png')),
625625
('images', ('bar.png', open('bar.png', 'rb'), 'image/png'))]
626626
>>> r = httpx.post("https://httpbin.org/post", files=files)
@@ -742,7 +742,7 @@ r = httpx.get("https://example.org", verify="path/to/client.pem")
742742

743743
Alternatively, you can pass a standard library `ssl.SSLContext`.
744744

745-
```python
745+
```pycon
746746
>>> import ssl
747747
>>> import httpx
748748
>>> context = ssl.create_default_context()
@@ -753,15 +753,15 @@ Alternatively, you can pass a standard library `ssl.SSLContext`.
753753

754754
We also include a helper function for creating properly configured `SSLContext` instances.
755755

756-
```python
756+
```pycon
757757
>>> context = httpx.create_ssl_context()
758758
```
759759

760760
The `create_ssl_context` function accepts the same set of SSL configuration arguments
761761
(`trust_env`, `verify`, `cert` and `http2` arguments)
762762
as `httpx.Client` or `httpx.AsyncClient`
763763

764-
```python
764+
```pycon
765765
>>> import httpx
766766
>>> context = httpx.create_ssl_context(verify="/tmp/client.pem")
767767
>>> httpx.get('https://example.org', verify=context)
@@ -796,7 +796,7 @@ If you do need to make HTTPS connections to a local server, for example to test
796796
1. Pass the server key/cert files when starting your local server. (This depends on the particular web server you're using. For example, [Uvicorn](https://www.uvicorn.org) provides the `--ssl-keyfile` and `--ssl-certfile` options.)
797797
1. Tell HTTPX to use the certificates stored in `client.pem`:
798798

799-
```python
799+
```pycon
800800
>>> import httpx
801801
>>> r = httpx.get("https://localhost:8000", verify="/tmp/client.pem")
802802
>>> r
@@ -814,7 +814,7 @@ class directly, and pass it to the client instance. The `httpcore` package
814814
provides a `local_address` configuration that is only available via this
815815
low-level API.
816816

817-
```python
817+
```pycon
818818
>>> import httpx, httpcore
819819
>>> ssl_context = httpx.create_ssl_context()
820820
>>> transport = httpcore.SyncConnectionPool(
@@ -854,7 +854,7 @@ HTTPX also currently ships with a transport that uses the excellent
854854
[`urllib3` library](https://urllib3.readthedocs.io/en/latest/), which can be
855855
used with the sync `Client`...
856856

857-
```python
857+
```pycon
858858
>>> import httpx
859859
>>> client = httpx.Client(transport=httpx.URLLib3Transport())
860860
>>> client.get("https://example.org")
@@ -891,7 +891,7 @@ class HelloWorldTransport(httpcore.SyncHTTPTransport):
891891

892892
Which we can use in the same way:
893893

894-
```python
894+
```pycon
895895
>>> import httpx
896896
>>> client = httpx.Client(transport=HelloWorldTransport())
897897
>>> response = client.get("https://example.org/")

docs/api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
*An HTTP request. Can be constructed explicitly for more control over exactly
8989
what gets sent over the wire.*
9090

91-
```python
91+
```pycon
9292
>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})
9393
>>> response = client.send(request)
9494
```
@@ -104,7 +104,7 @@ what gets sent over the wire.*
104104

105105
*A normalized, IDNA supporting URL.*
106106

107-
```python
107+
```pycon
108108
>>> url = URL("https://example.org/")
109109
>>> url.host
110110
'example.org'
@@ -128,7 +128,7 @@ what gets sent over the wire.*
128128

129129
*A case-insensitive multi-dict.*
130130

131-
```python
131+
```pycon
132132
>>> headers = Headers({'Content-Type': 'application/json'})
133133
>>> headers['content-type']
134134
'application/json'
@@ -141,7 +141,7 @@ what gets sent over the wire.*
141141

142142
*A dict-like cookie store.*
143143

144-
```python
144+
```pycon
145145
>>> cookies = Cookies()
146146
>>> cookies.set("name", "value", domain="example.org")
147147
```

docs/async.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async client for sending outgoing HTTP requests.
1414

1515
To make asynchronous requests, you'll need an `AsyncClient`.
1616

17-
```python
17+
```pycon
1818
>>> async with httpx.AsyncClient() as client:
1919
>>> r = await client.get('https://www.example.com/')
2020
>>> r
@@ -64,7 +64,7 @@ await client.aclose()
6464

6565
The `AsyncClient.stream(method, url, ...)` method is an async context block.
6666

67-
```python
67+
```pycon
6868
>>> client = httpx.AsyncClient()
6969
>>> async with client.stream('GET', 'https://www.example.com/') as response:
7070
>>> async for chunk in response.aiter_bytes():
@@ -177,7 +177,7 @@ app = Starlette(routes=[Route("/", hello)])
177177

178178
We can make requests directly against the application, like so:
179179

180-
```python
180+
```pycon
181181
>>> import httpx
182182
>>> async with httpx.AsyncClient(app=app, base_url="http://testserver") as client:
183183
... r = await client.get("/")

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ HTTPX is a fully featured HTTP client for Python 3, which provides sync and asyn
3535

3636
Let's get started...
3737

38-
```python
38+
```pycon
3939
>>> import httpx
4040
>>> r = httpx.get('https://www.example.org/')
4141
>>> r
@@ -52,7 +52,7 @@ Or, using the async API...
5252

5353
_Use [IPython](https://ipython.readthedocs.io/en/stable/) or Python 3.8+ with `python -m asyncio` to try this code interactively._
5454

55-
```python
55+
```pycon
5656
>>> import httpx
5757
>>> async with httpx.AsyncClient() as client:
5858
>>> r = await client.get('https://www.example.org/')

0 commit comments

Comments
 (0)