Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Code Commit Push Publish engine.

Project Description

Code Commit Push Publish


pip install c2p2


pip install git+


Fork c2p2_template

The easiest way to start is to fork this template:

Templates API

The application looks for templates inside SOURCE_FOLDER, so we need to add them. Minimal list of files required is:

- site
    - engine
        - templates
            - 404.html
            - 500.html
            - index.html
            - page.html
            - label.html
            - sitemap.xml

index.html, page.html, label.html and sitemap.xml receives, beside tornado standart template context, variable c, that uses to access list of pages and labels, for example:

{{ }}
{{ }}
{{ }}
{{ c.label }}
{% for page in c.pages %}
{{ c.pages['<page_slug>'] }}
{{ c.pages.for_label('<label_slug>') }} is available only in page.html. It returns current page object.

Page object has next attributes:
  • uri
  • html
  • created
  • modified
  • title
  • meta
  • labels

page.meta returns PageMeta object, where all variables specified in the top of the page is available.

created: 2015-10-10T00:00
show_comments: true
labels: Label1
// page.html
{{ }} -> '2015-10-10T00:00'
{{ }} -> '2015-10-10T00:00'
{{ }} -> 'Label1'
{{'labels') }} -> 'Label1'
{{'labels') }} -> ['Label1', 'Label2']
{{ }} -> true
{{ }} -> None

page.labels returns list of Label objects connected to the page:

{% for label in %}{{ label.title }}{% end %}
Label object has next attributes:
  • title
  • slug

c.pages returns an iterable that allows to get all pages list. In label.html it return only pages belong to the label. You also can get any page by uri using c.pages.

{% for page in c.pages %}{{ page.title }}{% end %}

{{ c.pages['2010/09/blog-post'].html }}

{{ c.pages.for_label('default') }}

Running the server

To run the application use site/engine/

import os.path

from c2p2 import app
from c2p2.settings import settings

rel = lambda p: os.path.join(os.path.dirname(os.path.realpath(__file__)), p)

if __name__ == '__main__':
    settings.SOURCE_FOLDER = rel('..')


There are 4 ways to set settings:
  • default settings (see c2p2/
  • environment variables with C2P2_ prefix: export C2P2_PORT=5000
  • command line arguments ( --PORT=5000)
  • also you can change them directly settings.PORT = 5000 in site/engine/
Available settings:
  • DEBUG: Enable tornado debug mode
  • PORT: Port the app listening to
  • SOURCE_FOLDER: Path to folder that contains pages source
  • UPDATE_TIMEOUT: Number of seconds to rescan source folder. 0 - disable
  • GITHUB_VALIDATE_IP: Enable GitHub ip validation
  • GITHUB_SECRET: GitHub web hook secret, optional
  • GITHUB_BRANCH: GitHub branch to watch

Questions and Answers

Run on work station

cd site
virtualenv venv --no-site-packages -p /usr/local/bin/python3.5
source venv/bin/activate
pip install c2p2
python engine/

Open http://localhost:5000 in browser.

Update site if md file was changed without server restart


Update site on GitHub push

Create new GitHub hook for your repository:
  • url:
  • secret: should be equal to GITHUB_SECRET setting value

Production configuration

  • DEBUG=false
  • GITHUB_SECRET=<webhook secret>
  • GITHUB_BRANCH=master

Supervisor configuration:

command=/home/deploy/mysite/venv/bin/python engine/

Nginx configuration:

upstream mysite {

server {
    listen   80;

    # If you need to restrict access
    # auth_basic "Restricted";
    # auth_basic_user_file /etc/nginx/.htpasswd;


    location / {
        proxy_cache off;
        proxy_pass http://mysite;

    location ~* \.(?:css|png|jpe?g|gif|ico|zip|txt)$ {
        root /home/deploy/mysite;
        log_not_found off;

    error_page 500 502 503 504 /home/deploy/mysite/engine/templates/500.html;
    error_page 400 402 403 404 /home/deploy/mysite/engine/templates/400.html;

Favicon and robots.txt

Just add favicon.ico and robots.txt to root folder of your site.

Custom md directives

It is possible to register custom md directives:

from c2p2.utils import ExtensionsRegistry



python -m unittest c2p2.tests


If you want to contribute to this project, please perform the following steps:

# Fork this repository
$ virtualenv .env --no-site-packages -p /usr/local/bin/python3.5
$ source .env/bin/activate
$ python install
$ pip install -r requirements.txt

$ git branch feature_branch master
# Implement your feature and tests
$ git add . && git commit
$ git push -u origin feature_branch
# Send me a pull request for your feature branch

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(10.9 kB) Copy SHA256 Hash SHA256
Source None May 12, 2016

Supported By

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 Google Google Cloud Servers