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
Metadata
Release files for anti-cf 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| anti_cf-1.1.3.tar.gz | 5.6 kB | With provenance | Details for anti_cf-1.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| anti_cf-1.1.3-py3-none-any.whl | Python 3 | none | any | Details for anti_cf-1.1.3-py3-none-any.whl |
Total release size: 11.5 kB
Release files / anti_cf-1.1.3.tar.gz
| Download URL | anti_cf-1.1.3.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4635cf1187647a42b141e67083da46400ea89d184d907515c51503271fa8180e
|
|
BLAKE2b-256 checksum How to use checksums |
57739b09f45c4657fdb6ccf90c9629e833055c496fa8d285db3769fa6a9224ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 29, 2026.
Transparency logRelease files / anti_cf-1.1.3-py3-none-any.whl
| Download URL | anti_cf-1.1.3-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a22bb653f9ce4b52b7b3966362f44a01e9c0448a1307a9424df47529572a85ec
|
|
BLAKE2b-256 checksum How to use checksums |
e607b59499cb7b90857a8e130ee567dcdebc260213f407e53083f1019a07b157
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 29, 2026.
Transparency logSecurity for anti-cf 1.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for anti_cf-1.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.