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 ipaddrVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create IP address and network objects using the `ipaddr` library, check their properties, and perform basic network membership tests.
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/
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`.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.
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`.
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`.
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')`.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.
No dependency data recorded yet.