Skip to main content

Python library for anonymizing IP addresses

Project description


This is a simple Python library for anonymizing IP addresses. Both IPv4 and IPv6 addresses are supported.


  • IPv4:
  • IPv6: 5219:3a94:fdc5:19e1:70a3:b2c4:40ef:ae035219:3a94:fdc5:19e1::


pip install anonymizeip
from anonymizeip import anonymize_ip

address = "fe80::0202:b3ff:fe1e:8329"
anonymized = anonymize_ip(address)

# Prints "fe80::"


The number of address blocks that are set to 0 can be customized.

Besides the IP address, the function anonymize_ip takes two optional parameters:

  • ipv4_mask: Defaults to, i.e. the last octet will be anonymized (set to 0)
  • ipv6_mask: Defaults to ffff:ffff:ffff:ffff:: (same as ffff:ffff:ffff:ffff:0:0:0:0), i.e. the last four blocks will be anonymized (set to 0)


  1. git clone
  2. pipenv install --dev
  3. Make your code modifications
  4. pipenv run test
  5. pipenv run lint

Contributions are always welcome. Please first discuss changes via issue before submitting a pull request.


The implementation of this library was strongly inspired by php-ip-anonymizer by Geert Wirken.

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
anonymizeip-1.0.0-py2.py3-none-any.whl (3.4 kB) Copy SHA256 hash SHA256 Wheel py2.py3
anonymizeip-1.0.0.tar.gz (4.3 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page