Skip to content

Commit e80972f

Browse files
committed
docs: convert pycon to python blocks
1 parent 104fbc5 commit e80972f

8 files changed

Lines changed: 206 additions & 209 deletions

File tree

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,33 @@ pip install git+https://github.com/thewebscraping/tls-requests.git
3636

3737
Start using TLS Requests with just a few lines of code. It automatically synchronizes headers based on your chosen browser identifier:
3838

39-
```pycon
40-
>>> import tls_requests
41-
>>> # The library automatically injects matching User-Agent and Sec-CH-UA headers
42-
>>> r = tls_requests.get("https://httpbin.org/headers", client_identifier="chrome_133")
43-
>>> r.json()["headers"]["User-Agent"]
39+
```python
40+
import tls_requests
41+
# The library automatically injects matching User-Agent and Sec-CH-UA headers
42+
r = tls_requests.get("https://httpbin.org/headers", client_identifier="chrome_133")
43+
r.json()["headers"]["User-Agent"]
4444
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36'
4545
```
4646

4747
Basic automatically rotates for proxies and TLS identifiers:
4848

49-
```pycon
50-
>>> import tls_requests
51-
>>> proxy_rotator = tls_requests.ProxyRotator([
49+
```python
50+
import tls_requests
51+
proxy_rotator = tls_requests.ProxyRotator([
5252
"http://user1:pass1@proxy.example.com:8080",
5353
"http://user2:pass2@proxy.example.com:8081",
5454
"socks5://proxy.example.com:8082",
5555
"proxy.example.com:8083", # defaults to http
5656
"http://user:pass@proxy.example.com:8084|1.0|US", # weight and region support
5757
])
58-
>>> r = tls_requests.get(
58+
r = tls_requests.get(
5959
"https://httpbin.org/get",
6060
proxy=proxy_rotator,
6161
client_identifier=tls_requests.TLSIdentifierRotator()
6262
)
63-
>>> r
63+
r
6464
<Response [200 OK]>
65-
>>> r.status_code
65+
r.status_code
6666
200
6767
```
6868

@@ -97,10 +97,10 @@ making it easy to scrape data or interact with websites that use sophisticated a
9797

9898
**Example Code:**
9999

100-
```pycon
101-
>>> import tls_requests
102-
>>> r = tls_requests.get('https://www.coingecko.com/')
103-
>>> r
100+
```python
101+
import tls_requests
102+
r = tls_requests.get('https://www.coingecko.com/')
103+
r
104104
<Response [200]>
105105
```
106106

@@ -110,7 +110,7 @@ making it easy to scrape data or interact with websites that use sophisticated a
110110
### **Enhanced Capabilities**
111111

112112
* **Browser-like TLS Fingerprinting**: Enables secure and reliable browser-mimicking connections.
113-
* **Dynamic Header Synchronization**: Automatically extracts browser versions from `tls_identifier` and injects them into `User-Agent` and `sec-ch-ua` headers.
113+
* **Dynamic Header Synchronization**: Automatically extracts browser versions from `client_identifier` and injects them into `User-Agent` and `sec-ch-ua` headers.
114114
* **High-Performance Backend**: Built on a Go-based HTTP backend with **Protocol Racing** (Happy Eyeballs) enabled by default for faster connections.
115115
* **Synchronous & Asynchronous Support**: Seamlessly switch between synchronous and asynchronous requests.
116116
* **Protocol Support**: Fully compatible with HTTP/1.1, HTTP/2, and HTTP/3 (Alpha).

docs/advanced/async_client.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ The `AsyncClient` mirrors the `Client` API but requires the `await` keyword for
6969

7070
### Async Methods
7171
All request methods are coroutines:
72+
7273
- `await client.get(url, ...)`
7374
- `await client.post(url, ...)`
7475
- `await client.put(url, ...)`

docs/advanced/client.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ The client supports all standard HTTP methods:
8787
- `client.options(url, **kwargs)`
8888

8989
For more advanced scenarios like custom authentication or request hooks, refer to the dedicated guides in the [Advanced](../advanced/authentication.md) section.
90+
91+
* **Merging Headers and Cookies:**
92+
Request-level values will override client-level values if there is a conflict.
93+
94+
```python
95+
client_headers = {'X-Auth': 'client'}
9096
request_headers = {'X-Custom': 'request'}
9197
with tls_requests.Client(headers=client_headers) as client:
9298
response = client.get("https://httpbin.org/get", headers=request_headers)
@@ -99,14 +105,12 @@ with tls_requests.Client(headers=client_headers) as client:
99105
```python
100106
with tls_requests.Client(auth=('user', 'pass')) as client:
101107
response = client.get("https://httpbin.org/get", auth=('admin', 'adminpass'))
102-
print(response.request.headers['Authorization']) # Encoded 'admin:adminpass'
103-
108+
# Authorization header would be encoded 'admin:adminpass'
104109
```
105110

106111
* * *
107112

108-
Advanced Request Handling
109-
-------------------------
113+
## Advanced Request Handling
110114

111115
For more control, explicitly build and send `Request` instances:
112116

@@ -122,15 +126,15 @@ To combine client- and request-level configurations:
122126
```python
123127
with tls_requests.Client(headers={"X-Client-ID": "ABC123"}) as client:
124128
request = client.build_request("GET", "https://httpbin.org/json")
125-
del request.headers["X-Client-ID"] # Modify as needed
129+
# request.headers["X-Client-ID"] is present, but you can modify it
130+
del request.headers["X-Client-ID"]
126131
response = client.send(request)
127132
print(response)
128133
```
129134

130135
* * *
131136

132-
File Uploads
133-
------------
137+
## File Uploads
134138

135139
Upload files with control over file name, content, and MIME type:
136140

docs/advanced/rotators.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ with tls_requests.Client(headers=tls_requests.HeaderRotator()) as client:
2929
**How to Override the Default Behavior:**
3030

3131
- **To rotate through your own list of headers**, pass a `list` of `dict`s:
32-
```python
33-
my_headers = [{"User-Agent": "MyBot/1.0"}, {"User-Agent": "MyBot/2.0"}]
34-
client = tls_requests.Client(headers=my_headers)
35-
```
32+
```python
33+
my_headers = [{"User-Agent": "MyBot/1.0"}, {"User-Agent": "MyBot/2.0"}]
34+
client = tls_requests.Client(headers=my_headers)
35+
```
3636

3737
- **To use a single, static set of headers (no rotation)**, pass a single `dict`:
38-
```python
39-
static_headers = {"User-Agent": "Always-The-Same-Bot/1.0"}
40-
client = tls_requests.Client(headers=static_headers)
41-
```
38+
```python
39+
static_headers = {"User-Agent": "Always-The-Same-Bot/1.0"}
40+
client = tls_requests.Client(headers=static_headers)
41+
```
4242

4343
- **To completely disable default headers**, pass `None`:
44-
```python
45-
# This client will not add any default headers (like User-Agent).
46-
client = tls_requests.Client(headers=None)
47-
```
44+
```python
45+
# This client will not add any default headers (like User-Agent).
46+
client = tls_requests.Client(headers=None)
47+
```
4848

4949
* * *
5050

docs/index.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ pip install git+https://github.com/thewebscraping/tls-requests.git
4646
4747
Start using TLS Requests with just a few lines of code:
4848
49-
```pycon
50-
>>> import tls_requests
51-
>>> r = tls_requests.get("https://httpbin.org/get")
52-
>>> r
49+
```python
50+
import tls_requests
51+
r = tls_requests.get("https://httpbin.org/get")
52+
r
5353
<Response [200 OK]>
54-
>>> r.status_code
54+
r.status_code
5555
200
5656
```
5757
@@ -88,10 +88,10 @@ Modern websites increasingly use **TLS Fingerprinting** and anti-bot tools like
8888

8989
**Example Code:**
9090

91-
```pycon
92-
>>> import tls_requests
93-
>>> r = tls_requests.get('https://www.coingecko.com/')
94-
>>> r
91+
```python
92+
import tls_requests
93+
r = tls_requests.get('https://www.coingecko.com/')
94+
r
9595
<Response [200]>
9696
```
9797
* * *

0 commit comments

Comments
 (0)