Skip to main content

ipaddress backport for Python 2.6 and 2.7

This is a Python 2.6 backport of the Python 3.4 ipaddress module.

Please refer to the official Python 3.4 documentation for more information on the module.

Differences from Python 3.4’s ipaddress module

The backport should behave identically to 3.4, except as noted here.

bytearray instead of bytes

Since Python 2 has no distinct bytes type, bytearray is used instead for the “packed” (binary) address representation:

>>> ipaddress.ip_address(bytearray('\xc0\xa8\x54\x17'))
IPv4Address('192.168.84.23')
>>> ipaddress.ip_address('127.0.0.17').packed
bytearray(b'\x7f\x00\x00\x11')

This means py2-ipaddress can accept both Python 2 string types (str and unicode) for the textual address representation.

If you prefer semantics closer to Python 3, you may be interested in Philipp Hagemeister’s ipaddress backport, which uses str for the “packed” address representation, but then requires all textual IP addresses to be given as unicode strings. That backport also supports Python 3.0–3.2.

Caching of is_private and is_global

Since Python 2.7’s functools module does not have Python 3.2’s lru_cache, no caching is performed for the is_private and is_global properties; this should be a minor problem as Python 3.3’s ipaddress did not use lru_cache either.

Changelog

py2-ipaddress 3.4.2

Test suite and documentation improvements.

py2-ipaddress 3.4.1

Python 2.6 support and a bugfix.

py2-ipaddress 3.4

Since Python 2 does not distinguish between bytes and str like Python 3 does, version 2.0.1 and earlier of py2-ipaddress attempted to interpret str arguments as both and do the “right” thing.

This unfortunately led to surprising behavior in py2-ipaddress:

>>> ipaddress.ip_address('test.example.org')
IPv6Address('7465:7374:2e65:7861:6d70:6c65:2e6f:7267')

The ipaddress module does not, of course, perform DNS resolution. Rather, the argument is interpreted as a byte string (of length 16) and converted bit-for-bit into an IPv6 address. In Python 3, ipaddress correctly rejects such a constructor argument (unless the b prefix is used to explicitly mark the literal as a byte string).

Even worse, there is not always a single right interpretation. Python 3 example:

>>> ipaddress.ip_address('::1234:5678:9abc')
IPv6Address('::1234:5678:9abc')
>>> ipaddress.ip_address(b'::1234:5678:9abc')
IPv6Address('3a3a:3132:3334:3a35:3637:383a:3961:6263')

There is no way to distinguish the two invocations in Python 2. As a result, py2-ipaddress 3.4 uses bytearray for all byte strings, and str for text strings only:

>>> ipaddress.ip_address('::1234:5678:9abc')
IPv6Address('::1234:5678:9abc')
>>> ipaddress.ip_address(b'::1234:5678:9abc')
IPv6Address('::1234:5678:9abc')
>>> ipaddress.ip_address(bytearray('::1234:5678:9abc'))
IPv6Address('3a3a:3132:3334:3a35:3637:383a:3961:6263')

License

The ipaddress modules (both the original and this backport) are licensed under the Python Software Foundation License version 2.

The modifications made for Python 2.6 compatibility are hereby released into the public domain by the authors.

Metadata

Release files for py2-ipaddress 3.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py2-ipaddress 3.4.2
File Size Uploaded Provenance Actions
py2-ipaddress-3.4.2.tar.gz 17.1 kB Without provenance Details for py2-ipaddress-3.4.2.tar.gz

Release files / py2-ipaddress-3.4.2.tar.gz

Download URL py2-ipaddress-3.4.2.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
097a2631ab0ac33425babbdc901ae671fb0d56932ebad748ee245ba6d64ad14c
BLAKE2b-256 checksum
How to use checksums
43fdac6cd46b9f0150749041944dd2c7fe5903a67770d2d68deeae1b5db2fa1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.17

Security for py2-ipaddress 3.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page