Typing Stubs for netaddr

1.3.0.20260408 · active · verified Thu Apr 16

This package provides static type checking stubs for the `netaddr` library, enabling tools like MyPy or Pyright to perform comprehensive type analysis on code that uses `netaddr`. It is part of the Python typeshed project, which maintains type hints for popular Python packages. The current version is `1.3.0.20260408` and it follows the release cadence of the typeshed project, updating frequently to reflect changes in `netaddr`.

Common errors

Warnings

Install

Imports

Quickstart

To use `types-netaddr`, you first need to install both `netaddr` and `types-netaddr`. You then write your Python code using `netaddr` with type hints as usual. A type checker like MyPy or Pyright will automatically find and utilize the stubs provided by `types-netaddr` during static analysis, without requiring any special imports from `types_netaddr` itself. The example shows a simple function using `IPAddress` with type hints, which would be checked by a type checker.

from netaddr import IPAddress

def check_ip_type(ip_str: str) -> bool:
    ip = IPAddress(ip_str)
    return ip.is_unicast()

# Example usage (runtime behaviour is handled by netaddr)
# Type checkers will use types-netaddr to validate the above type hints.
print(check_ip_type('192.168.1.1'))
print(check_ip_type('224.0.0.1'))

view raw JSON →