Registry / serialization / ipaddr

ipaddr

JSON →
library2.2.0pypypi✓ verified 84d ago

ipaddr (pypi-slug: ipaddr) is a Python library developed by Google for manipulating IPv4 and IPv6 addresses and networks. It provides functionalities for validation, subnet operations, and summarization. The last release was version 2.2.0 in 2017. This library has been superseded by the `ipaddress` module, which is part of the Python 3 standard library.

pip install ipaddr
INSTALL
IMPORT
SIG · IPADDR
I
ipaddr
serializationpythonv2.2.0
Install
2.4s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.2.0 · 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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

IPAddress
from ipaddr import IPAddress
import ipaddr.IPAddress
IPAddress is a class, import directly or use ipaddr.IPAddress() after importing the module.
IPNetwork
from ipaddr import IPNetwork
import ipaddr.IPNetwork
IPNetwork is a class, import directly or use ipaddr.IPNetwork() after importing the module.

This quickstart demonstrates how to create IP address and network objects using the `ipaddr` library, check their properties, and perform basic network membership tests.

import ipaddr # Create an IPv4 address object ip_v4 = ipaddr.IPAddress('192.168.1.1') print(f"IPv4 Address: {ip_v4}") print(f"Is private: {ip_v4.is_private}") # Create an IPv6 address object ip_v6 = ipaddr.IPAddress('2001:db8::1') print(f"IPv6 Address: {ip_v6}") # Create a network object network = ipaddr.IPNetwork('192.168.1.0/24') print(f"Network: {network}") print(f"Network address: {network.network}") print(f"Broadcast address: {network.broadcast}") print(f"Number of hosts: {network.numhosts}") # Check if an address is in a network print(f"192.168.1.5 in network: {ipaddr.IPAddress('192.168.1.5') in network}")
Debug
Known issues
breakingThe `ipaddr` library has been officially superseded by the `ipaddress` module, which is included in the Python 3 standard library. The PyPI package for `ipaddr` is primarily a backport for Python 2. Users on Python 3 should migrate to `ipaddress` for future compatibility and maintenance.
fix
Migrate your codebase from `ipaddr` to the built-in `ipaddress` module. The API is largely similar but has some differences (e.g., stricter network object creation, renamed factory functions). Refer to PEP 3144 for a detailed comparison of API changes: https://peps.python.org/pep-3144/
affects: All versions (migration recommended for Python 3 users)
gotchaWhen creating `IPNetwork` objects with `ipaddr`, the library is more lenient about host bits being set compared to the `ipaddress` module. In `ipaddress`, creating a network object like `ipaddress.ip_network('192.168.1.5/24')` would raise a `ValueError` because the host bits are set. `ipaddr` might implicitly correct this or allow it depending on the version and specific method.
fix
Always ensure the host portion of a network address is zero when defining a network, e.g., '192.168.1.0/24'. If migrating to `ipaddress`, be aware that `ipaddress`'s `*Network` classes default to `strict=True`, requiring canonical network addresses. For interface objects (address on a network), use `ipaddr.IPNetwork('192.168.1.5/24', strict=False)` or `ipaddress.ip_interface('192.168.1.5/24')` in `ipaddress`.
affects: All `ipaddr` versions, compared to `ipaddress` module
deprecatedThe `ipaddr.IPAddress()` and `ipaddr.IPNetwork()` factory functions had equivalent, but slightly different, behavior and naming conventions compared to the `ipaddress.ip_address()` and `ipaddress.ip_network()` factory functions in the standard library.
fix
When migrating to the `ipaddress` module, use `ipaddress.ip_address()` for addresses and `ipaddress.ip_network()` for networks. These factory functions automatically determine the IP version (IPv4 or IPv6) and return the appropriate object.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'ipaddr'
The `ipaddr` library is either not installed in your Python environment or you are attempting to use it in Python 3, where it has been superseded by the built-in `ipaddress` module.
fix
For Python 3 and newer, use the standard library's `ipaddress` module: `import ipaddress`. If you must use the `ipaddr` library (e.g., for legacy Python 2 code), install it using pip: `pip install ipaddr`.
SyntaxError: invalid syntax (related to `0L` with `ipaddr`)
The `ipaddr` library was primarily designed for Python 2, and code written for it often uses Python 2-specific syntax, such as `0L` for long integers, which is invalid in Python 3.
fix
Rewrite the Python 2 `ipaddr` code to use the standard `ipaddress` module and its Python 3-compatible syntax. For example, remove `L` from integer literals: `ip_int = 0`.
AttributeError: 'IPAddress' object has no attribute 'is_private'
This error often occurs when migrating code from `ipaddr` or another IP address library (like `netaddr`) to Python's built-in `ipaddress` module, or when wrapper libraries change their underlying implementation. The `is_private` attribute or method might exist in `ipaddr` or `netaddr` but not directly on the `ipaddress.IPAddress` (or `IPv4Address`/`IPv6Address`) object, or its name/behavior has changed.
fix
Use the correct attribute from the `ipaddress` module. For checking private IP addresses, use the `is_private` attribute directly on `IPv4Address` or `IPv6Address` objects from the `ipaddress` module: `import ipaddress; addr = ipaddress.ip_address('192.168.1.1'); if addr.is_private: print('Private IP')`.
ValueError: 'invalid_ip_string' does not appear to be an IPv4 or IPv6 address
This generic error indicates that the string provided to an IP address or network constructor function (like `ipaddr.IP()` or `ipaddress.ip_address()`) is not in a valid IPv4 or IPv6 format.
fix
Ensure that the input string represents a syntactically correct IP address or network. If using `ipaddress`, for more specific validation errors, use `ipaddress.IPv4Address()`, `ipaddress.IPv6Address()`, `ipaddress.IPv4Network()`, or `ipaddress.IPv6Network()` directly, which raise `AddressValueError` or `NetmaskValueError` with more detailed messages.
Upgrade
Version history
2.2.0latest on PyPI · released Sep 15, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources