Carp cuts down on typing by letting you store code templates (using jinja2) and then render them.

I named this project carp because this project will save me from CARP-al tunnel. Harharhar.

Isn’t this a bad idea?

Yes. Terrible idea. Good programmers use libraries and inheritance and dynamic code generation and run-time message passing to shrink redundancy.

Shitty programmers use copy-paste. And only the worst programmer imaginable would ever design and use a copy-paste framework.

This project is an abomination.

Hurry back to hacker news!


You can use easy_install:

$ easy_install carp

Or you can get the source from github here:

$ git clone
$ cd carp
$ python install


The first thing to do is make a directory named “carpdir” at the top of your project:

$ cd ~/src/my-awesome-project
$ mkdir carpdir

That’s where carp will store templates.

Now you can ask carp what templates are available. Since you haven’t stored any templates yet, you won’t get anything back though:

$ carp-list
no carpdir found!

$ mkdir carpdir

$ carp-list

Next, pick a file that you want to use as a template and copy it to some out-of-the-way place:

$ cp /tmp/

Now edit that copy and replace the text that you want to be passed in as a parameter, by using double-curly braces, like this:


Actually, you can use any jinja2 tricks, because the files will be run as jinja2 templates. For example, you can use a filter to make sure something comes out as lower case like this:

{{ project_name | lower }}

Once you have replaced the text that you want to use as parameters, add this template like this:

$ carp-add /tmp/

You can get a list of required variables to pass in:

$ carp-info required variables

*   project_name

That tells you that you have to pass in a project_name variable when you render the template.

And now you can render that template:

$ carp-render --define project_name=bogus

That will write a bunch of stuff to standard output, so use redirect to put it in a file:

$ carp-render --define project_name=bogus >

Templates made of folders

You can have single-file templates, but you can also store trees of folders and files as templates too.

Imagine you have a folder proj with a bunch of stuff inside and you want it to be a template:

$ find proj

You add folder templates just the same:

$ carp-add proj

And carp-info works the same:

$ carp-info proj
proj required variables

*  projname

But when you render a template that is a folder, you have to give me a folder to put it in, like this:

$ carp-render proj /tmp --define projname=scratch

Now you’ll see a folder /tmp/proj with all your stuff inside:

$ find /tmp/proj

Future plans

  • Include a few built-in templates when you install carp.
  • Add descriptions and other metadata to templates.
  • Support command-line tab completion for template names.

Boring stuff to do

  • Add a bootstrap + backbone.js template to the list of built-in templates.
  • Add a –version command-line option to all the scripts.
  • Pretty-up the error messaging when somebody forgets to define a variable during carp-render. Right now, it just blows up.
  • Move dependencies out from into requirements.txt, because that’s how the world is going, apparently.
  • Show docstrings from modules in docs.

Table Of Contents

This Page