skip to navigation
skip to content

pycapnp 0.4.0

A cython wrapping of the C++ Cap'n Proto library

Latest Version: 0.5.7

More thorough docs are available at


First you need a system-wide installation of the Cap’n Proto C++ library == 0.4.x. Follow the official installation docs or for the lazy:

curl -O
tar zxf capnproto-c++-0.4.0.tar.gz
cd capnproto-c++-0.4.0
make -j6 check
sudo make install

A recent version of cython and setuptools is also required. You can install these with:

pip install -U cython
pip install -U setuptools

Building and installation

Install with pip install pycapnp. You can set the CC environment variable to control which compiler is used, ie CC=gcc-4.8 pip install pycapnp.

Or you can clone the repo like so:

git clone
pip install ./pycapnp

Note: for OSX, if using clang from Xcode 5, you will need to set CFLAGS like so:

CFLAGS='-stdlib=libc++' pip install pycapnp


This project uses git-flow. Essentially, just make sure you do your changes in the develop branch. You can run the tests by installing pytest with pip install pytest, and then run py.test from the test directory.


There is some basic documentation here.

The examples directory has one example that shows off the capabilities quite nicely. Here it is, reproduced:

from __future__ import print_function
import os
import capnp

import addressbook_capnp

def writeAddressBook(file):
    addresses = addressbook_capnp.AddressBook.new_message()
    people = addresses.init('people', 2)

    alice = people[0] = 123 = 'Alice' = ''
    alicePhones = alice.init('phones', 1)
    alicePhones[0].number = "555-1212"
    alicePhones[0].type = 'mobile' = "MIT"

    bob = people[1] = 456 = 'Bob' = ''
    bobPhones = bob.init('phones', 2)
    bobPhones[0].number = "555-4567"
    bobPhones[0].type = 'home'
    bobPhones[1].number = "555-7654"
    bobPhones[1].type = 'work'
    bob.employment.unemployed = None


def printAddressBook(file):
    addresses =

    for person in addresses.people:
        print(, ':',
        for phone in person.phones:
            print(phone.type, ':', phone.number)

        which = person.employment.which()

        if which == 'unemployed':
        elif which == 'employer':
            print('employer:', person.employment.employer)
        elif which == 'school':
            print('student at:',
        elif which == 'selfEmployed':
            print('self employed')

if __name__ == '__main__':
    f = open('example', 'w')

    f = open('example', 'r')

Common Problems

If you get an error on installation like:

gcc-4.8: error: capnp/capnp.c: No such file or directory

gcc-4.8: fatal error: no input files

Then you have too old a version of setuptools. Run pip install -U setuptools then try again.

An error like:

capnp/capnp.cpp:312:10: fatal error: 'capnp/dynamic.h' file not found
#include "capnp/dynamic.h"

Means you haven’t installed the Cap’n Proto C++ library. Please follow the directions at the official installation docs

File Type Py Version Uploaded on Size
pycapnp-0.4.0.tar.gz (md5) Source 2013-12-12 274KB