This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

repoze.monty is a library that, given a WSGI environment dictionary (and a wsgi.input file pointer if the request is a POST request), will return a dictionary back containing “converted” form/query string elements. The form and query string elements contained in the request are converted into simple Python types when the form element names are decorated with special suffixes. For example, in an HTML form that you’d like monty to convert a form element for, you might say:

<form action=".">
   Age : <input type="hidden" name="age:int" value="20"/>
   <input type="submit" name="Submit"/>

Likewise, in the query string of the URL, you could put:

In both of these cases, when provided the WSGI environment and the wsgi.input file pointer, and asked to return a value, monty might return a dictionary like so:


repoze.monty is a generalized version of the form marshalling machinery originated in Zope 2.

Form/Query String Element Marshalling

repoze.monty provides a way for you to specify form input types in the form, rather than in your application code. Instead of converting the age variable to an integer in a controller or vierw, you can indicate that it is an integer in the form itself:

Age <input type="text" name="age:int" />

The ‘:int’ appended to the form input name tells repoze.monty to convert the form input to an integer when it is invoked. This process is called marshalling. If the user of your form types something that cannot be converted to an integer in the above case (such as “22 going on 23”) then Zope will raise a ValueError.

Here is a list of repoze.monty’s basic parameter converters.


Converts a variable to true or false. Variables that are 0, None, an empty string, or an empty sequence are false, all others are true.


Converts a variable to an integer.


Converts a variable to a long integer.


Converts a variable to a floating point number.


Converts a variable to a string. Most variables are strings already so this converter is seldom used.


Converts a variable to a string with normalized line breaks. Different browsers on various platforms encode line endings differently, so this script makes sure the line endings are consistent, regardless of how they were encoded by the browser.


Converts a variable to a Python list.


Converts a variable to a Python tuple.


Converts a string to a list by breaking it on white spaces.


Converts a string to a list by breaking it on new lines.


Raises an exception if the variable is not present.


Excludes the variable from the request if the variable is an empty string.

These converters all work in more or less the same way to coerce a form variable, which is a string, into another specific type.

The list and tuple converters can be used in combination with other converters. This allows you to apply additional converters to each element of the list or tuple. Consider this form:

<form action=".">

  <p>I like the following numbers</p>

  <input type="checkbox" name="favorite_numbers:list:int"
  value="1" /> One<br />

  <input type="checkbox" name="favorite_numbers:list:int"
  value="2" />Two<br />

  <input type="checkbox" name="favorite_numbers:list:int"
  value="3" />Three<br />

  <input type="checkbox" name="favorite_numbers:list:int"
  value="4" />Four<br />

  <input type="checkbox" name="favorite_numbers:list:int"
  value="5" />5<br />

  <input type="submit" />

By using the list and date converters together, repoze.monty will convert each selected time to a date and then combine all selected dates into a list named favorite_numbers.

A more complex type of form conversion is to convert a series of inputs into records. Records are structures that have attributes. Using records, you can combine a number of form inputs into one variable with attributes. The available record converters are:


Converts a variable to a record attribute.


Converts a variable to a record attribute in a list of records.


Provides a default value for a record attribute if the variable is empty.


Skips a record attribute if the variable is empty.

Here are some examples of how these converters are used:

<form action=".">

  First Name <input type="text" name="person.fname:record" /><br />
  Last Name <input type="text" name="person.lname:record" /><br />
  Age <input type="text" name="person.age:record:int" /><br />

  <input type="submit" />

If the information represented by this form post is passed to repoze.monty, the result dictionary will container one parameter, person. The person variable will have the attributes fname, lname and age. Here’s an example of how you might use repoze.monty to process the form post (assuming you have a WSGI environment in hand):

from repoze.monty import marshal

info = marshal(environ, environ['wsgi.input'])
person = info['person']
full_name = "%s %s" % (person.fname, person.lname)
if person.age < 21:
    return ("Sorry, %s. You are not old enough to adopt an "
            "aardvark." % full_name)
return "Thanks, %s. Your aardvark is on its way." % full_name

The records converter works like the record converter except that it produces a list of records, rather than just one. Here is an example form:

<form action=".">

  <p>Please, enter information about one or more of your next of

    First Name <input type="text" name="people.fname:records" />
    Last Name <input type="text" name="people.lname:records" />

    First Name <input type="text" name="people.fname:records" />
    Last Name <input type="text" name="people.lname:records" />

    First Name <input type="text" name="people.fname:records" />
    Last Name <input type="text" name="people.lname:records" />

  <input type="submit" />

If you call repoze.monty’s marshal method with the information from this form post, a dictionary will be returned from it with a variable called people that is a list of records. Each record will have fname and lname attributes. Note the difference between the records converter and the list:record converter: the former would create a list of records, whereas the latter would produce a single record whose attributes fname and lname would each be a list of values.

The order of combined modifiers does not matter; for example, int:list is identical to list:int.


The file pointer passed to repoze.monty’s marshal method will be consumed. For all intents and purposes this means you should make a tempfile copy of the wsgi.input file pointer before calling marshal if you intend to use the POST file input data in your application.

Reporting Bugs / Development Versions

Visit to report bugs. Visit to download development or tagged versions.


Initial release.
Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
repoze.monty-0.1.tar.gz (17.3 kB) Copy SHA256 Checksum SHA256 Source Jul 30, 2008

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting