Anti-CloudFlare package
Project description
anti-cf
A Python library for handling Cloudflare-protected websites using FlareSolverr.
Overview
anti-cf provides a persistent session wrapper for handling websites protected by Cloudflare's anti-bot measures. It automatically manages cookies, user agents, and integrates with FlareSolverr to bypass Cloudflare challenges.
Features
- Persistent cookie storage
- Automatic FlareSolverr management (including Docker startup)
- Optional request caching via
requests-cache - Random user agent generation
- Transparent handling of Cloudflare challenges
Installation
pip install anti-cf
Usage
Basic Usage
from anti_cf import session
# The library will automatically check if FlareSolverr is running
# and start it if needed using Docker
# For Cloudflare-protected sites
response = session.get("https://cloudflare-protected-site.com", try_with_cloudflare=True)
# For regular requests
response = session.get("https://example.com")
Advanced Usage
from anti_cf import session
# Set a custom user agent
session.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
# Post requests work as normal
response = session.post("https://example.com/api", json={"key": "value"})
# All cookies are automatically saved between requests
Error Handling
from anti_cf import session
from requests import HTTPError
try:
response = session.get("https://cloudflare-protected-site.com", try_with_cloudflare=True)
response.raise_for_status()
except HTTPError as e:
print(f"HTTP error occurred: {e}")
Dependencies
- Python 3.11+
- FlareSolverr
- Docker (optional, for automatic FlareSolverr startup)
requestsorrequests-cache(optional for caching)fake-useragentlogprise
Configuration
The library uses the following default settings:
- Cache directory:
~/.cache/anti_cf/ - FlareSolverr API:
http://localhost:8191/ - Default timeout: 600 seconds
- Cache expiry: 2 hours (when using
requests-cache)
How It Works
-
When making a request to a Cloudflare-protected site:
- First attempts a normal request
- If Cloudflare challenge detected, sends the request through FlareSolverr
- Stores the resulting cookies for future requests
-
On startup:
- Checks if FlareSolverr API is reachable
- If not available, automatically starts the Docker container
Docker
By default, anti-cf will attempt to start the FlareSolverr Docker container:
ghcr.io/svaningelgem/flaresolverr:latest
License
Copyright © Steven Van Ingelgem steven@vaningelgem.be
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anti_cf-1.0.2.tar.gz.
File metadata
- Download URL: anti_cf-1.0.2.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc262a00108e7bef963dd55c14faa879a1b2dbaa181a2b1d5e5d3cf82a6640d5
|
|
| MD5 |
0b5ec55bc3562d8aa84cabb47ba9a351
|
|
| BLAKE2b-256 |
d6e16f388e93d70beb2e837bd02e22d4312726bfaa2231e2d2b9d0faa80480ad
|
Provenance
The following attestation bundles were made for anti_cf-1.0.2.tar.gz:
Publisher:
release.yml on svaningelgem/anti_cf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anti_cf-1.0.2.tar.gz -
Subject digest:
dc262a00108e7bef963dd55c14faa879a1b2dbaa181a2b1d5e5d3cf82a6640d5 - Sigstore transparency entry: 199834661
- Sigstore integration time:
-
Permalink:
svaningelgem/anti_cf@27050aef1633b8a755e3f149f9030e9423d862d1 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/svaningelgem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@27050aef1633b8a755e3f149f9030e9423d862d1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file anti_cf-1.0.2-py3-none-any.whl.
File metadata
- Download URL: anti_cf-1.0.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
091f66719bfb620b35d539c85eb2ba509878fab1e1d475ff8ff7e9a6877d17ec
|
|
| MD5 |
a3c5164ed0587713823d16e1af1ca5c6
|
|
| BLAKE2b-256 |
866c909f358ab4e7eb7007ae025292722544faef2aeaf393506d640f7dc573a5
|
Provenance
The following attestation bundles were made for anti_cf-1.0.2-py3-none-any.whl:
Publisher:
release.yml on svaningelgem/anti_cf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anti_cf-1.0.2-py3-none-any.whl -
Subject digest:
091f66719bfb620b35d539c85eb2ba509878fab1e1d475ff8ff7e9a6877d17ec - Sigstore transparency entry: 199834664
- Sigstore integration time:
-
Permalink:
svaningelgem/anti_cf@27050aef1633b8a755e3f149f9030e9423d862d1 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/svaningelgem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@27050aef1633b8a755e3f149f9030e9423d862d1 -
Trigger Event:
push
-
Statement type: