old blog,

repoze.bfg - Introduction and bootstrapping it on buildout

Izhar Firdaus Izhar Firdaus Follow Support May 08, 2010 · 3 mins read
repoze.bfg - Introduction and bootstrapping it on buildout
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.
2 months without a post here .. T_T ... must .. restart .. blogging ...

Anyway, I've been poking around with repoze.bfg since last week and growing to love it by the days. Been thinking to post a blog on getting started on it but was a bit lazy .. until I saw lowkster's post about bfg at planet.foss.org.my a few days ago.

Full documentation at http://docs.repoze.org/bfg

A little review

I love Zope Component Architecture because the modularity/reusability it offers, but Bluebream, Grok and Zope2 feels a bit big for simple web apps or for introducing ZCA to new people. Then I saw BFG.

BFG simplifies many concepts which I'm familiar with in Zope2/Zope3, and it does it without overwhelming developers with other parts of the framework. Not endorsing any type of storage backend, and giving an option between URL routing and traversal or a mix of both is a plus.

The initial base code is simple and straightforward, and there are no need to subclass any parent class when you want to create your initial project.

The starter project is as simple as:

models.py:
class MyModel(object):
pass

root = MyModel()

def get_root(request):
return root


views.py:
def my_view(request):
return {'project':'helloworld'}


A registration of the view in configure.zcml:
  <view
context=".models.MyModel"
view=".views.my_view"
renderer="templates/mytemplate.pt"
/>


And its template file which uses TAL compatible markup.

As the initial requirement is simple, and theres close to no enforcement on how developers supposed to write something on it, it made it easy for new people to quickly learn it and start being productive. BFG too, being something that uses many Zope concepts, can utilize many existing Zope/Z3C components out there, and if a developer know how to utilize ZCA well, what developed on a BFG project may also be componentized and reused in other frameworks.

What to know more on whats cool with BFG? .. read their Sales Pitch ;)

Installation on Buildout

Depending on your distribution, BFG might be available in your distro repository (Fedora have it). However, being a Zope/Plone developer as my main job, whenever it comes to installing python applications from pypi, I tend to prefer to use buildout to create a self-contained environment. So I'll use buildout here too.

First, if you don't have zc.buildout yet, install it using:
$ easy_install zc.buildout


Now lets create the contained environment
$ mkdir -p ~/repozebuildout/src
$ cd ~/repozebuildout


Then create a buildout.cfg file in the directory with this config:
[buildout]
parts =
repoze
develop =
src/*
versions = versions

[repoze]
recipe = zc.recipe.egg
eggs =
repoze.bfg
interpreter = python
entry-points = paster=paste.script.command:run

[versions]
repoze.bfg = 1.2.1



What the buildout config will do is, it will create a buildout with repoze.bfg framework and its dependencies installed, with an interpreter script configured for the buildout environment, and a paster script.

Now initialize the buildout
$ buildout init
$ ./bin/buildout -vv


After the buildout initialization is done, you may start creating the project skeleton.

Creating your first project

There are several templates to choose from: bfg_starter, bfg_routesalchemy, bfg_alchemy, and bfg_zodb.

bfg_starter template simply give a very basic bfg skeleton to get started. Those who are familiar with Pylons/Django might want to look at bfg_routesalchemy and those who are familiar with Zope might want to look at bfg_alchemy and bfg_zodb.

For this example, i'll just create a simple project using bfg_starter template.

cd src/
../bin/paster create -t bfg_starter helloworld
cd ..


then , edit buildout.cfg and add helloworld into the eggs section:

[buildout]
...
[repoze]
...
eggs =
...
helloworld
...


afterward, rerun buildout
./bin/buildout -vvv


Once that is done, you may start the server using:
./bin/paster serve src/helloworld/helloworld.ini


Now you can start developing on BFG!. Read the documentation to get you started in developing on BFG.

Happy hacking :D
Written by Izhar Firdaus Follow Support
I'm a system architect, data engineer and developer advocate with passion in Free / Open Source software, entrepreneurship, community building, education and martial art. I take enjoyment in bridging and bringing together different FOSS technologies to help businesses and organizations utilize IT infrastructure to aid and optimize their business and organizational process.

HOWTO: Linux Container (LXC) on Fedora 12

Those who are familiar with BSD Jails or Solaris Zones might be quite familiar to the concept of OS-level virtualization. The Linux w...

In old blog, Mar 03, 2010

« Previous Post

Using deliverance as WSGI pipeline to elegantly theme a repoze.bfg project

I was looking around for template inheritance solution for repoze.bfg, as it seems like by default, BFG does not have context view tr...

In old blog, May 08, 2010

Next Post »