Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install utils

How to install utils

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install utils
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.5Never BuiltWhy not?
0.1 Available View build log
Windows (64-bit)
0.5Never BuiltWhy not?
0.1 Available View build log
Mac OS X (10.5+)
0.5Never BuiltWhy not?
0.1 Available View build log
Linux (32-bit)
0.5Never BuiltWhy not?
0.1 Available View build log
Linux (64-bit)
0.5 Available View build log
0.1 Available View build log
Lastest release
version 0.5 on Jan 9th, 2014

Sometimes you write a function over and over again; sometimes you look up at the ceiling and ask "why, Guido, why isn't this included in the standard library?"

Well, we perhaps can't answer that question. But we can collect those functions into a centralized place!

Provided things

Utils is broken up into broad swathes of functionality, to ease the task of remembering where exactly something lives.


Python doesn't have a built-in way to define an enum, so this module provides (what I think) is a pretty clean way to go about them.

from utils import enum

class Colors(enum.Enum):
    RED = 0
    GREEN = 1

    # Defining an Enum class allows you to specify a few
    # things about the way it's going to behave.
    class Options:
        frozen = True # can't change attributes
        strict = True # can only compare to itself; i.e., Colors.RED == Animals.COW
                      # will raise an exception.

# or use the enum factory (no Options, though)
ColorsAlso = enum.enum("RED", "GREEN")

Once defined, use is straightforward:

>>> Colors
<class 'blahblah.Colors'>
>>> Colors.RED
<EnumItem: RED [0]>
>>> Colors.RED == 0
>>> Colors.RED == Colors.RED
>>> Colors.RED = 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "utils/enum.py", line 114, in __setattr__
    raise TypeError("can't set attributes on a frozen enum")
TypeError: can't set attributes on a frozen enum

Currently only has the multiplicative analogue of the built-in sum.


intersections, differences, winnowing, a few specialized dicts...


flatten and unlisting


currently only provides an xor function.


Mostly cool for the TimePeriod classes:

>>> from datetime import date # will also work with datetimes
>>> time_period = TimePeriod(date(2013, 5, 10), date(2013, 8, 11))
>>> time_period
<TimePeriod: 2013-05-10 00:00:00-2013-08-11 23:59:59>
>>> date(2013, 6, 12) in time_period
>>> other_time_period = TimePeriod(date(2013, 6, 1), date(2013, 6, 30))
>>> other_time_period in time_period
>>> another_time_period = TimePeriod(date(2013, 8, 1), date(2013, 8, 30))
>>> time_period.overlaps(another_time_period)
>>> TimePeriod.get_containing_period(time_period, another_time_period)
<TimePeriod: 2013-05-08 00:00:00-2013-08-30 23:59:59>

and so on and so forth. There's also a DiscontinousTimePeriod class, which stores a collection of TimePeriods.

There's also helper functions for common operations like days_ahead and days_ago, which pretty much do what they say on the tin.

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.