IPvAnyNetwork is a Pydantic type for validating IPv4 or IPv6 network values. It accepts an individual address or a CIDR range, making it a close model for an INET database column. section 9.5.2 section 9.3.2
Its behavior matters when application models, database types, and user-facing displays do not have identical requirements:
- A single address such as 127.0.0.1 is normalized to 127.0.0.1/32, where /32 explicitly represents one address. section 9.5.2
- A range such as 192.168.1.0/24 remains suitable for validation, although an audit record may require only one originating address. section 9.3.2
- Choosing IPvAnyNetwork because the database uses INET can expose implementation details in the interface; a display helper can remove a trailing /32. section 9.5.2
Validating an audit-log address
An AuditLogRecord can declare ip_address as Optional[IPvAnyNetwork]. A value of "192.168.1.0/24" can be inserted and retrieved, while an invalid value such as "127.0.0.256" raises a validation error.
