Simple admin web interface with CRUD operation for docker images. You can delete and view it. In example uses default crud templates from ps_crud module.

$ cd examples/docker_crud/
$ pip install -e .
$ pserve development.ini --reload

and goto http://localhost:6543/admin/


How it works

pyramid_sacrud copes with the resource technology, especially those who adhere to the principle of Pyramid traversal. In this example, we create resources, associate them with the own views, but inherit the templates from pyramid_sacrud and ps_crud. Also entry point for all resources from pyramid_sacrud settings is GroupResource.


When you pass the Docker in pyramid_sacrud settings, it automatically derives from GroupResource. Docker is a base resource and it not displayed in the Web interface, therefore it doesn’t require binding to the view.

Docker - base resource
class Docker(object):

    breadcrumb = True

    def __init__(self):
        self.cli = docker.Client(base_url='unix://var/run/docker.sock')

    def verbose_name(self):
        return self.__class__.__name__ + "'s"

    def __name__(self):
        return self.verbose_name

Image represent a list of all docker images in Web interface.

Image - represent docker image lists
class Image(Docker):

    def _get_id(self, row):
        return row['Id']

    def _columns(self):
        class Column:
            def __init__(self, name, value):
       = name
                self.value = value

            def value(self, row):
                return self.value(row)
        return (
            Column("id", lambda x: x["Id"][:10]),
                   lambda x: time.strftime("%D %H:%M",
            Column("tag", lambda x: x["RepoTags"][0])

    def __getitem__(self, name):

        if name == 'mass_action':
            return self.ps_crud["crud"]["mass_action"]
        elif name == 'update':
            return self.ps_crud["crud"]["update"]

    def ps_crud(self):
        mass_action = MassAction()
        mass_action.__parent__ = self
        update = UpdateFactory()
        update.__parent__ = self
        return {
            "get_id": self._get_id,
            "columns": self._columns,
            "crud": {
                "mass_action": mass_action,
                "update": update,

    def all(self):
        return self.cli.images()

It uses view:

View for Image resource
def admin_docker_list_view(context, request):
    """Show list of docker images."""
    return {
        'paginator': Page(
            url_maker=lambda p: request.path_url + "?page=%s" % p,
            page=int(request.params.get('page', 1)),

With template ps_crud/list.jinja2 from extension module ps_crud.

def admin_docker_list_view(context, request):
    """Show list of docker images."""

UpdateFactory designed to reflect a particular image.

UpdateFactory - choices image
class UpdateFactory(object):

    __name__ = "update"

    def __getitem__(self, name):
        return self.Update(name, self)

    def __call__(self, row):
        return self[row["Id"]]

    class Update(Docker):

        __name__ = None

        def get_image(self, img_id):
            for img in self.cli.images():
                if img['Id'] == img_id:
                    return img

        def __init__(self, name, parent):
            self.__name__ = name
            self.__parent__ = parent
            self.img = self.get_image(name)
            self.ps_crud = parent.__parent__.ps_crud
View for UpdateFactory resource
def admin_docker_update_view(context, request):
    from pprint import pformat
    return {'data': '<pre>' + pformat(context.img) + '</pre>'}


Added Docker logo to redefineme.jinja2 template
{% extends "sacrud/base.jinja2" %}

{% block menu_logo %}
  <img src="/static/docker.png" width="300px" />
{% endblock %}
Template for show image
{% extends "sacrud/redefineme.jinja2" %}

{% block title %} - {{ _(context.verbose_name) }}{% endblock %}

{% block body %}
  <div id="grid_view"></div>
  <h4>{{ _(context.verbose_name) }}</h4>

  <div class="bordered highlight hoverable z-depth-1">
    {{ data|safe }}
{% endblock %}
  Read the Docs
v: latest  
Free document hosting provided by Read the Docs.