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
cd cf-box
pip install -e ".[dev]"
Using Docker
docker run -e CLOUDFLARE_API_TOKEN=your_token cf-box
Or using Docker Compose:
Quick Start
- Set your Cloudflare API token:
-
Configure
config.yamlwith your settings -
Run the tools:
cf-data-export
# Manage IP lists
cf-ip-manager
# Export analytics
cf-analytics
Development
Setup Pre-commit Hooks
pre-commit install
Run Tests
Code Quality
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 directoryclient.py- Async HTTP client for Cloudflare APImodels.py- Pydantic models for type safetydatabase.py- SQLAlchemy database operationspdf_generator.py- Template-based PDF generationlogging_config.py- Structured logging configurationdata_export.py- Data export moduleip_list_manager.py- IP list managementaggregated_analytics.py- Analytics export
Related Projects
- Backup via GitHub Actions: cloudflare-backup-actions
- WAF Control: wafcontrol
- Zone Control: zonecontrol
- mTLS with AWS: mtls-cloudflare-aws
- DNS Redundancy: dnscontrol-actions