Dario  Schaden

Dario Schaden


Ptah: A Open Source High-Level Python Web Development Environment


Ptah is a fast, fun, open source high-level Python web development environment. Ptah is built on top of the Pyramid web framework. Ptah's goal is to make developing interactive web sites and applications fun. Ptah aims to fill a void in the Pyramid eco-system, a "full stack" environment which is well integrated and provides opinions (forms, management ui, models, etc).

Ptah is loosely affiliated with the Pyramid, Django, Drupal and Zope/Plone communities.

Most documentation requires Ptah 0.3 or greater.

You can read the ptah documentation on-line at http://ptahproject.readthedocs.org.


  • Python 2.6+ or Python 3.2+
  • virtualenv

Note for Windows Users

On Windows virtualenv/bin will be virtualenv/Scripts besides this difference everything else below is the same.

Grab the release

If you do not want to faff about with source, cloning repos, etc. Just grab the latest released version of ptah.

$ /path/to/virtualenv/bin/pip install ptah

Ptah from source

If you want the latest and greatest you need to grab code from source.

clone ptah from github and then install it:

$ /path/to/virtualenv/bin/python setup.py develop

then run the tests:

$ /path/to/virtualenv/bin/python setup.py test

An empty project

Let's generate a empty project using the ptah_starter scaffolding. You can start from there:

/path/to/virtualenv $ bin/pcreate -t ptah_starter myapp
/path/to/virtualenv $ cd myapp
/path/to/virtualenv/myapp $ ../bin/python setup.py develop
/path/to/virtaulenv/myapp $ ../bin/pserve settings.ini --reload

Open your browser to http://localhost:6543/ if you want examples that do more such as demonstrating editing models and authentication. Check out the examples.


There are several example applications ready for you to install and see Ptah in action. You can find them in the examples repository at github.


Support and Documentation

Ptahproject google groups/mailing list, Ptahproject Google Groups

On irc, use the freenode network and find us on channels, #ptahproject and #pyramid.

Documentation can be found in docs directory. You can also see it online at http://ptahproject.readthedocs.org/

Report bugs at Ptahproject @ Github

Known Issues

On some versions of Ubuntu you may get Python 2.7 exiting stating it has "Aborted." There is a bug in ctypes on that particular Ubuntu platform.

Author: ptahproject
Source Code: https://github.com/ptahproject/ptah
License: View license

#python #pyramid 

Ptah: A Open Source High-Level Python Web Development Environment
Dario  Schaden

Dario Schaden


Pyramid Runner: Pyramid Scaffold to Create Web API


A minimal Pyramid scaffold that aims to provide a starter template to build small to large web services. To achieve this goal the following design decisions are made for you -

  1. Completely decoupled from client-side coding
  2. Use only JSON renderer
  3. Use only url traversal
  4. Focus on resource management

Following packages are included in the setup.py -

  1. Pyramid itself
  2. SQLAlchemy
  3. Alembic

Key Features

  • A predetermined project structure (See Project Structure).
  • Saves hours of google search and typing.
  • Open source and free.
  • IDE (i.o PyCharm) friendly.
  • One configuration file per environment(i.e development and production).
  • A simple Makefile to make life even easier(See the usage of the Makefile).
  • A built-in ModelBase for SQLAlchemy (See features of the ModelBase).
  • Uses CookieCutter project templating system.



After installing cookiecutter, run -

cookiecutter https://github.com/asif-mahmud/pyramid_runner.git


  • Create a Python virtual environtment first.
  • Clone the git repo.
  • Open a Terminal inside pyramid_runner.
  • Activate the virtual environtment by running source <your-venv-path>/bin/activate.
  • Run python setup.py install

Project Structure

  • # - Stands for Folder.
  • + - Stands for File.
  • All __init__.py are ignored.
  • All README.md's are ignored.
  • Learn more about the purpose of the folders in their README.md file.
 # project_name
 |-# database
 |-# project_name - Pyramid application code
 | |
 | |-# models
 | |-# views
 | |-# tests
 | |-# security
 | |-# resources - Includes all your resource classes including Root resource.
 |-# alembic
 | |
 | |-# versions
 | |-+ script.py.mako
 | |-+ env.py
 |-# wsgi - Will contain wsgi servers's log files and pid file.
 |-+ setup.py - Python distribution setup file.
 |-+ development.ini - Development environment config file.
 |-+ production.ini - Production environment config file.
 |-+ alembic.ini - Pyramid project friendly alembic config file.
 |-+ MANIFEST.in
 |-+ CHANGES.txt
 |-+ Makefile - Provides some useful shortcut commands.

Usage of Makefile

The Makefile inside the project folder provides some easy shortcut commands-

  • make setup : This command must be run once at the beginnng.
  • make revision: Make a database revision by Alembic.
  • make upgrade : Migrate your database to latest revision.
  • make downgrade : Migrate your database to a previous revision.
  • make run : Run pserve to serve local server. Additionally it will start watching SASS sources and angular apps.
  • make test : Run pytest to test the project.

Features of ModelBase

It is a default Model base for all of your SQLAlchemy Models. But you don't have to inherit it, instead you inherit the infamous Base class. It provides the following class level attributes -

  • id : An Integer Column as primary_key. Feel free to override it anytime.
  • created_on : A DateTime Column to provide when the entry was created. Defaults to current time.
  • updated_on : A DateTime Column to provide when the entry was updated. Always the last update time.
  • __tablename__ : You don't have to write __tablename__ whenever you create a Model
  • __json__ : Method to represent the model as JSON object.

Helper Classes


Root resource inherits this class. See the default resources.root.Root resource.


A helper base class for child nodes in the resource tree. __name__ and __parent__ attributes are handled in the __init__ method. So a container child need to implement child_instance and/or child_class (Updated in version 4.0.0) methods of it's own to generate it's requested child node. Decisions made here are -

  1. Parent/Container node is responsible to generate Child node.
  2. Parent/Container node is responsible to give the Child instance a name.


A helper class for view classes. What it does -

  1. Sets the request attribute in __init__ method.
  2. Adds a default empty view for OPTIONS HTTP requests.


(new in version 4.0.0) A subclass of dict to provide consistent response from different views. It includes the following keys-

  1. code : An integer code mostly representing HTTP response code. Dafaults 200.
  2. status: A string status like "OK" or "ERROR". Defaults "OK".
  3. msg: A string containing a message for the client. Defaults "".
  4. error: A string containing any error message to send to the client. Defaults "".

These keys can be accessed both as dictionary keys or class attributes.


(new in version 6.0.0) A subclass of BaseJSONResponse. This is helpful to quickly define a status(error or success) report standard for the API.


A base class to retreive authenticated user info from request params.

NOTE: Removed from version 3.9+


Base class for ticket based authentication policy.

NOTE: Removed from version 3.9+

Version History

Version 6.0.1

  • Added log_error method to BaseResource.

Version 6.0.0

  • Added BaseStatusReport and some subclasses of it. See views.errors package.
  • Updated project README.md to better reflect the setup procedure.
  • Fixed some stylings.

Version 5.9.0

  • BaseTest and BaseFunctionalTest is being merged into single BaseTest

Version 5.0.0

  • Little fixes.
  • Added a .gitignore file.

Version 4.9.0

  • Test base class now uses development.ini file to read the configurations. So tests will run with same configurations as the development versions.
  • Initializing database by inserting some test data is made easier by introducing init_db and clean_db methods in BaseTest class. Child classes will just implement these methods to insert test data into database by normal session.add or session.delete methods.

Version 4.0.0

  • More pythonic all the way. Improved import statements.
  • BaseView, BaseChild has more functionalities.

Version 3.9.0

  • Added pyramid_jwt for JWT authentication suitable for CORS.

Version 3.0.0

  • Using Gunicorn instead of waitress as development and production server.

Version 2.9.0

  • Added CORS headers on NewResponse event.

Version 2.0.0

  • Using cookiecutter project templating system.

Version 1.9.0

  • Added a basic stateless security system.

Version 1.0.0

  • ModelBase includes an abstract __json__(request) method.

Version 0.9.0

  • Working version with 3 utility classes -
    1. BaseRoot
    2. BaseChild
    3. BaseView
  • Added an example functional test for home_view.

Version 0.0.1

  • Git initialization.

Author: asif-mahmud
Source Code: https://github.com/asif-mahmud/pyramid_runner
License: GPL-2.0 license

#python #pyramid 

Pyramid Runner: Pyramid Scaffold to Create Web API
Dario  Schaden

Dario Schaden


Nive CMS: Out The Box, Content Management System

Welcome to Nive cms

Nive is professional out the box content management system for mobile and desktop websites based on python and the webframework pyramid. Please refer to the website cms.nive.co for detailed information.


The package will soon be released as stable 1.0 version. For a better package management the previous nive package has been split up into several smaller packages.

If you are updating from version 0.9.11 or older please read nive/update-0.9.11-to-1.0.txt. If you are updating from version 0.9.12 read changes.txt.

Source code

The source code is hosted on github: https://github.com/nive/nive_cms

Documentation and installation



Translations can be extracted using lingua>=3.2

> pip install lingua-3.2
> bin/pot-create -o nive_cms/locale/nive_cms.pot nive_cms

Third party modules

Some included modules have their own license:

  • bootstrap (nive_cms.design.static.bootstrap)
  • jquery / jquery-ui / jquery.form
  • iconset (nive_cms.cmsview.static.images) by Mark James http://www.famfamfam.com/

Author: nive
Source Code: https://github.com/nive/nive_cms
License: GPL-3.0 license

#python #pyramid 

Nive CMS: Out The Box, Content Management System
Dario  Schaden

Dario Schaden


Pyramid Extdirect: Pyramid Web Application Development Framework

pyramid_extdirect README


This pyramid plugin provides a router for the ExtDirect Sencha API included in ExtJS .

ExtDirect allows to run server-side callbacks directly through JavaScript without the extra AJAX boilerplate. The typical ExtDirect usage scenario goes like this:

MyApp.SomeClass.fooMethod(foo, bar, function(response) {
    // do cool things with response

or even better, if ExtDirect is used in a GridStore:

var usersStore = new Ext.data.Store({
    fields: ['id', 'name', 'title'],
    proxy: {
        type: 'direct',
        directFn: MyApp.Users.loadAll,
        reader: {
            type: 'json',
            rootProperty: 'items'
    // ...

Here MyApp is the application namespace, SomeClass or Grids are classes or actions and fooMethod and loadGridData are methods.

Usage example:

The minimum requirement for pyramid_extdirect is to create an ExtDirect API and Router:

from pyramid.config import Configurator
from exampleapp.resources import Root

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    config = Configurator(root_factory=Root, settings=settings)
    config.add_static_view('static', 'exampleapp:static')
    # let pyramid_extdirect create all the needed views automatically
    # scan your code once to make sure the @extdirect_method decorators
    # are picked up
    return config.make_wsgi_app()

After this you can decorate arbitrary functions or class methods using @extdirect_method:

def do_stuff(a, b, c):
    return a + b + c

Or, if you'd like to group your methods into classes (actions), you can do so by decoration class methods:

The UsersController class could combine all methods for users CRUD operations, the only requirement is that this class accepts request as its first and only constructor argument, this is needed to make sure your methods have access to request at any time:

from pyramid_extdirect import extdirect_method

class UsersController(object):

    __extdirect_settings__ = {
        'default_action_name': 'Users',
        'default_permission': 'view'

    def __init__(self, request):
        self.request = request

    # we don't need to set ``action`` here, because
    # it's already defined via __extdirect_settings__
    @extdirect_method(permission='view', method_name='loadAll')
    def load_all(self, params):
        # params is a simple dict that will contain the
        # paging and sorting options as well as any other
        # extra parameters (defined using proxy.extraParams
        # your store config)
        users = []
        for user in users_db.fetch_all():
                id: obj.id,
                name: obj.name,
                title: obj.title,
                # ...
        return dict(success=True, items=users)

As you can see, the Users#loadAll method doesn't even know it's been called through a HTTP request, it's just a plain old python method which returns a dict. The @extdirect_method(permission='view') decoration adds it to the Users action (also making sure only users with view permission are allowed to run it). We're returning a dict here simply because the AJAX response sent to the client has to be JSON serializable. By default python JSON marshallers can only encode/decode builtin python primitives. pyramid_extdirect has a small helper though, that checks if an object has a method called json_repr() (which should return a JSON serializable dict/list/string/number/etc.) and if found, this method is used to decode an instance to its JSONable version. You can define a __extdirect_settings__ property in a class to define a default action and permission, so in the example above we could also just use @extdirect_method().

Sometimes you need to use the upload features of ExtDirect. Since uploads cannot be done using AJAX (through JSON-encoded request body) Ext does a little trick by creating a hidden iframe and posting a form within this iframe to the server. However, ExtDirect needs to know in advance, that your code might receive uploads. In pyramid_extdirect decorators this is done by adding a accepts_files parameter to the @extdirect_method decorator:

class Users(object):
    def upload_avatar(self, uploaded_file):
        # uploaded_file is now a FieldStorage instance

In some situations it is absolutely necessary to access the request object in your functions and you don't want to create an extra class (where the request would be passed in to the class constructor) -- this can be achieved by passing request_as_last_param to the decorator:

from pyramid.security import authenticated_userid

@extdirect_method(action='App', request_as_last_param=True):
def get_current_user(request):
    return authenticated_userid(request)

-- Igor Stroh, <igor.stroh -at- rulim.de>

Author: jenner
Source Code: https://github.com/jenner/pyramid_extdirect
License: View license

#python #pyramid 

Pyramid Extdirect: Pyramid Web Application Development Framework
Dario  Schaden

Dario Schaden


Tomb Routes: Simple Utility Library Around Pyramid Routing



A set of simple defaults for Pyramid routing.

Pyramid's URL dispatch has separate concepts for routes and views. This gives additional flexibility in that you can one route map to multiple views, using different predicates (e.g.: predicates depending on Accept header, whether request is XHR or not, etc.). In many applications, this flexibility is not needed and having both routes and views adds a bit of complexity and duplication, and reduces DRYness. This module implements some easy-to-use mechanisms that create a route and a view in one step, resulting in simpler, easier to understand code. This kind of makes Pyramid's routing look a bit more like Flask, albeit without Flask's controversial thread locals.

You can use simple_route as a decorator:

from tomb_routes import simple_route
from pyramid.response import Response

def my_route(request, name):
    return Response('Hello %s' % name)

or you can use it from the configurator:

    '/hello/{name}', view_callable,


Frameworks with very simple routing (including so-called "microframeworks") are nothing new. Here are a few in the Python world:

Pyramid is a very powerful and extensible web framework and it's a framework that we love, but sometimes we want very simple routing. This package brings the simplified routing from microframeworks to Pyramid, so we can have our cake and eat it too.

Author: sontek
Source Code: https://github.com/sontek/tomb_routes

#python #pyramid 

Tomb Routes: Simple Utility Library Around Pyramid Routing
Dario  Schaden

Dario Schaden


Paginate: Python Pagination Module

What is pagination?

This module helps dividing large lists of items into pages. The user is shown one page at a time and can navigate to other pages. Imagine you are offering a company phonebook and let the user search the entries. If the search result contains 23 entries but you may want to display no more than 10 entries at once. The first page contains entries 1-10, the second 11-20 and the third 21-23. See the documentation of the "Page" class for more information.

How do I use this module?

The paginate module contains extensive in-line documentation with examples.

Concerning WebHelpers

This is a standalone module. Former versions were included in the WebHelpers Python module as webhelpers.paginate and were tightly coupled with the WebHelpers and the Pylons web framework. This version aims to be useful independent of any web framework.

Subclassing Page()

This module supports pagination through list-like objects. To paginate though other types of objects you can subclass the paginate.Page() class and provide a wrapper class that defines how to access elements of that special collection.

You can find examples in other paginate_* modules like paginate_sqlalchemy. Basically you would have to provide a class that implements the init, getitem and len methods.

It is trivial to make pagination for other datastores like Elasticsearch/Solr extending the base class.


class SqlalchemyOrmWrapper(object):
    """Wrapper class to access elements of a collection."""
    def __init__(self, obj):
        self.obj = obj

    def __getitem__(self, range):
        # Return a range of objects of an sqlalchemy.orm.query.Query object
        return self.obj[range]

    def __len__(self):
        # Count the number of objects in an sqlalchemy.orm.query.Query object
        return self.obj.count()

Then you can create your own Page class that uses the above wrapper class::

class SqlalchemyOrmPage(paginate.Page):
    """A pagination page that deals with SQLAlchemy ORM objects."""
    def __init__(self, *args, **kwargs):
        super(SqlalchemyOrmPage, self).__init__(*args, wrapper_class=SqlalchemyOrmWrapper, **kwargs)

As you can see it does not do much. It basically calls paginate.Page.init and adds wrapper_class=SqlalchemyOrmWrapper as an argument. The paginate.Page instance will use that wrapper class to access the elements.

Generating HTML code for current page


p = paginate.Page([], page=15, items_per_page=15, item_count=1010)
# item_count is optional, but we pass a dummy empty resultset for this example
pattern = '$link_first $link_previous ~4~ $link_next $link_last (Page $page our of $page_count - total $item_count)'
p.pager(pattern, url='http://foo.com?x=$page', dotdot_attr={'x':5}, link_attr={'y':6}, curpage_attr={'z':77})
# *_attr arguments are optional and can be used to attach additional classes/attrs to tags

Results in::

'<a class="L" href="URL?x=1">&lt;&lt;</a> <a class="L" href="URL?x=14">&lt;</a> <a class="L" href="URL?x=1">1</a> <span class="D">..</span> <a class="L" href="URL?x=11">11</a> <a class="L" href="URL?x=12">12</a> <a class="L" href="URL?x=13">13</a> <a class="L" href="URL?x=14">14</a> <span class="C">15</span> <a class="L" href="URL?x=16">16</a> <a class="L" href="URL?x=17">17</a> <a class="L" href="URL?x=18">18</a> <a class="L" href="URL?x=19">19</a> <span class="D">..</span> <a class="L" href="URL?x=68">68</a> <a class="L" href="URL?x=16">&gt;</a> <a class="L" href="URL?x=68">&gt;&gt;</a> (Page 15 our of 68 - total items 1010)'

Using url maker to generate links to specific result ranges

You can pass url_maker Callback to generate the URL of other pages, given its numbers. Must accept one int parameter and return a URI string.


def url_maker(page_number):
    return str('foo/%s' % page_number)
page = paginate.Page(range(100), page=1, url_maker=url_maker)
eq_(page.pager(), '1 <a href="foo/2">2</a> <a href="foo/3">3</a> .. <a href="foo/5">5</a>')

Alternatively if you will not pass the link builder function, the pager() method can also accept url argument that contains URL that page links will point to. Make sure it contains the string $page which will be replaced by the actual page number. Must be given unless a url_maker is specified to init, in which case this parameter is ignored.

Using link information for custom paginator templates

If you do not like the default HTML format produced by paginator you can use link_map() function to generate a dictionary of links you can use in your own template.


p.link_map('$link_first $link_previous ~4~ $link_next $link_last (Page $page our of $page_count - total items $item_count)',url='URL?x=$page',dotdot_attr={'class':'D'}, link_attr={'class':"L"}, curpage_attr={'class':"C"})

Returns something like::

{'current_page': {'attrs': {'class': 'C'}, 'href': 'URL?x=15', 'value': 15},
 'first_page': {'attrs': {'class': 'L'}, 'href': 'URL?x=1', 'type': 'first_page', 'value': 1},
 'last_page': {'attrs': {'class': 'L'}, 'href': 'URL?x=68', 'type': 'last_page', 'value': 68},
 'next_page': {'attrs': {'class': 'L'}, 'href': 'URL?x=16', 'type': 'next_page', 'value': 16},
 'previous_page': {'attrs': {'class': 'L'}, 'href': 'URL?x=14', 'type': 'previous_page', 'value': 14},
 'range_pages': [{'attrs': {'class': 'D'}, 'href': '', 'type': 'span', 'value': '..'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=11', 'type': 'page', 'value': '11'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=12', 'type': 'page', 'value': '12'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=13', 'type': 'page', 'value': '13'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=14', 'type': 'page', 'value': '14'},
  {'attrs': {'class': 'C'}, 'href': 'URL?x=15', 'type': 'current_page', 'value': 15},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=16', 'type': 'page', 'value': '16'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=17', 'type': 'page', 'value': '17'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=18', 'type': 'page', 'value': '18'},
  {'attrs': {'class': 'L'}, 'href': 'URL?x=19', 'type': 'page', 'value': '19'},
  {'attrs': {'class': 'D'}, 'href': '', 'type': 'span', 'value': '..'}],
  'radius': 4}

Using link_tag callable to generate custom link markup

In case you want to generate custom link markup for your project - for example for use with bootstrap, pager() accepts link_tag argument that expects a callable that can be used to easly override the way links are generated.


from paginate import Page, make_html_tag

def paginate_link_tag(item):
    Create an A-HREF tag that points to another page usable in paginate.
    a_tag = Page.default_link_tag(item)
    if item['type'] == 'current_page':
        return make_html_tag('li', a_tag, **{'class':'active'})
    return make_html_tag('li', a_tag)

symbol_first='<i class="fa fa-chevron-circle-left"></i>',
symbol_last='<i class="fa fa-chevron-circle-right"></i>',
symbol_previous='<i class="fa fa-chevron-left"></i>',
symbol_next='<i class="fa fa-chevron-right"></i>',

Author: Pylons
Source Code: https://github.com/Pylons/paginate
License: MIT license

#python #pyramid 

Paginate: Python Pagination Module
Dario  Schaden

Dario Schaden


Pyramid RPC: RPC Plugins for Pyramid

RPC Services for Pyramid

pyramid_rpc is a package of RPC related add-on's to make it easier to create RPC services.

from pyramid.config import Configurator
from pyramid_rpc.jsonrpc import jsonrpc_method

def say_hello(request, name):
    return 'hello, %s!' % name

def main(global_conf, **settings):
    config = Configurator(settings=settings)
    config.add_jsonrpc_endpoint('api', '/api')
    return config.make_wsgi_app()

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    app = main({})
    server = make_server('', 8080, app)

Support and Documentation

See the pyramid_rpc website to view documentation, report bugs, and obtain support.


pyramid_rpc is made available by Agendaless Consulting and a team of contributors.

Author: Pylons
Source Code: https://github.com/Pylons/pyramid_rpc
License: View license

#python #pyramid 

Pyramid RPC: RPC Plugins for Pyramid
Dario  Schaden

Dario Schaden


Helper to Create New Smgid and Translate Msgid To Local Langs

Pyramid I18N Helper

This is a helper for internationalization and localization in Pyramid


This package add 3 view to your pyramid based application:

  • i18n_helper.domain view in route /translate
  • i18n_helper.pot view in route /translate/{domain}
  • i18n_helper.po view in route /translate/{domain}/{lang}

in /translate you see available domains and also you can create new domain.

in /translate/{domain} you can edit pot file for selected domain.

in /translate/{domain}/{lang} you can translate msgid to selected lang in selected domain. also you can update po file from pot file.

additional object

This package add Babel locale object to request. This package use Pyramid_flash_message to handle flash messages.

collecting msgids

you can also use auto collect msgids. for this set i18n_helper.collect_msgid = true in your project config file. by enabling auto collect. new msgids for any domain add to its own pot file. even if pot file for specific is not available it will create automatically

translation directory

you can specify translation directory in config file via i18n_helper.locale_dir


pip install pyramid_i18n_helper

add then add this package to your application

pyramid.includes =



now user with i18n_helper permission can access this pages.


You can use project issue page to submit your issue

Khown Issues

  • After translating a msgid you have to restart your application
  • At now this package use pyramid_layout default layout. form pyramid_layout documentation page main_template is the template object that provides the main template (aka, o-wrap) for the view. if your application don't have main_layout some default main_template will be used but it is so simple and you may have problem. at now templates will be load in block named content.
  • main_layout template have to designed via jinja2.
  • excuse me for my bad english knowledge.

Author: sahama
Source Code: https://github.com/sahama/pyramid_i18n_helper

#python #pyramid #i18n 

Helper to Create New Smgid and Translate Msgid To Local Langs
Dario  Schaden

Dario Schaden


Lingua: Translation Toolkit For Python

What is lingua?

Lingua is a package with tools to extract translatable texts from your code, and to check existing translations. It replaces the use of the xgettext command from gettext, or pybabel from Babel.

Message extraction

The simplest way to extract all translatable messages is to point the pot-create tool at the root of your source tree.

$ pot-create src

This will create a messages.pot file containing all found messages.

Specifying input files

There are three ways to tell lingua which files you want it to scan:

Specify filenames directly on the command line. For example:

$ pot-create main.py utils.py

Specify a directory on the command line. Lingua will recursively scan that directory for all files it knows how to handle.

$ pot-create src

Use the --files-from parameter to point to a file with a list of files to scan. Lines starting with # and empty lines will be ignored.

$ pot-create --files-from=POTFILES.in

You can also use the --directory=PATH parameter to add the given path to the list of directories to check for files. This may sound confusing, but can be useful. For example this command will look for main.py and utils.py in the current directory, and if they are not found there in the ../src directory:

$ pot-create --directory=../src main.py utils.py


In its default configuration lingua will use its python extractor for .py files, its XML extractor for .pt and .zpt files and its ZCML extractor for .zcml files. If you use different extensions you setup a configuration file which tells lingua how to process files. This file uses a simple ini-style format.

There are two types of configuration that can be set in the configuration file: which extractor to use for a file extension, and the configuration for a single extractor.

File extensions are configured in the extensions section. Each entry in this section maps a file extension to an extractor name. For example to tell lingua to use its XML extractor for files with a .html extension you can use this configuration:

.html = xml

To find out which extractors are available use the -list-extractors option.

$ bin/pot-create --list-extractors
chameleon         Chameleon templates (defaults to Python expressions)
python            Python sources
xml               Chameleon templates (defaults to Python expressions)
zcml              Zope Configuration Markup Language (ZCML)
zope              Zope templates (defaults to TALES expressions)

A section named extractor:<name> can be used to configure a specific extractor. For example to tell the XML extractor that the default language used for expressions is TALES instead of Python:

default-engine = tales

Either place a global configuration file named .config/lingua to your home folder or use the --config option to point lingua to your configuration file.

$ pot-create -c lingua.cfg src

Domain filtering

When working with large systems you may use multiple translation domains in a single source tree. Lingua can support that by filtering messages by domain when scanning sources. To enable domain filtering use the -d option:

$ pot-create -d mydomain src

Lingua will always include messages for which it can not determine the domain. For example, take this Python code:

print(gettext(u'Hello, World'))
print(dgettext('mydomain', u'Bye bye'))

The first hello-message does not specify its domain and will always be included. The second line uses dgettext to explicitly specify the domain. Lingua will use this information when filtering domains.

Including comments

You can add comments to messages to help translators, for example to explain how a text is used, or provide hints on how it should be translated. For chameleon templates this can be done using the i18n:comment attribute:

<label i18n:comment="This is a form label" i18n:translate="">Password</label>

Comments are inherited, so you can put them on a parent element as well.

<form i18n:comment="This is used in the password reset form">
  <label i18n:translate="">Password</label>
  <button i18n:translate="">Change</button>

For Python code you can tell lingua to include comments by using the --add-comments option. This will make Linua include all comments on the line(s) immediately preceeding (there may be no empty line in between) a translation call.

# This text should address the user directly.
return _('Thank you for using our service.')

Alternatively you can also put a comment at the end of the line starting your translation function call.

return _('Thank you for using our service.')  # Address the user directly

If you do not want all comments to be included but only specific ones you can add a keyword to the --add-comments option, for example --add-comments=I18N.

# I18N This text should address the user directly, and use formal addressing.
return _('Thank you for using our service')

Setting message flags in comments

Messages can have flags. These are to indicate what format a message has, and are typically used by validation tools to check if a translation does not break variable references or template syntax. Lingua does a reasonable job to detect strings using C and Python formatting, but sometimes you may need to set flags yourself. This can be done with a [flag, flag] marker in a comment.

# I18N [markdown,c-format]
header =  _(u'# Hello *%s*')

Specifying keywords

When looking for messages a lingua parser uses a default list of keywords to identify translation calls. You can add extra keywords via the --keyword option. If you have your own mygettext function which takes a string to translate as its first parameter you can use this:

$ pot-create --keyword=mygettext

If your function takes more parameters you will need to tell lingua about them. This can be done in several ways:

  • If the translatable text is not the first parameter you can specify the parameter number with <keyword>:<parameter number>. For example if you use i18n_log(level, msg) the keyword specifier would be i18n_log:2
  • If you support plurals you can specify the parameter used for the plural message by specifying the parameter number for both the singular and plural text. For example if your function signature is show_result(single, plural) the keyword specifier is show_result:1,2
  • If you use message contexts you can specify the parameter used for the context by adding a c to the parameter number. For example the keyword specifier for pgettext is pgettext:1c,2.
  • If your function takes the domain as a parameter you can specify which parameter is used for the domain by adding a d to the parameter number. For example the keyword specifier for dgettext is dgettext:1d,2. This is a lingua-specified extension.
  • You can specify the exact number of parameters a function call must have using the t postfix. For example if a function must have four parameters to be a valid call, the specifier could be myfunc:1,4t.


Lingua includes a number of extractors:

  • python: handles Python source code.
  • chameleon: handles Chameleon files, using the Zope i18n syntax
  • zcml: handles Zope Configuration Markup Language (ZCML) files.
  • xml: old name for the chameleon extractor. This name should not be used anymore and is only supported for backwards compatibility.

Babel extractors

There are several packages with plugins for Babel's message extraction tool. Lingua can use those plugins as well. The plugin names will be prefixed with babel- to distinguish them from lingua extractors.

For example, if you have the PyBabel-json package installed you can instruct lingua to use it for .json files by adding this to your configuration file:

.json = babel-json

Some Babel plugins require you to specify comment tags. This can be set with the comment-tags option.

comment-tags = TRANSLATOR:

Comparison to other tools

Differences compared to GNU gettext:

  • Support for file formats such as Zope Page Templates (popular in Pyramid, Chameleon, Plone and Zope).
  • Better support for detecting format strings used in Python.
  • No direct support for C, C++, Perl, and many other languages. Lingua focuses on languages commonly used in Python projects, although support for other languages can be added via plugins.

Differences compared to Babel:

  • More reliable detection of Python format strings.
  • Lingua includes plural support.
  • Support for only extracting texts for a given translation domain. This is often useful for extensible software where you use multiple translation domains in a single application.

Validating translations

Lingua includes a simple polint tool which performs a few basic checks on PO files. Currently implemented tests are:

  • duplicated message ids (can also be checked with GNU gettext's msgfmt). These should never happen and are usually a result of a bug in the message extraction logic.
  • identical translations used for multiple canonical texts. This can happen for valid reasons, for example when the original text is not spelled consistently.

To check a po file simply run polint with the po file as argument:

$ polint nl.po

    ${val} ist keine Zeichenkette
Used for 2 canonical texts:
1       ${val} is not a string
2       "${val}" is not a string

Writing custom extractors

First we need to create the custom extractor:

from lingua.extractors import Extractor
from lingua.extractors import Message

class MyExtractor(Extractor):
    '''One-line description for --list-extractors'''
    extensions = ['.txt']

    def __call__(self, filename, options):
        return [Message(None, 'msgid', None, [], u'', u'', (filename, 1))]

Hooking up extractors to lingua is done by lingua.extractors entry points in setup.py:

      my_extractor = mypackage.extractor:MyExtractor

Note - the registered extractor must be a class derived from the Extractor base class.

After installing mypackage lingua will automatically detect the new custom extractor.

Helper Script

There exists a helper shell script for managing translations of packages in docs/examples named i18n.sh. Copy it to package root where you want to work on translations, edit the configuration params inside the script and use:

./i18n.sh lang

for initial catalog creation and:


for updating translation and compiling the catalog.

zope: a variant of the chameleon extractor, which assumes the default

expression language is TALES instead of Python.

Author: wichert
Source Code: https://github.com/wichert/lingua
License: View license

#python #pyramid 

Lingua: Translation Toolkit For Python
Dario  Schaden

Dario Schaden


Kajiki: Python XML-Based Template Engine with Genshi-Like Syntax

Kajiki provides fast well-formed XML templates

Because Kajiki's input is XML, it can ensure that your HTML/XML output is well-formed. The Genshi-like syntax, based on XML attributes or tags, is simply beautiful and easily understood (or ignored) by web designers. But instead of the slow performance of Genshi, Kajiki compiles templates to Python code that renders with blazing-fast speed, so Kajiki can compete with the speed of Jinja, Mako, Chameleon and others. Also, one of Genshi's misfeatures -- py:match -- is replaced with blocks which work like Jinja's blocks.

By combining the best ideas out there -- XML input, Genshi's syntax and features, Jinja's template inheritance and final compilation to Python --, Kajiki is ready to become the most widely used templating engine for web development in Python. And more features are coming soon; stay tuned!


>>> import kajiki
>>> Template = kajiki.XMLTemplate('''<html>
...     <head><title>$title</title></head>
...     <body>
...         <h1>$title</h1>
...         <ul>
...             <li py:for="x in range(repetitions)">$title</li>
...         </ul>
...     </body>
... </html>''')
>>> print(Template(dict(title='Kajiki is teh awesome!', repetitions=3)).render())
    <head><title>Kajiki is teh awesome!</title></head>
        <h1>Kajiki is teh awesome!</h1>
            <li>Kajiki is teh awesome!</li><li>Kajiki is teh awesome!</li><li>Kajiki is teh awesome!</li>

Author: jackrosenthal
Source Code: https://github.com/jackrosenthal/kajiki
License: View license

#python #pyramid 

Kajiki: Python XML-Based Template Engine with Genshi-Like Syntax
Dario  Schaden

Dario Schaden


Tonnikala: Python Templating Engine


Tonnikala is the latest reincarnation among the Python templating languages that feed on Kid-inspired XML syntax. It rejects the Kid and Genshi notions of tagstreams and trees, and follows in footsteps of Chameleon and Kajiki in making the template to compile into Python bytecode directly. The syntax is very close to that of Kajiki, but the internals are very different: Tonnikala writes code as Abstract Syntax Trees and optimizes the resulting trees extensively. In addition, there is an optional speed-up module (currently Python 3 only), that provides a specialized class used for output buffering.


from tonnikala.loader import Loader

template_source = u"""
    <tr py:for="row in table">
        <py:for each="key, value in row.items()"

template = Loader().load_string(template_source)

ctx = {
    'table': [dict(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10)
        for x in range(1000)]


Template inheritance


<title><py:block name="title_block">I am ${title}</py:block></title>
<py:def function="foo()">I can be overridden too!</py:def>


<py:extends href="base.tk">
<py:block name="title_block">But I am ${title} instead</py:block>
<py:def function="foo()">I have overridden the function in parent template</py:def>

Template imports


<py:def function="foo()">I am an importable function</py:def>


<py:import href="importable.tk" alias="imp" />


To load templates from files, use the tonnikala.FileLoader class:

loader = FileLoader(paths=['/path/to/templates'])
template = loader.load('child.tk')

A FileLoader currently implicitly caches all loaded templates in memory.


To render the template:

result = template.render(ctx)

You can specify a block, or no-argument def to render explicitly:

result = template.render(ctx, funcname='title_block')

Pyramid integration

Include 'tonnikala.pyramid' into your config to enable Tonnikala. When included, tonnikala adds the following configuration directives:


Registers tonnikala renderer for these template extensions. By default Tonnikala is not registered as a renderer for any extension. For example: config.add_tonnikala_extensions('.html', '.tk') would enable Tonnikala renderer for templates with either of these extensions.


Adds the given paths to the end of Tonnikala search paths that are searched for templates. These can be absolute paths, or package.module:directory/subdirectory-style asset specs. By default no search path is set (though of course you can use an asset spec for template).


If True, makes Tonnikala not cache templates. Default is False.


If True, makes Tonnikala skip some optimizations that make debugging harder.

These 3 can also be controlled by tonnikala.extensions, tonnikala.search_paths and tonnikala.reload respectively in the deployment settings (the .ini files). If tonnikala.reload is not set, Tonnikala shall follow the pyramid.reload_templatea setting.


Beta, working features are

  • Structural elements py:if, py:unless, py:def, py:for, py:replace, py:content
  • Basic template inheritance: py:extends and py:block; the child template also inherits top level function declarations from the parent template, and the child can override global functions that the parent defines and uses.
  • Expression interpolation using $simple_identifier and ${complex + python + "expression"}
  • Boolean attributes: <tag attr="${False}">, <tag attr="$True">
  • Implicit escaping
  • Disabling implicit escaping (literal())
  • C speedups for both Python 2 and Python 3
  • Importing def blocks from another template: py:import
  • Basic I18N using gettext.
  • Pyramid integration
  • Javascript as the target language (using js: prefix)
  • Overriding attributes, setting attrs from dictionary: py:attrs
  • Understandable exceptions and readable tracebacks on CPython

Upcoming features:

  • Structural elements: py:vars, py:switch, py:case; py:else for for, if and switch.
  • Custom tags mapping to py:def
  • I18N with optional in-parse-tree localization (partially done)
  • Pluggable frontend syntax engines (partially done)
  • METAL-like macros
  • Pluggable expression languages akin to Chameleon
  • Even better template inheritance
  • Better documentation

Author: ztane
Source Code: https://github.com/ztane/Tonnikala
License: Apache-2.0 license

#python #pyramid 

Tonnikala: Python Templating Engine
Dario  Schaden

Dario Schaden


Pyramid Excel: Let You Focus on Data, Instead Of File formats

Support the project

If your company has embedded pyexcel and its components into a revenue generating product, please support me on github, patreon or bounty source to maintain the project and develop it further.

If you are an individual, you are welcome to support me too and for however long you feel like. As my backer, you will receive early access to pyexcel related contents.

And your issues will get prioritized if you would like to become my patreon as pyexcel pro user.

With your financial support, I will be able to invest a little bit more time in coding, documentation and writing interesting posts.

Known constraints

Fonts, colors and charts are not supported.


Here is a typical conversation between the developer and the user:

User: "I have uploaded an excel file"
      "but your application says un-supported file format"
Developer: "Did you upload an xlsx file or a csv file?"
User: "Well, I am not sure. I saved the data using "
      "Microsoft Excel. Surely, it must be in an excel format."
Developer: "OK. Here is the thing. I were not told to support"
           "all available excel formats in day 1. Live with it"
           "or delay the project x number of days."

pyramid-excel is based on pyexcel and makes it easy to consume/produce information stored in excel files over HTTP protocol as well as on file system. This library can turn the excel data into a list of lists, a list of records(dictionaries), dictionaries of lists. And vice versa. Hence it lets you focus on data in Pyramid based web development, instead of file formats.

The idea originated from the common usability problem: when an excel file driven web application is delivered for non-developer users (ie: team assistant, human resource administrator etc). The fact is that not everyone knows (or cares) about the differences between various excel formats: csv, xls, xlsx are all the same to them. Instead of training those users about file formats, this library helps web developers to handle most of the excel file formats by providing a common programming interface. To add a specific excel file format type to you application, all you need is to install an extra pyexcel plugin. Hence no code changes to your application and no issues with excel file formats any more. Looking at the community, this library and its associated ones try to become a small and easy to install alternative to Pandas.

The highlighted features are:

  1. excel data import into and export from databases
  2. turn uploaded excel file directly into Python data structure
  3. pass Python data structures as an excel file download
  4. provide data persistence as an excel file in server side
  5. supports csv, tsv, csvz, tsvz by default and other formats are supported via the following plugins:

A list of file formats supported by external plugins

Package nameSupported file formatsDependencies
pyexcel-iocsv, csvz [1], tsv, tsvz [2] 
pyexcel-xlsxls, xlsx(read only), xlsm(read only)xlrd, xlwt
pyexcel-ods3odspyexcel-ezodf, lxml

Dedicated file reader and writers

Package nameSupported file formatsDependencies
pyexcel-xlsxwxlsx(write only)XlsxWriter
pyexcel-libxlsxwxlsx(write only)libxlsxwriter
pyexcel-xlsxrxlsx(read only)lxml
pyexcel-xlsbrxlsb(read only)pyxlsb
pyexcel-odsrread only for ods, fodslxml
pyexcel-odswwrite only for odsloxun
pyexcel-htmlrhtml(read only)lxml,html5lib
pyexcel-pdfrpdf(read only)camelot

Plugin shopping guide

Since 2020, all pyexcel-io plugins have dropped the support for python version lower than 3.6. If you want to use any python verions, please use pyexcel-io and its plugins version lower than 0.6.0.

Except csv files, xls, xlsx and ods files are a zip of a folder containing a lot of xml files

The dedicated readers for excel files can stream read

In order to manage the list of plugins installed, you need to use pip to add or remove a plugin. When you use virtualenv, you can have different plugins per virtual environment. In the situation where you have multiple plugins that does the same thing in your environment, you need to tell pyexcel which plugin to use per function call. For example, pyexcel-ods and pyexcel-odsr, and you want to get_array to use pyexcel-odsr. You need to append get_array(..., library='pyexcel-odsr').

Other data renderers

Package nameSupported file formatsDependenciesPython versions
pyexcel-textwrite only:rst, mediawiki, html, latex, grid, pipe, orgtbl, plain simple read only: ndjson r/w: jsontabulate2.6, 2.7, 3.3, 3.4 3.5, 3.6, pypy
pyexcel-handsontablehandsontable in htmlhandsontablesame as above
pyexcel-pygalsvg chartpygal2.7, 3.3, 3.4, 3.5 3.6, pypy
pyexcel-sortablesortable table in htmlcsvtotablesame as above
pyexcel-ganttgantt chart in htmlfrappe-ganttexcept pypy, same as above


[1]zipped csv file
[2]zipped tsv file

This library makes information processing involving various excel files as easy as processing array, dictionary when processing file upload/download, data import into and export from SQL databases, information analysis and persistence. It uses pyexcel and its plugins:

  1. to provide one uniform programming interface to handle csv, tsv, xls, xlsx, xlsm and ods formats.
  2. to provide one-stop utility to import the data in uploaded file into a database and to export tables in a database as excel files for file download.
  3. to provide the same interface for information persistence at server side: saving a uploaded excel file to and loading a saved excel file from file system.

Tested Pyramid Versions

So far pyexcel-xls plugin does not work with Python 3.9


You can install pyramid-excel via pip:

$ pip install pyramid-excel

or clone it and install it:

$ git clone https://github.com/pyexcel-webwares/pyramid-excel.git
$ cd pyramid-excel
$ python setup.py install


Once the pyramid_excel is installed, you must use the config.include mechanism to include it into your Pyramid project's configuration:

config = Configurator(.....)

Alternately, you may activate the extension by changing your application's .ini file by adding it to the pyramid.includes list:

pyramid.includes = pyramid_excel

Development guide

Development steps for code changes

  1. git clone https://github.com/pyexcel/pyramid-excel.git
  2. cd pyramid-excel

Upgrade your setup tools and pip. They are needed for development and testing only:

  1. pip install --upgrade setuptools pip

Then install relevant development requirements:

  1. pip install -r rnd_requirements.txt # if such a file exists
  2. pip install -r requirements.txt
  3. pip install -r tests/requirements.txt

Once you have finished your changes, please provide test case(s), relevant documentation and update CHANGELOG.rst.


As to rnd_requirements.txt, usually, it is created when a dependent library is not released. Once the dependecy is installed (will be released), the future version of the dependency in the requirements.txt will be valid.

How to test your contribution

Although nose and doctest are both used in code testing, it is adviable that unit tests are put in tests. doctest is incorporated only to make sure the code examples in documentation remain valid across different development releases.

On Linux/Unix systems, please launch your tests like this:

$ make

On Windows systems, please issue this command:

> test.bat

Before you commit

Please run:

$ make format

so as to beautify your code otherwise travis-ci may fail your unit test.

Author: pyexcel-webwares
Source Code: https://github.com/pyexcel-webwares/pyramid-excel
License: View license

#python #pyramid #excel 

Pyramid Excel: Let You Focus on Data, Instead Of File formats
Dario  Schaden

Dario Schaden


Easily Use MongoDB for Persistence with The Pyramid Web Framework


pyramid_mongodb is a simple Paster template or scaffold for the Pyramid Web Framework. It provides URL mapping via traversal and persistence via MongoDB. It is based on the "starter" template included in Pyramid core, and Mike Orr's "Akhet" template.


Latest stable releases can be found at http://pypi.python.org/pypi/pyramid_mongodb

You can install from Pypi using easy_install or pip:

easy_install pyramid_mongodb

or alternatively:

pip install pyramid_mongodb


Once pyramid_mongodb is installed, you should see it in the list of available templates when you run

pcreate -l
$ pcreate -l
Available scaffolds:
  alchemy:          Pyramid SQLAlchemy project using url dispatch
  pyramid_mongodb:  pyramid MongoDB project
  starter:          Pyramid starter project
  zodb:             Pyramid ZODB project using traversal

You can create a project with MongoDB support by running pcreate -s pyramid_mongodb <name of project>.

Author: niallo
Source Code: https://github.com/niallo/pyramid_mongodb
License: MIT license

#python #pyramid #mongodb 

Easily Use MongoDB for Persistence with The Pyramid Web Framework
Dario  Schaden

Dario Schaden


Pyramid Mongoengine: Mongoengine Pyramid Extension

Pyramid Mongoengine

pyramid-mongoengine package based in flask-mongoengine

README In Progress


pip install pyramid-mongoengine


Basic setup

if __name__ == "__main__":
    config = Configurator()


pyramid-mongoengine provides add_connection_database(), he makes a connection with database using data coming from .ini file.

mongo_url = mongodb://my_ip_location_to_mongodb
mongodb_name = "my_db_application"

If theses data not exists in .ini, pyramid-mongoengine use default values

# Default values
mongo_url = mongodb://localhost
mongodb_name = "test"

Creating models

from pyramid_mongoengine import MongoEngine

db = MongoEngine()

class User(db.Document):
    email = db.StringField(required=True)
    username = db.StringField(required=True)

See demo application to examples

Support on Beerpay

Hey dude! Help me out for a couple of!

Author: marioidival
Source Code: https://github.com/marioidival/pyramid_mongoengine
License: MIT license

#python #pyramid 

Pyramid Mongoengine: Mongoengine Pyramid Extension
Dario  Schaden

Dario Schaden


Pyramid SQLAlchemy: SQLAlchemy Integration for Pyramid

pyramid_sqlalchemy provides some basic glue to facilitate using SQLAlchemy with Pyramid.

SQLAlchemy relies on global state for a few things:

  • A MetaData instance which tracks all known SQL tables.
  • A base class for all models using the ORM.
  • A session factory.

Every application using SQLAlchemy must provides its own instance of these. This makes it hard create add-on packages that also use SQLAlchemy, since they either need to have their own SQLAlchemy state, which makes it hard to integrate them into your application, or they need to jump through multiple complex hoops to allow them share state with your application.

pyramid_sqlalchemy helps by providing a canonical location for the global SQLAlchemy state. In addition it provides a convenient way to configure SQLAlchemy in a Pyramid application.
from pyramid.config import Configurator
from pyramid_sqlalchemy import BaseObject

class MyModel(BaseObject):
    __tablename__ = 'my_model'

def main():
    config = Configurator()
    # Configure SQLAlchemy using settings from the .ini file
    return config.make_wsgi_app()

Author: wichert
Source Code: https://github.com/wichert/pyramid_sqlalchemy
License: View license

#python #pyramid #sqlalchemy 

Pyramid SQLAlchemy: SQLAlchemy Integration for Pyramid