iptree is a Python module which provides classes for representing IPv4 addresses and netmasks, particularly in tree structures organized by CIDR hierarchy.
For more information, see the module's pydoc documentation.