Skip to main content
IPForce Logo

IPForce: Force IPv4/IPv6 in Python HTTP Requests


PyPI version built with Python3 GitHub repo size Discord Channel

Overview

IPForce is a Python library that provides HTTP adapters for forcing specific IP protocol versions (IPv4 or IPv6) during HTTP requests. It's particularly useful for testing network connectivity, ensuring compatibility with specific network configurations, and controlling which IP protocol version is used for DNS resolution and connections.

PyPI Counter
Github Stars
Branch main dev
CI
Code Quality CodeFactor

Installation

Source Code

PyPI

Usage

Enforce IPv4

Use when you need to ensure connections only use IPv4 addresses, useful for legacy systems that don't support IPv6, networks with IPv4-only infrastructure, or testing IPv4 connectivity.

from ipforce import IPForceAdapter, IPVersion, IPForceMethod
import requests

session = requests.Session()
adapter = IPForceAdapter(IPVersion.V4, IPForceMethod.LOCK)
session.mount('http://', adapter)
session.mount('https://', adapter)

response = session.get('https://ifconfig.co/json')

Enforce IPv6

Use when you need to ensure connections only use IPv6 addresses, useful for modern networks with IPv6 infrastructure, testing IPv6 connectivity, or applications requiring IPv6-specific features.

from ipforce import IPForceAdapter, IPVersion, IPForceMethod
import requests

session = requests.Session()
adapter = IPForceAdapter(IPVersion.V6, IPForceMethod.LOCK)
session.mount('http://', adapter)
session.mount('https://', adapter)

response = session.get('https://ifconfig.co/json')

Using IPForceSession

from ipforce import IPForceSession, IPVersion

with IPForceSession(IPVersion.V4) as session:
    response = session.get('https://ifconfig.co/json')

Available Methods

Method Description
IPForceMethod.LOCK Thread-safe — global lock serialization (default)
IPForceMethod.GLOBAL Non-thread-safe — temporary getaddrinfo patch

Direct Class Usage (Deprecated)

The following direct class usage still works but is deprecated in favor of the unified API above:

from ipforce import IPv4LockAdapter, IPv6LockAdapter

session = requests.Session()
session.mount('http://', IPv4LockAdapter()) # or IPv6LockAdapter()
session.mount('https://', IPv4LockAdapter()) # or IPv6LockAdapter()
response = session.get('https://ifconfig.co/json')

Issues & Bug Reports

Just fill an issue and describe it. We'll check it ASAP!

  • Please complete the issue template

You can also join our discord server

Discord Channel

Show Your Support

Star This Repo

Give a ⭐️ if this project helped you!

Donate to Our Project

If you do like our project and we hope that you do, can you please support us? Our project is not and is never going to be working for profit. We need the money just so we can continue doing what we do ;-)

IPForce Donation

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Unreleased

0.2 - 2026-09-14

Added

  • IPForceAdapter unified factory function
  • IPForceSession unified session class
  • IPVersion enum (V4, V6)
  • IPForceMethod enum (GLOBAL, LOCK)
  • IPv6LockAdapter class
  • IPv4LockAdapter class
  • Logo

Changed

  • README.md updated
  • Dependencies structure modified

0.1 - 2026-02-16

Added

  • IPv6TransportAdapter class
  • IPv4TransportAdapter class
  • Test system

Metadata

Release files for ipforce 0.2

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

Source distribution (sdist)

Source distribution for ipforce 0.2
File Size Uploaded
ipforce-0.2.tar.gz 12.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ipforce 0.2
File Interpreter ABI Platform
ipforce-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 20.4 kB

Release files / ipforce-0.2.tar.gz

Download URL ipforce-0.2.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
aa7a27ae6ec3074888f9c562fc4ef4ce390872527ac1e98deb1bcaf3c1317d57
BLAKE2b-256 checksum
How to use checksums
19870e46a83a37fa04d350bc1657fc2ca00fd671ea4ab8c5766e92ebb32da930
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / ipforce-0.2-py3-none-any.whl

Download URL ipforce-0.2-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a5f798b9167d8af447a14dd23c69b07ada93102c618eae7c35bd61f70ebfd8e
BLAKE2b-256 checksum
How to use checksums
5b692843050e4e1aafd9d0d99f08ca9ea126e0f1f0eefdd319fad6948c6e7001
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1

2 release files

0.0.0

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