Skip to main content


Project description

An API service that will give you back a configuration file from a template and variables.

The project is at a really early stage, but you can try it already.


Install diecutter from Github, configure it then run the server:

# Download and install (in a virtualenv if you like).
pip install -e
# Configure: adapt "YOUR_TEMPLATE_DIR"!
wget -O diecutter.ini --post-data "template_dir=YOUR_TEMPLATE_DIR"
# Run the server.
pserve diecutter.ini --reload

Check it works:

$ curl http://localhost:8106
{"diecutter": "Hello", "version": "0.1dev"}


Put your template in the service templates directory or use the API:

$ echo "Hello {{ who }}" | curl -X PUT http://localhost:8106/hello -F "file=@-"
{"diecutter": "Ok"}

Then we can get the raw template we just created:

$ curl http://localhost:8106/hello
Hello {{ who }}

And we can render the template against some variables:

$ curl -X POST http://localhost:8106/hello -d 'who=world'
Hello world


You can also get directories:

$ echo "circus.ini" | curl -X PUT http://localhost:8106/circus/circus.ini -F "file=@-"
{"diecutter": "Ok"}

$ echo "circus_django.ini" | curl -X PUT http://localhost:8106/circus/circus_django.ini -F "file=@-"
{"diecutter": "Ok"}

$ curl http://localhost:8106/circus

$ curl http://localhost:8106/circus/

If you want to render the directory against a global context:

$ curl -X POST http://localhost:8106/circus
/-- Get a ZIP archive with all the files listed below rendered against the context --/

$ mkdir -p ~/sandbox/
$ cd ~/sandbox/
$ curl -X POST http://localhost:8106/circus >
$ unzip
$ tree .
├── circus
│   ├── circus_django.ini
│   └── circus.ini

1 directory, 3 files

Posting input data

When you perform POST requests on resources, you provide a context, i.e. variables and values.

Diecutter has builtin support for the following input content-types:

Diecutter expects data to be provided as the body of the request. “multipart/form-data” requests aren’t supported currently.

Here are “flat” examples using curl.

# All examples below return the same result.

# Default (implicit application/x-www-form-urlencoded content type).
curl -X POST -d 'who=world' http://localhost:8106/hello

# Explicit "application/x-www-form-urlencoded" content-type.
curl -X POST -d 'who=world' -H "Content-Type: application/x-www-form-urlencoded" http://localhost:8106/hello

curl -X POST -d '{"who": "world"}' -H "Content-Type: application/json" http://localhost:8106/hello

# INI.
curl -X POST -d 'who=world' -H "Content-Type: text/plain" http://localhost:8106/hello


Pass content of a file using @ in curl’s -d option.

INI content-type allows you to provide 2 levels of data:

cat > input.ini <<EOF
hello = world
bar = baz
curl -X POST --data-binary '@input.ini' -H "Content-Type: text/plain" http://localhost:8106/hello
# Templates can use variables like {{ hello }} and {{ }}.

JSON allows you to provide multiple levels of data.

Render file names

Sometimes you want to define names from the context.

You just add to put +context_name+ it will match automatically:

 $ echo "[watcher:{{ watcher_name }}]" | curl -X PUT http://localhost:8106/circus/circus_+watcher_name+.ini -F "file=@-"
 {"diecutter": "Ok"}

 $ curl http://localhost:8106/circus

$ curl http://localhost:8106/circus -d 'watcher_name=diecutter' >
$ unzip -l
  Length      Date    Time    Name
---------  ---------- -----   ----
       10  2012-12-24 12:02   circus/circus.ini
       19  2012-12-24 12:02   circus/circus_diecutter.ini
       17  2012-12-24 12:02   circus/circus_django.ini
---------                     -------
       46                     3 files
$ cat circus/circus_diecutter.ini

A full example : the diecutter startproject

As an example, we added a +django_project+ template that you can use like this:

$ curl http://localhost:8106/+django_project+ -d 'django_project=diecutter_demo' >
$ unzip -l
  Length      Date    Time    Name
---------  ---------- -----   ----
      256  2012-12-24 12:08   diecutter_demo/
        0  2012-12-24 12:08   diecutter_demo/diecutter_demo/
     5239  2012-12-24 12:08   diecutter_demo/diecutter_demo/
      579  2012-12-24 12:08   diecutter_demo/diecutter_demo/
     1149  2012-12-24 12:08   diecutter_demo/diecutter_demo/
---------                     -------
     7223                     5 files

Project details

Download files

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

Files for diecutter, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size diecutter-0.2.tar.gz (9.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page