Skip to main content

Simple and flexible password generation library.

Project description

Copyright 2012 Elvio Toccalino.


The grampg (cue to Grumpy Admin Password Generator, and pronounced “grummpeegee”) is a small Python library which allows to generate passwords according to (possibly complicated) user specs. The idea is simple: build an instance, feed it your desired specifications, then generate as many passwords as you want. Each password generated will be independent of the others, except from the fact that all of them will comply with the specs.

The objectives for the grampg are flexibility and easy of use. grampg fulfills by providing a kind interface to the user: When building the password generator the user writes the spec as if it were being pronounced. In this fashion, a set of complex rules is expressed in a declarative line.


Typical usage follows the pattern outlined before: build a generator instance, feed it your specs, collect your passwords. This brief explanation fails to explain how, which is the main attractive of the grampg. As an example, consider the following:

Your admin needs your system to produce passwords of between 5 and 10 letters, at least 4 numbers, adding up to 10 characters total. Oh, and since this passwords may be used in some-mail-system, they should start with a letter.

The constrains, or specs, are quite contrived, but they can be fed to grampg simply:

from grampg import PasswordGenerator
passwords = (PasswordGenerator().of().between(5, 10, 'letters')
                                     .at_least(4, 'numbers')
return [passwords.generate() for i in xrange(so_many_passwords)]

Only one generator instance is created, and then used to produce as many passwords as are required.

Other character sets available by default are ‘lower_letters’, ‘upper_letters’, and ‘alphanumeric’, but the user is free to build generator instances with any character sets desired (as well as overriding the defaults). For example:

passwords = (PasswordGenerator({'special': list('%$#!*'), 'letters': list('abcde')})
                              .of().exactly(3, special).at_most(2, 'special').done())

For more examples, execute and read the program (which lives in grampg/demo), a simple program that spits passwords according to somewhat realistic specifications. There is also the file, which consists of many uses of the grampg and their expected output (both valid and not).


The grampg package includes the following files which purpose is to serve as test bed:

Unit test suite.

Integration tests.

Regression tests. Like integration, but actual examples that went awry and are now fixed.


The name sucks, I know. It’s meant as a silly joke to the person who inspired the code creation.


The grampg software package (including tests, documentation and demonstration programs) is licensed under the GNU Affero GPL version 3.0. A copy of the license is included with the grampg package. For details about the license, visit

Project details

Download files

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

Source Distribution

grampg-0.3.0.tar.gz (34.8 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page