Skip to content

cf-box is a set of Python tools to play with API and multiple Cloudflare accounts.

License

Notifications You must be signed in to change notification settings

fabriziosalmi/cf-box

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

cf-box: Cloudflare Management Toolkit

cf-box is a comprehensive, production-ready suite of Python tools designed to streamline and automate interactions with the Cloudflare API, enabling efficient management of multiple Cloudflare accounts and their associated resources.

Features

  • IP List Manager: Centrally manage multiple IP access rule lists across your Cloudflare accounts using a single, easy-to-maintain YAML configuration. Link
  • Data Export: Export detailed data from all your Cloudflare accounts, including zones, DNS records, and settings, to various formats (JSON, CSV, Excel, PDF). Link
  • Analytics Export: Fetch and export aggregated analytics data from Cloudflare using GraphQL
  • Async/Await Support: Modern async architecture using aiohttp for improved performance
  • Structured Logging: Professional logging with structlog for better observability
  • Type Safety: Pydantic models for API response validation
  • SQLAlchemy Integration: Secure database operations with parameterized queries

Installation

From Source

git clone https://github.com/fabriziosalmi/cf-box.git
cd cf-box
pip install -e ".[dev]"

Using Docker

docker build -t cf-box .
docker run -e CLOUDFLARE_API_TOKEN=your_token cf-box

Or using Docker Compose:

docker-compose up cf-data-export

Quick Start

  1. Set your Cloudflare API token:
export CLOUDFLARE_API_TOKEN=your_api_token_here
  1. Configure config.yaml with your settings

  2. Run the tools:

# Export Cloudflare data
cf-data-export

# Manage IP lists
cf-ip-manager

# Export analytics
cf-analytics

Development

Setup Pre-commit Hooks

pip install pre-commit
pre-commit install

Run Tests

pytest

Code Quality

# Format code
black cf_box/

# Lint code
ruff check cf_box/

# Type checking
mypy cf_box/

Architecture

The project follows a modern Python package structure:

  • cf_box/ - Main package directory
    • client.py - Async HTTP client for Cloudflare API
    • models.py - Pydantic models for type safety
    • database.py - SQLAlchemy database operations
    • pdf_generator.py - Template-based PDF generation
    • logging_config.py - Structured logging configuration
    • data_export.py - Data export module
    • ip_list_manager.py - IP list management
    • aggregated_analytics.py - Analytics export

Related Projects