liveBook · Manning

IPvAnyNetwork

As explained in Build Financial Software with Generative AI (From Scratch)

IPvAnyNetwork is a Pydantic type that validates IPv4 or IPv6 network values, including individual addresses and address ranges.

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.

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Explains validation, CIDR normalization, and display consequences, but stops short of detailed IPv4 or IPv6 internals.
Examples
Uses 127.0.0.1, 192.168.1.0/24, invalid 127.0.0.256, and an AuditLogRecord persistence test.
What it assumes
Assumes basic Pydantic models and database fields, while teaching the difference between individual addresses and CIDR ranges.
What you can do after
Apply it via Pydantic to validate audit-record IP fields and recognize when normalized CIDR notation needs presentation cleanup.
How it connects
Connects Pydantic models with IPvAnyAddress, CIDR notation, INET data types, and audit logging.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.