Skip to content

Commit daed462

Browse files
release
1 parent 1e837ad commit daed462

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+6207
-2
lines changed

.github/workflows/ci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: ['master', 'main', 'dev', 'develop']
6+
7+
pull_request:
8+
branches: ['master', 'main', 'dev', 'develop']
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
max-parallel: 4
15+
matrix:
16+
python-version: ['3.9', '3.10', '3.11']
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install Dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -r requirements.txt
28+
29+
- name: Run pre-commit
30+
uses: pre-commit/action@v3.0.0
31+
32+
deploy:
33+
needs: build
34+
runs-on: ubuntu-latest
35+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
36+
steps:
37+
- uses: actions/checkout@v4
38+
- name: Configure Git Credentials
39+
run: |
40+
git config user.name github-actions[bot]
41+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
42+
- uses: actions/setup-python@v5
43+
with:
44+
python-version: '3.10'
45+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
46+
- uses: actions/cache@v4
47+
with:
48+
key: mkdocs-material-${{ env.cache_id }}
49+
path: .cache
50+
restore-keys: |
51+
mkdocs-material-
52+
- run: pip install -r requirements.txt
53+
- run: mkdocs gh-deploy --force

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,4 @@ cython_debug/
159159
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160160
# and can be added to the global gitignore or merged into this file. For a more nuclear
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162-
#.idea/
162+
.idea/

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
exclude: '^docs.sh/|scripts/'
2+
default_stages: [commit]
3+
4+
default_language_version:
5+
python: python3.10
6+
7+
repos:
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v4.5.0
10+
hooks:
11+
- id: trailing-whitespace
12+
- id: end-of-file-fixer
13+
- id: check-json
14+
- id: check-toml
15+
- id: check-xml
16+
- id: check-yaml
17+
- id: debug-statements
18+
- id: check-builtin-literals
19+
- id: check-case-conflict
20+
- id: check-docstring-first
21+
- id: detect-private-key
22+
23+
# run the isort.
24+
- repo: https://github.com/PyCQA/isort
25+
rev: 5.13.2
26+
hooks:
27+
- id: isort
28+
29+
# run the flake8.
30+
- repo: https://github.com/PyCQA/flake8
31+
rev: 7.0.0
32+
hooks:
33+
- id: flake8

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Release History
2+
===============
3+
4+
1.0.0 (2024-12-04)
5+
-------------------
6+
* First release

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include LICENSE
2+
include README.md
3+
include CHANGELOG.md
4+
recursive-include tls_requests docs Makefile *.md *.rst

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.PHONY: docs
2+
init:
3+
python -m pip install -r requirements.txt
4+
5+
test-readme:
6+
python setup.py check --restructuredtext --strict && ([ $$? -eq 0 ] && echo "README.rst and CHANGELOG.md ok") || echo "Invalid markup in README.md or CHANGELOG.md!"
7+
8+
lint:
9+
python -m black tls_requests
10+
python -m isort tls_requests
11+
python -m flake8 tls_requests
12+
13+
publish-pypi:
14+
python -m pip install 'twine>=6.0.1'
15+
python setup.py sdist bdist_wheel
16+
twine upload dist/*
17+
rm -rf build dist .egg tls_requests.egg-info
18+
19+
docs:
20+
mkdocs serve

README.md

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,109 @@
1-
# tls-requests
1+
# TLS REQUESTS
2+
**A powerful and lightweight Python library for making secure and reliable HTTP/TLS fingerprint requests.**
3+
4+
* * *
5+
6+
**Installation**
7+
----------------
8+
9+
Install TLS Requests using pip:
10+
11+
```shell
12+
pip install tls-requests
13+
```
14+
15+
### Quick Start
16+
17+
Start using TLS Requests with just a few lines of code:
18+
19+
```pycon
20+
>>> import tls_requests
21+
>>> r = tls_requests.get("https://httpbin.org/get")
22+
>>> r
23+
<Response [200 OK]>
24+
>>> r.status_code
25+
200
26+
```
27+
28+
* * *
29+
30+
**Introduction**
31+
----------------
32+
33+
**TLS Requests** is a cutting-edge HTTP client for Python, offering a feature-rich,
34+
highly configurable alternative to the popular [`requests`](https://github.com/psf/requests) library.
35+
36+
It is built on top of [`tls-client`](https://github.com/bogdanfinn/tls-client),
37+
combining ease of use with advanced functionality for secure networking.
38+
39+
**Acknowledgment**: A big thank you to all contributors for their support!
40+
41+
### **Key Benefits**
42+
43+
* **Bypass TLS Fingerprinting:** Mimic browser-like behaviors to navigate sophisticated anti-bot systems.
44+
* **Customizable TLS Clients:** Select specific TLS fingerprints to meet your needs.
45+
* **Ideal for Developers:** Build scrapers, API clients, or other custom networking tools effortlessly.
46+
47+
* * *
48+
49+
**Why Use TLS Requests?**
50+
-------------------------
51+
52+
Modern websites increasingly use **TLS Fingerprinting** and anti-bot tools like Cloudflare Bot Fight Mode to block web crawlers.
53+
54+
**TLS Requests** bypasses these obstacles by mimicking browser-like TLS behaviors,
55+
making it easy to scrape data or interact with websites that use sophisticated anti-bot measures.
56+
57+
### Cloudflare Bot Fight Mode
58+
![coingecko.png](https://raw.githubusercontent.com/thewebscraping/tls-requests/refs/heads/master/docs/static/coingecko.png)
59+
60+
### Unlock Content Behind Cloudflare Bot Fight Mode
61+
62+
**Example Code:**
63+
64+
```pycon
65+
>>> import tls_requests
66+
>>> r = tls_requests.get('https://www.coingecko.com/')
67+
>>> r
68+
<Response [200]>
69+
```
70+
* * *
71+
72+
**Key Features**
73+
----------------
74+
75+
### **Enhanced Capabilities**
76+
77+
* **Browser-like TLS Fingerprinting**: Enables secure and reliable browser-mimicking connections.
78+
* **High-Performance Backend**: Built on a Go-based HTTP backend for speed and efficiency.
79+
* **Synchronous & Asynchronous Support**: Seamlessly switch between synchronous and [asynchronous requests](https://github.com/thewebscraping/tls-requests/blob/main/docs/advanced/async_client).
80+
* **Protocol Support**: Fully compatible with HTTP/1.1 and HTTP/2.
81+
* **Strict Timeouts**: Reliable timeout management for precise control over request durations.
82+
83+
### **Additional Features**
84+
85+
* **Internationalized Domain & URL Support**: Handles non-ASCII URLs effortlessly.
86+
* **Cookie Management**: Ensures session-based cookie persistence.
87+
* **Authentication**: Native support for Basic and Function authentication.
88+
* **Content Decoding**: Automatic handling of gzip and brotli-encoded responses.
89+
* **Hooks**: Perfect for logging, monitoring, tracing, or pre/post-processing requests and responses.
90+
* **Unicode Support**: Effortlessly process Unicode response bodies.
91+
* **File Uploads**: Simplified multipart file upload support.
92+
* **Proxy Configuration**: Supports Socks5, HTTP, and HTTPS proxies for enhanced privacy.
93+
94+
* * *
95+
96+
**Documentation**
97+
-----------------
98+
99+
Explore the full capabilities of TLS Requests in the documentation:
100+
101+
* **[Quickstart Guide](https://github.com/thewebscraping/tls-requests/blob/main/docs/quickstart.md)**: A beginner-friendly guide.
102+
* **Advanced Topics**: Learn to leverage specialized features.
103+
* **[Async Support](https://github.com/thewebscraping/tls-requests/blob/main/docs/docs/advanced/async_client)**: Handle high-concurrency scenarios.
104+
* **Custom TLS Configurations**:
105+
* **[Wrapper TLS Client](https://github.com/thewebscraping/tls-requests/blob/main/docs/docs/tls/index)**
106+
* **[TLS Client Profiles](https://github.com/thewebscraping/tls-requests/blob/main/docs/docs/tls/profiles)**
107+
* **[Custom TLS Configurations](https://github.com/thewebscraping/tls-requests/blob/main/docs/docs/tls/configuration)**
108+
109+
* * *

docs/advanced/async_client.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
Async Support in TLS Requests
2+
=============================
3+
4+
TLS Requests provides support for asynchronous HTTP requests using the `AsyncClient`. This is especially useful when working in an asynchronous environment, such as with modern web frameworks, or when you need the performance benefits of asynchronous I/O.
5+
6+
* * *
7+
8+
Why Use Async?
9+
--------------
10+
11+
* **Improved Performance:** Async is more efficient than multi-threading for handling high concurrency workloads.
12+
* **Long-lived Connections:** Useful for protocols like WebSockets or long polling.
13+
* **Framework Compatibility:** Essential when integrating with async web frameworks (e.g., FastAPI, Starlette).
14+
15+
Advanced usage with syntax similar to Client, refer to the [Client documentation](client).
16+
17+
* * *
18+
19+
Making Async Requests
20+
---------------------
21+
22+
To send asynchronous HTTP requests, use the `AsyncClient`:
23+
24+
```pycon
25+
>>> import asyncio
26+
>>> async def fetch(url):
27+
async with tls_requests.AsyncClient() as client:
28+
r = await client.get("https://www.example.com/")
29+
return r
30+
31+
>>> r = asyncio.run(fetch("https://httpbin.org/get"))
32+
>>> r
33+
<Response [200 OK]>
34+
```
35+
36+
!!! tip
37+
Use [IPython](https://ipython.readthedocs.io/en/stable/) or Python 3.8+ with `python -m asyncio` to try this code interactively, as they support executing `async`/`await` expressions in the console.
38+
39+
* * *
40+
41+
Key API Differences
42+
-------------------
43+
44+
When using `AsyncClient`, the API methods are asynchronous and must be awaited.
45+
46+
### Making Requests
47+
48+
Use `await` for all request methods:
49+
50+
* `await client.get(url, ...)`
51+
* `await client.post(url, ...)`
52+
* `await client.put(url, ...)`
53+
* `await client.patch(url, ...)`
54+
* `await client.delete(url, ...)`
55+
* `await client.options(url, ...)`
56+
* `await client.head(url, ...)`
57+
* `await client.request(method, url, ...)`
58+
* `await client.send(request, ...)`
59+
60+
* * *
61+
62+
### Managing Client Lifecycle
63+
64+
#### Context Manager
65+
66+
For proper resource cleanup, use `async with`:
67+
68+
```python
69+
import asyncio
70+
71+
async def fetch(url):
72+
async with tls_requests.AsyncClient() as client:
73+
response = await client.get(url)
74+
return response
75+
76+
r = asyncio.run(fetch("https://httpbin.org/get"))
77+
print(r) # <Response [200 OK]>
78+
```
79+
80+
#### Manual Closing
81+
82+
Alternatively, explicitly close the client:
83+
84+
```python
85+
import asyncio
86+
87+
async def fetch(url):
88+
client = tls_requests.AsyncClient()
89+
try:
90+
response = await client.get("https://www.example.com/")
91+
finally:
92+
await client.aclose()
93+
```
94+
95+
* * *
96+
97+
By using `AsyncClient`, you can unlock the full potential of asynchronous programming in Python while enjoying the simplicity and power of TLS Requests.

0 commit comments

Comments
 (0)