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


Literal is a fun weekend project to create a way to generate python code with Python code. Instead of having string literals of Python code, you use objects that remembers the operations done to them, and the history of operations is the resulting Python program.

This is just an experiment that I wanted to play with; It’s usefulness is not proven, and more than likely this will be thrown away as a failed experiment. So use with care and caution.

Quick overview

import literal
def unpack_octet(x, payload, offset, unpack_from):
    x <<= unpack_from('B', payload, offset)
    offset += 1



x = unpack_from('B', payload, offset)
offset += 1

Or another example used to create argument unpackers for the AMQP protocol:

def unpack(method):
    def body(p, payload, offset, unpack_from, argtuple, ssize):
        fields = method.fields
        names = p.tuple(*self.field_names)

        for i, fset in enumerate(fields):
            if len(fset) == 1:
                for field in fset:
                    name = p.var(
                    if field.format == '*':
                        # This is a string payload,
                        # don't have to unpack
                        name <<= payload[offset:offset + ssize]
                        offset += ssize
                        # A single field to unpack
                        name <<= unpack_from(struct_format(field.format),
                                            payload, offset)[0]
                        offset += field.size
                # A list of field to unpack
                these = p.tuple(*fset.names)
                these <<= unpack_from(struct_format(fset.format),
                                    payload, offset)
                offset += sum(f.size for f in fset)
            return names

        return body().as_fun(lambda payload, offset: 1,

Would generate the following code for the AMQP method basic_deliver:

def deliver(payload, offset):
    ssize = unpack_from('B', payload, offset)[0]
    offset += 1
    consumer_tag = payload[offset:offset + ssize]
    offset += ssize
    delivery_tag, redelivered, ssize = unpack_from('QBB', payload, offset)
    offset += 10
    exchange = payload[offset:offset + ssize]
    offset += ssize
    ssize = unpack_from('B', payload, offset)[0]
    offset += 1
    routing_key = payload[offset:offset + ssize]
    offset += ssize
    return (consumer_tag, delivery_tag, redelivered,
            exchange, routing_key)

More documentation to come.


You can install literal either via the Python Package Index (PyPI) or from source.

To install using pip,:

$ pip install literal

To install using easy_install,:

$ easy_install literal

If you have downloaded a source tarball you can install it by doing the following,:

$ python build
# python install # as root

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to our issue tracker at


Development of happens at Github:

You are highly encouraged to participate in the development. If you don’t like Github (for some reason) you’re welcome to send regular patches.


This software is licensed under the New BSD License. See the LICENSE file in the top distribution directory for the full license text.

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
literal-1.0.0.tar.gz (11.7 kB) Copy SHA256 Checksum SHA256 Source Dec 5, 2011

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS 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