Install & Compatibility
Where this runs
tested against v1.0.8 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ip_address
✓ from ipaddress import ip_address
ip_network
✓ from ipaddress import ip_network
IPv4Address
✓ from ipaddress import IPv4Address
IPv6Address
✓ from ipaddress import IPv6Address
IPv4Network
✓ from ipaddress import IPv4Network
IPv6Network
✓ from ipaddress import IPv6Network
This quickstart demonstrates basic usage of the `ipaddress` module, including creating IP address and network objects, and checking for membership. When `types-ipaddress` is installed, a static type checker would verify the type annotations in `check_ip_in_network` against the provided stubs for `ipaddress` objects.
import ipaddress
def check_ip_in_network(ip_str: str, network_str: str) -> bool:
try:
ip_addr = ipaddress.ip_address(ip_str)
network = ipaddress.ip_network(network_str, strict=False)
return ip_addr in network
except ValueError as e:
print(f"Error: {e}")
return False
if __name__ == "__main__":
test_ip_v4 = "192.168.1.5"
test_network_v4 = "192.168.1.0/24"
print(f"Is {test_ip_v4} in {test_network_v4}? {check_ip_in_network(test_ip_v4, test_network_v4)}")
test_ip_v6 = "2001:db8::1"
test_network_v6 = "2001:db8::/64"
print(f"Is {test_ip_v6} in {test_network_v6}? {check_ip_in_network(test_ip_v6, test_network_v6)}")
invalid_ip = "999.999.999.999"
valid_network = "10.0.0.0/8"
print(f"Is {invalid_ip} in {valid_network}? {check_ip_in_network(invalid_ip, valid_network)}")
Debug
Known issues
gotchaThis package only provides type stubs; the actual runtime functionality comes from Python's built-in `ipaddress` module. You do not import directly from `types_ipaddress` at runtime.fixAlways import `ipaddress` as usual: `import ipaddress` or `from ipaddress import ...`.
affects: All
breakingType stub versions are managed by the `typeshed` project. While `typeshed` aims for compatibility, updates to `types-ipaddress` might introduce changes that cause type-checking errors if your runtime `ipaddress` (i.e., your Python version) is significantly older or newer than what the stubs were last tested against. `typeshed` policy states 'any version bump can introduce changes that might make your code fail to type check'.fixPin the version of `types-ipaddress` in your `requirements.txt` to the one that is compatible with your specific Python environment. For example, `types-ipaddress==1.0.8`.
affects: All versions of `types-ipaddress` can potentially exhibit this if not aligned with the runtime Python version.
gotchaContributions and bug fixes for the `ipaddress` stubs should be made directly to the `python/typeshed` GitHub repository, not to the `types-ipaddress` PyPI project directly.fixWhen reporting issues or proposing changes, refer to the `typeshed` contribution guidelines: https://github.com/python/typeshed/blob/main/README.md
affects: All
deprecated`typeshed` officially dropped Python 2 support for `ipaddress` stubs in March 2022. While older `types-ipaddress` versions might exist, newer stubs will not support Python 2 type checking.fixEnsure your project uses Python 3.7+ for robust type checking with `types-ipaddress`.
affects: Versions released after March 2022 (e.g., if there's a 1.0.9+). The current 1.0.8 was released Jan 29, 2022, so it might still have Python 2 stubs, but these are not maintained.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'types_ipaddress'
The `types-ipaddress` package is a stub-only package for type checkers and is not meant to be imported at runtime as a regular Python module.
fixRemove the `import types_ipaddress` statement. If you intend to use the `ipaddress` module, import it directly as `import ipaddress`.
Missing type stubs for "ipaddress" (or implicitly `import`ed module "ipaddress")
MyPy is reporting that it cannot find type hints for the `ipaddress` module, which means the `types-ipaddress` stub package is not installed or discoverable.
fixInstall the type stubs using pip: `pip install types-ipaddress`.
No type information for "ipaddress" (reportMissingTypeStubs)
Pyright (or Pylance in VS Code) is indicating that it lacks type information for the `ipaddress` module, suggesting that the `types-ipaddress` stub package is either not installed or not configured correctly.
fixInstall the type stubs using pip: `pip install types-ipaddress`. Ensure your Pyright/Pylance environment can discover installed packages.
Upgrade
Version history
1.0.8latest on PyPI · released Jan 30, 2022
Audit
Dependencies
pythonrequiredThe `ipaddress` module is part of the Python standard library (since 3.3). `types-ipaddress` provides stubs for it. This stub package requires Python >=3.7.