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.

Download
ActivePython
INSTALL>
pypm install pyutil

How to install pyutil

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install pyutil
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.9.3
1.9.7Never BuiltWhy not?
1.9.3 Available View build log
1.8.4 Available View build log
1.8.2 Available View build log
1.8.1 Available View build log
1.8.0 Available View build log
1.7.12 Failed View build log
1.7.11 Failed View build log
1.7.10 Failed View build log
Windows (64-bit)
1.9.3
1.9.7Never BuiltWhy not?
1.9.3 Available View build log
1.8.4 Available View build log
1.8.2 Available View build log
1.8.1 Available View build log
1.8.0 Available View build log
1.7.12 Failed View build log
1.7.11 Failed View build log
1.7.10 Failed View build log
Mac OS X (10.5+)
1.9.7 Available View build log
1.9.3 Available View build log
1.8.4 Available View build log
1.8.2 Available View build log
1.8.1 Available View build log
1.8.0 Available View build log
1.7.12 Failed View build log
1.7.11 Failed View build log
1.7.10 Failed View build log
Linux (32-bit)
1.9.7 Available View build log
1.9.4 Available View build log
1.9.3 Available View build log
1.8.4 Available View build log
1.8.2 Available View build log
1.8.1 Available View build log
1.8.0 Available View build log
1.7.12 Failed View build log
1.7.11 Failed View build log
1.7.10 Failed View build log
Linux (64-bit)
1.9.7 Available View build log
1.9.4 Available View build log
1.9.3 Available View build log
1.8.4 Available View build log
1.8.2 Available View build log
1.8.1 Available View build log
1.8.0 Available View build log
1.7.12 Failed View build log
1.7.11 Failed View build log
1.7.10 Failed View build log
 
License
GNU GPL
Dependencies
Lastest release
version 1.9.7 on Jun 1st, 2013

pyutil -- a library of useful Python functions and classes

Many of these utilities (or their ancestors) were developed for the Mojo Nation, Mnet, Allmydata.com "Mountain View", Tahoe-LAFS, or SimpleGeo's products. (In the case where the code was developed for a for-profit company, the copyright holder donated the pyutil code to the public under these open source licences.)

utilities

current modules

These are useful! Use them.

  • mathutil.py - integer power, floor, ceil, and nearest multiples; permute and fit slope
  • memutil.py - statistics and diagnostics for memory use and garbage collection
  • platformutil.py - get platform including Linux distro; more accurate and less noisy than platform.platform()
  • strutil.py - common prefix and suffix of two strings, and newline processing
  • assertutil.py - test preconditions, postconditions, and assertions
  • benchutil.py - benchmark a function by running it repeatedly
  • fileutil.py - work with files and directories
  • iputil.py - query available local IPv4 addresses
  • jsonutil.py - wrapper around simplejson which converts decimal inputs to Python Decimal objects instead of to Python floats
  • lineutil.py - remove extra whitespace from files
  • testutil.py - utilities for use in unit tests, especially in Twisted
  • time_format.py - date and time formatting operations
  • version_class.py - parse version strings into a Version Number object
  • verlib.py - utility to compare version strings, by Tarek Ziade
current scripts
  • passphrase - generate memorable random passphrases
  • verinfo - print out versioning information about a Python package and/or module
  • unsort - sort the lines of an input file into a random order
  • try_decoding - try decoding some bytes with every codec and print the results
  • lines - convert end-of-lines to the current system's native end-of-line format
  • tailx - print all but the first K lines of a file
out of shape modules

I don't currently use these, but I still think they are possibly good ideas.

  • nummedobj.py - number objects in order of creation for consistent debug output
  • observer.py - the Observer pattern
  • increasing.py - an implementation of a monotonically-increasing timer; By the way a future, better implementation of this would use CLOCK_MONOTONIC or CLOCK_MONOTONIC_RAW if it were available: http://stackoverflow.com/questions/1205722/how-do-i-get-monotonic-time-durations-in-python/1205762#1205762
  • repeatable_random.py - Make the random and time modules deterministic, so that executions can be reproducible.
  • cache.py - multiple implementations of a least-recently-used in-memory caching strategy, optimized for different sizes (note: I, Zooko, nowadays prefer a random-replacement cache eviction strategy over least-recently-used because the former has more consistent and predictable behavior)
  • odict.py - ordered dictionary implementation: see PEP 372. Note: there is now (as of Python 2.7) an ordered dict implementation in the standard library, but I haven't checked if it is as good as this one.
  • zlibutil.py - zlib decompression in limited memory
out of shape scripts
  • time_comparisons - empirically look for timing attacks (incomplete)
  • memdump2dot - generate graphviz file from memdump (probably incomplete)
deprecated modules

I no longer use these and I don't recommend that you do either.

  • logutil.py - send log messages to Twisted logger if present, else Python library logger
  • weakutil.py - allows a bound method's object to be GC'd
  • twistedutil.py - callLater_weakly, a variant of Twisted's callLater which interacts more nicely with weakrefs
  • PickleSaver.py - make all or part of an object persistent, by saving it to disk when it's garbage collected
  • humanreadable.py - an improved version of the builtin repr() function
  • hashexpand.py - cryptographically strong pseudo-random number generator based on SHA256
  • find_exe.py - try different paths in search of an executable
  • dictutil.py - several specialized dict extensions, as well as some convenient functions for working with dicts
  • randutil.py - various ways to get random bytes
  • xor.py - xor two same-length strings together
deprecated scripts
  • randcookie - deprecated in favor of passphrase
  • randfile - deprecated in favor of "head --bytes=$B /dev/urandom"

Thanks to Peter Westlake and Ravi Pinjala for help documenting what these do.

darcs repository

https://tahoe-lafs.org/source/pyutil/trunk

(To get the latest source, run darcs get --lazy https://tahoe-lafs.org/source/pyutil/trunk.)

tests and benchmarks

To run tests: python ./setup.py trial -s pyutil.test.current.

You can also run the tests with the standard pyunit test runner instead of trial, but a couple of the tests will fail due to the absence of Trial's "Skip This Test" feature. You can also run the tests of the out-of-shape and deprecated modules:

python ./setup.py trial -s pyutil.test.out_of_shape

python ./setup.py trial -s pyutil.test.deprecated

Or of all modules:

python ./setup.py trial -s pyutil.test

Some modules have self-benchmarks provided. For example, to benchmark the cache module: python -OOu -c 'from pyutil.test import test_cache; test_cache.quick_bench()'

or for more complete and time-consuming results: python -OOu -c 'from pyutil.test import test_cache; test_cache.slow_bench()'

(The "-O" is important when benchmarking, since cache has extensive self-tests that are optimized out when -O is included.)

LICENCE

You may use this package under the GNU General Public License, version 2 or, at your option, any later version. You may use this package under the Transitive Grace Period Public Licence, version 1.0, or at your option, any later version. (You may choose to use this package under the terms of either licence, at your option.) You may use this package under the Simple Permissive Licence, version 1 or, at your option, any later version. See the file COPYING.GPL for the terms of the GNU General Public License, version 2. See the file COPYING.TGPPL.html for the terms of the Transitive Grace Period Public Licence, version 1.0. See the file COPYING.SPL.txt for the terms of the Simple Permissive Licence, version 1.

Subscribe to package updates

Last updated Jun 1st, 2013

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.