Skip to main content

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)
  • requests or requests-cache (optional for caching)
  • fake-useragent
  • logprise

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

  1. 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
  2. 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

anti_cf-1.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anti_cf-1.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file anti_cf-1.1.0.tar.gz.

File metadata

  • Download URL: anti_cf-1.1.0.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

Hashes for anti_cf-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c8e00acfb7ed1186b75aa52ca28609d5410ea1134cca5ae12b56864c6a692f6d
MD5 e73b5735718cfc3cf7602d160d0ca0ad
BLAKE2b-256 e47314baf82f7a451b2644c819e6fd42394ff5c8abc7f40a8e8447930353a0f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for anti_cf-1.1.0.tar.gz:

Publisher: release.yml on svaningelgem/anti_cf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file anti_cf-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: anti_cf-1.1.0-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

Hashes for anti_cf-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c2ce2f5ce4263497ba725d47b3b7426b795b7ad0aef27e1a0ac9e68fd841624
MD5 6cb43efe5cabea7056d90dd9433bc905
BLAKE2b-256 413bd99aec2e9aaf060c8856bcbd0d7626ca92ea496e8a2614174cfd003b0ff5

See more details on using hashes here.

Provenance

The following attestation bundles were made for anti_cf-1.1.0-py3-none-any.whl:

Publisher: release.yml on svaningelgem/anti_cf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page