{"id":8741,"library":"types-netaddr","title":"Typing Stubs for netaddr","description":"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`.","status":"active","version":"1.3.0.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","netaddr","typeshed","mypy","pyright"],"install":[{"cmd":"pip install types-netaddr","lang":"bash","label":"Install typing stubs"}],"dependencies":[{"reason":"This package provides type stubs for `netaddr`; `netaddr` itself must be installed to actually use the functionality.","package":"netaddr","optional":false}],"imports":[{"note":"`types-netaddr` provides stubs, not the runtime library. Imports should always be from the actual `netaddr` package.","wrong":"from types_netaddr import IPAddress","symbol":"IPAddress","correct":"from netaddr import IPAddress"},{"note":"You never import directly from `types_netaddr`. It's automatically picked up by type checkers for `netaddr`.","wrong":"import types_netaddr","symbol":"IPNetwork","correct":"from netaddr import IPNetwork"}],"quickstart":{"code":"from netaddr import IPAddress\n\ndef check_ip_type(ip_str: str) -> bool:\n    ip = IPAddress(ip_str)\n    return ip.is_unicast()\n\n# Example usage (runtime behaviour is handled by netaddr)\n# Type checkers will use types-netaddr to validate the above type hints.\nprint(check_ip_type('192.168.1.1'))\nprint(check_ip_type('224.0.0.1'))","lang":"python","description":"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."},"warnings":[{"fix":"Ensure both `pip install netaddr` and `pip install types-netaddr` are executed.","message":"Installing `types-netaddr` does NOT install the `netaddr` library itself. It only provides typing stubs. You must install `netaddr` separately if you intend to run the code.","severity":"gotcha","affected_versions":"All versions"},{"fix":"All imports should be `from netaddr import ...`.","message":"You should never import directly from `types_netaddr`. The stubs are automatically discovered by type checkers for imports made from the actual `netaddr` library.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you are using a type checker in your development workflow to benefit from the stubs.","message":"These stubs are only useful for static type checking tools (e.g., MyPy, Pyright). They do not alter runtime behavior or provide any new functionality at runtime.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"The `types-netaddr` package provides stubs, not a runtime module to be imported. You should import from the actual `netaddr` library (e.g., `from netaddr import IPAddress`). Type checkers will automatically use the stubs.","cause":"Attempting to import directly from the `types_netaddr` package.","error":"ModuleNotFoundError: No module named 'types_netaddr'"},{"fix":"Install the separate stub package: `pip install types-netaddr`.","cause":"The `netaddr` library itself does not ship with its own type stubs, and `types-netaddr` has not been installed.","error":"mypy: Missing type stubs for 'netaddr' (or similar error from other type checkers) even after 'pip install netaddr'"}]}