Skip to main content

cloudflare-json-ips

Python library that resolves Cloudflare-published IP ranges from the authoritative JSON source.

It downloads and parses https://api.cloudflare.com/client/v4/ips, extracts all IPv4 and IPv6 CIDRs, and provides helpers for containment and overlap queries.

Why JSON?

Cloudflare publishes an authoritative machine-readable API response with:

  • result.ipv4_cidrs
  • result.ipv6_cidrs
  • result.etag

This package reads that source directly.

Install

From PyPI

pip install cloudflare-json-ips

Local Development

From the project root:

pip install -e .

Library Usage

from cloudflare_json_ips import CloudflareIPQuery, get_cloudflare_ip_cidrs

result = get_cloudflare_ip_cidrs()
query = CloudflareIPQuery.from_cidrs(result.cidrs)

print(result.etag)
print(query.contains("104.16.0.0/13"))
print(query.collides("104.16.0.0-104.23.255.255"))

result is a ResolutionResult with:

  • cidrs: sorted tuple of unique CIDR strings
  • etag: source etag from Cloudflare's response
  • source_url: JSON URL used
  • selected_prefix_count: number of selected IPv4 and IPv6 prefix entries

CloudflareIPQuery supports:

  • contains(value): full containment for IP, CIDR, or range string (start-end)
  • collides(value): any overlap for IP, CIDR, or range string (start-end)
  • Specific methods: contains_ip, contains_cidr, contains_range, collides_ip, collides_cidr, collides_range

Example Script

Run:

python examples/print_cloudflare_ips.py

Flask JSON Server Example

Run:

python examples/flask_server.py

All endpoints return JSON.

Examples:

curl "http://127.0.0.1:5003/health"
curl "http://127.0.0.1:5003/metadata"
curl "http://127.0.0.1:5003/cidrs"
curl "http://127.0.0.1:5003/networks"
curl "http://127.0.0.1:5003/check?value=104.16.0.0/13"
curl "http://127.0.0.1:5003/check?value=104.16.0.0-104.23.255.255"
curl "http://127.0.0.1:5003/check/range?start=104.16.0.0&end=104.23.255.255"

Metadata

Release files for cloudflare-json-ips 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cloudflare-json-ips 0.1.0
File Size Uploaded
cloudflare_json_ips-0.1.0.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cloudflare-json-ips 0.1.0
File Interpreter ABI Platform
cloudflare_json_ips-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / cloudflare_json_ips-0.1.0.tar.gz

Download URL cloudflare_json_ips-0.1.0.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
33abb1ba878c768f03cbda449b2d5612871279110da140d0a45658b8197fc995
BLAKE2b-256 checksum
How to use checksums
d8f47b57bf7de7f4f44763c2dac0b5e58ac7e5d66cdec2cbf74aa992110c12d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / cloudflare_json_ips-0.1.0-py3-none-any.whl

Download URL cloudflare_json_ips-0.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8cc4f27e68bb0b0b1c4b12cc0f62fa937e1a545eb7462abda78feed56fcd692
BLAKE2b-256 checksum
How to use checksums
51ca886583a3afad27a375b6c29778e3e1534662bd3067bb4628e84248cbc102
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page