{"id":1581,"library":"netaddr","title":"netaddr: Network Address Manipulation Library","description":"netaddr is a Python library for manipulating network addresses, subnets, MAC addresses, and related network concepts. It supports IPv4, IPv6, EUI (MAC addresses), OUI, and IAB objects, providing a rich API for parsing, validating, converting, and performing operations like aggregation, intersection, and iteration. The current version is 1.3.0, and it maintains an active, albeit irregular, release cadence.","status":"active","version":"1.3.0","language":"en","source_language":"en","source_url":"https://github.com/netaddr/netaddr/","tags":["networking","ip","ipv6","ipv4","mac-address","subnetting"],"install":[{"cmd":"pip install netaddr","lang":"bash","label":"Install netaddr"}],"dependencies":[],"imports":[{"symbol":"IPAddress","correct":"from netaddr import IPAddress"},{"symbol":"IPNetwork","correct":"from netaddr import IPNetwork"},{"symbol":"IPSet","correct":"from netaddr import IPSet"},{"symbol":"EUI","correct":"from netaddr import EUI"},{"note":"Common formatter for MAC addresses","symbol":"mac_unix_common","correct":"from netaddr.formatters import mac_unix_common"}],"quickstart":{"code":"from netaddr import IPNetwork, IPAddress, EUI\n\n# --- IP Network and Address Manipulation ---\nip_net = IPNetwork('192.168.0.0/24')\nprint(f\"\\nNetwork: {ip_net} (version {ip_net.version})\")\nprint(f\"Number of hosts: {ip_net.num_hosts}\")\nprint(f\"First usable address: {ip_net.first}\")\nprint(f\"Last usable address: {ip_net.last}\")\n\n# Iterate through hosts (excluding network and broadcast addresses)\nprint(\"First 3 hosts in network:\")\nfor i, ip in enumerate(ip_net.hosts()):\n    if i >= 3:\n        break\n    print(f\"  - {ip}\")\n\n# Check if an IP is within a network\nip_addr = IPAddress('192.168.0.10')\nprint(f\"Is {ip_addr} in {ip_net}? {ip_addr in ip_net}\")\n\n# --- MAC Address (EUI) Manipulation ---\nmac = EUI('00-01-02-03-04-05')\nprint(f\"\\nMAC Address: {mac}\")\nprint(f\"MAC as integer: {int(mac)}\")\nprint(f\"Vendor prefix (OUI): {mac.oui}\")\n\n# Generate a different format\nprint(f\"MAC in Cisco format: {mac.format(dialect='cisco')}\")","lang":"python","description":"This quickstart demonstrates the creation and basic manipulation of IPNetwork, IPAddress, and EUI objects. It shows how to inspect network properties, iterate through hosts, check for address membership, and format MAC addresses."},"warnings":[{"fix":"Review code that relied on the previous behavior of `num_hosts` or address iteration for RFC 6164 IPv6 subnets if migrating from versions older than 0.9.0.","message":"The handling of RFC 6164 IPv6 point-to-point subnets changed. `netaddr` no longer reserves the first IP address, affecting `num_hosts` and address iteration for these specific subnets.","severity":"breaking","affected_versions":"< 0.9.0"},{"fix":"Ensure your logic correctly identifies `::1/128` as a loopback address if it previously relied on the incorrect `False` return value.","message":"The `is_loopback` property for `IPNetwork('::1/128')` (and similar IPv6 loopback representations) now correctly returns `True`. Prior versions returned `False`.","severity":"breaking","affected_versions":"< 0.9.0"},{"fix":"For `IPSet` operations, be mindful of methods that modify the set in-place versus those that return a new set. For `IPAddress` and `IPNetwork`, generally assume immutability for their core network and address values.","message":"While core `IPAddress` and `IPNetwork` objects are generally treated as immutable once created, some operations on `IPSet` are in-place, and certain properties like `IPNetwork.netmask` can be reassigned. Be aware of mutable vs. immutable behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Explicitly instantiate `IPAddress()`, `IPNetwork()`, or `EUI()` from strings or other data types before performing operations, rather than relying on implicit conversions.","message":"Operations often expect specific `netaddr` object types (`IPAddress`, `IPNetwork`, `EUI`). Passing raw strings or incompatible types can lead to errors. Always explicitly convert when necessary.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}