A correct, immutable, strict-parsing address library with no runtime
dependencies and a single clean exception tree — suitable for protocol
stacks, network tooling, and anywhere ipaddress is too loose or does
not give you hashable / orderable / MAC / wildcard / interface-address
value types.
Two ABC roots — Base (the value-type contract: __str__ / __repr__
/ __eq__ / __hash__) and Ip (the IP-version mixin: version /
is_ip4 / is_ip6, mixed into every IP-versioned family but notMacAddress). Concrete leaves are @final:
Base value-type contract
Ip IP-version mixin
Address(Base)
├── IpAddress(Address, Ip)
│ ├── Ip4Address @final
│ └── Ip6Address @final
└── MacAddress @final (no Ip mixin — a MAC has no IP version)
IpNetwork[A, M](Base, Ip) ├── Ip4Network @final └── Ip6Network @final
IfAddr[A, N](Base, Ip) ├── Ip4IfAddr @final └── Ip6IfAddr @final
IpMask(Base, Ip) ├── Ip4Mask @final └── Ip6Mask @final
IpWildcard(Base, Ip) ├── Ip4Wildcard @final └── Ip6Wildcard @final
IpVersion IntEnum (IP4 / IP6)
The generics use PEP 695 syntax: IpNetwork[A, M] is parameterised
over its address and mask type, IfAddr[A, N] over its address and
network type. @final on every leaf is load-bearing — the
isinstance(other, type(self))-based __eq__ / __hash__ is
symmetric and hash-consistent only for non-subclassable leaves.
Public API
from pmd_net_addr import … exposes the concrete value types, the ABCs
(for typing), the IpVersion enum, the length constants
(IP4__ADDRESS_LEN, IP6__ADDRESS_LEN, MAC__ADDRESS_LEN), and the
full *Error tree. The opt-in ClickType* argument types
(ClickTypeIp4Address, ClickTypeIp6IfAddr, …) are re-exported
lazily — from pmd_net_addr import ClickTypeIp4Address works but pulls in
click only on first access, so the base import stays stdlib-only.
Ip4IfAddr / Ip6IfAddr are pure (address, network) value
pairs — there is no mutable per-address metadata. A default gateway
is not interface-address state: it is routing state, owned by the
consuming stack's routing table (FIB) / Route API. Mutating a value
type means constructing a fresh instance, never assigning to a field.
Exception model
One tree, three catchable supersets per leaf, never a bare builtin:
*FormatError is construction failure; *SanityError is everything
else (a precondition such as multicast_mac on a non-multicast
address, a bad subnets() / address_exclude() argument, an
out-of-range network[i], an unknown __format__ code). Mask and
wildcard types have a Format axis only — they can fail only at
construction. PyTCP does not mirror stdlib ipaddress's
ValueError / IndexError: catch NetAddrError (or a precise
subclass) instead.
Installation
pip install PyTCP-pmd_net_addr
Stdlib-only. The optional Click argument types are an extra:
Python 3.14+ (the library uses PEP 695 generics and modern
typing).
Current state (3.0.7)
23 source modules; 2610 unit tests, ~99% source coverage (the
remaining lines are @abstractmethod stub bodies, a documented
unreachable NoReturn guard, and the lazy-click__getattr__
exercised in subprocess probes).
Addressing-RFC fidelity (RFC 4291 scopes, 5952 canonical text, 4007
zones, 1918 / 4193 classification, 7217 / 8981 IID generation) is
encoded in code + unit tests, not in docs/rfc — by design,
since this is a value-type library, not a wire protocol. The
authoring contract lives in
.claude/rules/pmd_net_addr.md.
License
GPL-3.0-or-later. Part of the PyTCP project by Sebastian Majewski.
Same project
Also published from ccie18643/pytcp.
pmd-pytcpPure-Python, zero-dependency TCP/IP stack — Ethernet through RFC 9293 TCP — running in user space on a TAP/TUN interface, embeddable in-process or run as a daemon, with a Berkeley-sockets API.
pmd-net-protoThe network-protocol packet parse/assemble layer of the PyTCP stack — Ethernet through TCP/UDP — fully usable on its own.