{"id":4303,"library":"types-ipaddress","title":"Typing Stubs for ipaddress","description":"types-ipaddress is a PEP 561 compliant stub-only package providing static type hints for Python's built-in `ipaddress` module. It allows type-checking tools like MyPy, PyCharm, and Pyright to perform static analysis on code that uses `ipaddress` functionality. The package tracks the `ipaddress` stubs within the `typeshed` project and is released upon changes to those stubs. The current version is 1.0.8.","status":"active","version":"1.0.8","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed/tree/master/stubs/ipaddress","tags":["typing","stubs","type hints","ip address","network","typeshed"],"install":[{"cmd":"pip install types-ipaddress","lang":"bash","label":"Install types-ipaddress"}],"dependencies":[{"reason":"The `ipaddress` module is part of the Python standard library (since 3.3). `types-ipaddress` provides stubs for it. This stub package requires Python >=3.7.","package":"python","optional":false}],"imports":[{"symbol":"ip_address","correct":"from ipaddress import ip_address"},{"symbol":"ip_network","correct":"from ipaddress import ip_network"},{"symbol":"IPv4Address","correct":"from ipaddress import IPv4Address"},{"symbol":"IPv6Address","correct":"from ipaddress import IPv6Address"},{"symbol":"IPv4Network","correct":"from ipaddress import IPv4Network"},{"symbol":"IPv6Network","correct":"from ipaddress import IPv6Network"}],"quickstart":{"code":"import ipaddress\n\ndef check_ip_in_network(ip_str: str, network_str: str) -> bool:\n    try:\n        ip_addr = ipaddress.ip_address(ip_str)\n        network = ipaddress.ip_network(network_str, strict=False)\n        return ip_addr in network\n    except ValueError as e:\n        print(f\"Error: {e}\")\n        return False\n\nif __name__ == \"__main__\":\n    test_ip_v4 = \"192.168.1.5\"\n    test_network_v4 = \"192.168.1.0/24\"\n    print(f\"Is {test_ip_v4} in {test_network_v4}? {check_ip_in_network(test_ip_v4, test_network_v4)}\")\n\n    test_ip_v6 = \"2001:db8::1\"\n    test_network_v6 = \"2001:db8::/64\"\n    print(f\"Is {test_ip_v6} in {test_network_v6}? {check_ip_in_network(test_ip_v6, test_network_v6)}\")\n\n    invalid_ip = \"999.999.999.999\"\n    valid_network = \"10.0.0.0/8\"\n    print(f\"Is {invalid_ip} in {valid_network}? {check_ip_in_network(invalid_ip, valid_network)}\")","lang":"python","description":"This quickstart demonstrates basic usage of the `ipaddress` module, including creating IP address and network objects, and checking for membership. When `types-ipaddress` is installed, a static type checker would verify the type annotations in `check_ip_in_network` against the provided stubs for `ipaddress` objects."},"warnings":[{"fix":"Always import `ipaddress` as usual: `import ipaddress` or `from ipaddress import ...`.","message":"This package only provides type stubs; the actual runtime functionality comes from Python's built-in `ipaddress` module. You do not import directly from `types_ipaddress` at runtime.","severity":"gotcha","affected_versions":"All"},{"fix":"Pin the version of `types-ipaddress` in your `requirements.txt` to the one that is compatible with your specific Python environment. For example, `types-ipaddress==1.0.8`.","message":"Type stub versions are managed by the `typeshed` project. While `typeshed` aims for compatibility, updates to `types-ipaddress` might introduce changes that cause type-checking errors if your runtime `ipaddress` (i.e., your Python version) is significantly older or newer than what the stubs were last tested against. `typeshed` policy states 'any version bump can introduce changes that might make your code fail to type check'.","severity":"breaking","affected_versions":"All versions of `types-ipaddress` can potentially exhibit this if not aligned with the runtime Python version."},{"fix":"When reporting issues or proposing changes, refer to the `typeshed` contribution guidelines: https://github.com/python/typeshed/blob/main/README.md","message":"Contributions and bug fixes for the `ipaddress` stubs should be made directly to the `python/typeshed` GitHub repository, not to the `types-ipaddress` PyPI project directly.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure your project uses Python 3.7+ for robust type checking with `types-ipaddress`.","message":"`typeshed` officially dropped Python 2 support for `ipaddress` stubs in March 2022. While older `types-ipaddress` versions might exist, newer stubs will not support Python 2 type checking.","severity":"deprecated","affected_versions":"Versions released after March 2022 (e.g., if there's a 1.0.9+). The current 1.0.8 was released Jan 29, 2022, so it might still have Python 2 stubs, but these are not maintained."}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}