How to package a generated library

Author: Dave Kuhlman
dkuhlman (at) davekuhlman (dot) org
date:October 18, 2014


This document explains how to use the library template to create a package enabling you to distribute a module generated with This package and the instructions below will help you to create the following:

The latest copy of these instructions is here:

and the template package itself is here:

These instructions assume the name "peach" as the name of the schema. You should replace "peach" in these instructions with the name of your schema.

Find out more about here:

You will need to install Sphinx in order to build the documentation in your package. Learn about Sphinx here:


In the instructions that follow, I'll assume that the name of your XML schema is "peach" and that the name of the module that you generate using will be "peachlib".

Follow these steps:

  1. Unroll the library template (, for example:

    $ unzip
  2. Rename the top-level directory created by the previous step, for example:

    $ mv librarytemplate-x.y peachlib-1.0a

    Or, on MS Windows:

    $ rename librarytemplate-x.y peachlib-1.0a

  3. Go to the new directory. For example:

    $ cd peachlib-1.0a
  4. Copy your generated modules into this directory. Suggested name is {schema_name} For example

  5. Run (which is in the top level directory). makes changes in the boiler plate provided by librarytemplate; it changes occurrences of "{{schema_name}}" to the name of your schema, which is entered on the command line. For example:

    $ python --help
    $ python --schema-name=peach
  6. Add some more content to the documentation. It is likely that you will want to make additions and changes in the following files:

    • README.txt
    • docs/intro.txt
    • sample_code/README.txt
  7. Generate the documentation. This step requires Sphinx.

    First, add the top-level directory of your distribution to your PYTHONPATH environment variable. Sphinx needs to be able to import your library module ( Then, go to the ./docs/ directory and build the HTML documentation:

    $ cd docs
    $ make clean
    $ make html

    You also can build other forms of documentation, e.g. LaTeX and PDF. See the Sphinx documentation, or type:

    $ make help

    By default, the generated documentation for the module includes lists of the member functions for each class. You can change this by removing the :members: and :undoc-members: options from the file docs/module_contents.txt, and then run:

    $ make clean
    $ make html


  8. Add some functionality and sample code. In particular:

    • Add some helper functions in
    • Add example applications in directory sample_code/. Suggestions: (1) Rename and add code to sample_code/example01.txt. (2) Generate a subclass module (using the "-s" command line option with, then add a bit of code to a few of the subclasses.
    • List and describe any example applications that you add in the file sample_code/README.txt.
  9. It might be a good idea to include the XML schema from which you generated your library module. You can copy the schema(s) to the schemas/ directory, and/or add a link in file schemas/README.txt that points to a location where it can be found.

  10. Create a distribution file. For example, use either:

    $ tar czf peachlib-1.0a.tar.gz peachlib-1.0a


    $ zip -r peachlib-1.0a

    In order to avoid including backup files and compiled Python modules, you might want to use something like the following:

    $ zip -r peachlib-1.0a -x \*~ -x \*.pyc

    See the man page on zip for more on the -x command line option. The backslash avoids the shell filename substitution. Adjust this command for your needs. For example, you may need to use "*.bak" instead of "*~".