[Python-Dev] PEP 3144: IP Address Manipulation Library for the Python Standard Library

Peter Moody peter at hda3.com
Fri Aug 21 18:24:46 CEST 2009

On Thu, Aug 20, 2009 at 10:15 PM, Case Vanhorsen<casevh at gmail.com> wrote:
>>On Thu, Aug 20, 2009 at 2:00 PM, Peter Moody<peter at hda3.com> wrote:
>> The pep has been updated with the excellent suggestions thus far.
>> Are there any more?
> Thanks for writing the PEP.
> I tried a few of the common scenarios that I use at work. Disclaimer:
> my comments are based on my work environment.
> I was surprised that IP('') returned
> IPv4Address('') instead of IPv4Address(''). I
> know I can change the behavior by using host=True, but then
> IP('', host=True) will raise an error. It makes more
> sense, at least to me, that if I input just an IP address, I get an IP
> address back. I would prefer that IP('') return an
> IPv4Network and IP('') return an IPv4Address.

I think you mean that it returns an IPv4Network object (not
IPv4Address).  My suggestion there is that if you know you're dealing
with an address, use one of the IPvXAddress classes (or pass host=True
to the IP function). IP is just a helper function and defaulting to a
network with a /32 prefix seems relatively common.

Knowing that my experience may not always be the most common, I can
change this behavior if it's indeed confusing, but in my conversations
with others and in checking out the current state of ip address
libraries, this seems to be a perfectly acceptable default.

> Would it be possible to provide an iterator that returns just the
> valid host IP addresses (minus the network and broadcast addresses)?
> "for i in IPv4Network('')" and "for in in
> IPv4Network('').iterhosts()" both return all 16 IP
> addresses. I normally describe as consisting of one
> network address, 14 host addresses, and one broadcast address. I would
> prefer that "for i in IPv4Network('')" return all IP
> addresses and that "for in in
> IPv4Network('').iterhosts()" exclude the network and
> broadcast addresses. I think creating a list of IP addresses that can
> be assigned to devices on a network is a common task.

this is a good idea and I'll implement this.  .iterhosts() for subnet
- (network|broadcast) and .iterallhosts() for the entire subnet (in my
testing, looping over an iterator was actually reasonably faster than
just for i in IP(network):, so I'll support iterators for both)

> Can .subnet() be enhanced to accept masks? For example,
> IPv4Network('').subnet('/19') would return the eight /19
> subnets.

This seems like an easy win. I'll implement this too.

> What about supporting multiple parameters to subnet? I frequently need
> to create complex subnet layouts. The following subnet layout is NOT
> made up!

I believe it, we have equally odd subnet assignments at work.


> A possible syntax would be:
> .subnet((1,'/23'),(1,'/25'),(2,'/26'),(2,'/28'),(8,'/30'),(16,'/32'),(3,'/28'),(2,'/27'),(1,'/26'))
> Note: I am willing to provide patches to implement my suggestions. I
> just won't have much time over the next couple weeks.

I'm happy reviewing/accepting patches to ipaddr. I'd worry a bit about
the complexity required for this, but I'm open-minded.

> casevh
>> Cheers,
>> /peter
>> On Tue, Aug 18, 2009 at 1:00 PM, Peter Moody<peter at hda3.com> wrote:
>>> Howdy folks,
>>> I have a first draft of a PEP for including an IP address manipulation
>>> library in the python stdlib. It seems like there are a lot of really
>>> smart folks with some, ahem, strong ideas about what an IP address
>>> module should and shouldn't be so I wanted to solicit your input on
>>> this pep.
>>> the pep can be found here:
>>>  http://www.python.org/dev/peps/pep-3144/
>>> the code can be found here:
>>>  http://ipaddr-py.googlecode.com/svn/branches/2.0.x/
>>> Please let me know if you have any comments (some already coming :)
>>> Cheers,
>>> /peter
>> _______________________________________________
>> Python-Dev mailing list
>> Python-Dev at python.org
>> http://mail.python.org/mailman/listinfo/python-dev
>> Unsubscribe: http://mail.python.org/mailman/options/python-dev/casevh%40gmail.com

More information about the Python-Dev mailing list