django-netfields
Django PostgreSQL netfields implementation
What it is and what it does
django-netfields extends Django's ORM with proper PostgreSQL network data types, replacing the inefficient built-in IP fields with native INET, CIDR, MACADDR, and MACADDR8 field types. The package maps these PostgreSQL types to Python's ipaddress module (for IP fields) and netaddr.EUI (for MAC fields), eliminating costly HOST() casts in queries and enabling IPv6 support.
The package includes NetManager, which unlocks advanced network-based lookups directly in the ORM—containment checks, overlap detection, family matching, prefix length filtering, and more—corresponding to PostgreSQL's native network functions. It also exposes Postgres network functions (Family, Masklen, Broadcast, etc.) as Django database functions for complex queries and annotations.
Use it for:
- Store and query IP addresses and subnets efficiently in Django models backed by PostgreSQL
- Perform network containment and overlap queries without application-level filtering
- Track MAC addresses in network device or inventory models
- Build IP-based access control or firewall rule systems with native database queries
- Annotate models with extracted network metadata (family, netmask length, broadcast address)
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides Django model fields for PostgreSQL network types (INET, CIDR, MACADDR, MACADDR8) with native IP and MAC address handling and advanced network-based ORM lookups.
Yes. The package is actively maintained, has no known vulnerabilities, and solves a real problem—efficient network data handling in Django+PostgreSQL. Install if you need to store or query IP/CIDR/MAC data; skip if you're not using PostgreSQL or don't need network-specific lookups.
Install
django-netfields on PyPI
pip
pip install django-netfieldsuv
uv add django-netfieldspoetry
poetry add django-netfieldsInstalling django-netfields
Before you install
Low friction: pure Python wheel with only netaddr and django as runtime dependencies. Actively maintained with a recent commit on 2026-03-05 and no known vulnerabilities.
License in practice
BSD license is permissive; you can use, modify, and distribute this package freely with minimal restrictions.
Quickstart
pip install django-netfields
from netfields import InetAddressField, NetManager
from django.db import models
class Example(models.Model):
inet = InetAddressField()
objects = NetManager()
# Query with network lookups
Example.objects.filter(inet__net_contained='10.0.0.0/8')
Requires PostgreSQL backend; psycopg2 or psycopg driver must be installed separately. Django >= 1.11 required.
Verify before relying
- Whether the package supports Django versions newer than 1.11
- Performance characteristics of network lookups on large datasets
- Compatibility with psycopg2 vs. psycopg driver versions
Package facts
| License | BSD (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — netaddr, django |
| Maintenance | actively maintained — 162 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 179,571/month — #10,168 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_netfields-1.4.1-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
django-allow-cidrA Django middleware that extends ALLOWED_HOSTS…
permissive · top 5,000 on PyPI
netaddrRepresents and manipulates IPv4, IPv6, MAC…
permissive · top 5,000 on PyPI
django-citextProvides PostgreSQL CIText field types for…
permissive · top 15,000 on PyPI
ipaddressProvides IPv4 and IPv6 address manipulation for…
permissive · top 5,000 on PyPI
iptoolsProvides utilities for parsing, validating, and…
permissive · top 15,000 on PyPI
django-user-sessionsReplaces Django's opaque session backend with…
permissive · top 15,000 on PyPI
IPyIPy provides Python classes for parsing,…
permissive · top 5,000 on PyPI
py-radixImplements a radix tree data structure for…
permissive · top 15,000 on PyPI
ipaddrProvides utilities for parsing, validating, and…
permissive · top 15,000 on PyPI