Monthly Archives: September 2012

rrdtool-py3k: Python 3 bindings for rrdtool

As I started to port some code from Python 2 to Python 3 I had a problem that probably thousands of developers may have: A third-party library they require is not ported to Python 3 yet.

To support the community I’ve ported the Python bindings for rrdtool to use with Python 3. Its based on the original binding and should work almost the same as the old one, but got some improvements:

  • Updated documentation contents (__doc__) of each of the functions
  • The graph function can now return the actual image from function rather requiring to write it to a file. This is possible because the rrdtool program has the ability to specify “-” as the output file which will print the image bytes to stdout. The binding stores the data written to stdout and returns it along with the graph geometry as a bytes object.
  • An object-oriented interface was added. While the C extension can be imported withimport rrdtool, you can import the object-oriented interface with import RRDtool. The interface offers a class that can work with RRD files and execute all the rrdtool functions directly on arbitrary instances. Again, the graph method of the RRD class supports writing the output into files or to a BytesIO object.

The library is not well tested and considered being buggy. I’d like to encourage everyone interested into it to test it and submit bugs to the issue tracker on the Github project page.

Pre-compiled Windows binaries

The binaries are built with rrdtool 1.4.7 and MSVC 10.0. Please note that the output redirection mentioned in the feature list above is not available under Windows yet. Additionally, the flushcached function will have no effect, since I wasn’t able to compile the libraries when using that function from rrdlib. Use the appropriate architecture and Python version listed in the list below.

Django and Python 3

Many people use the Django Web Framework for turning their Web Project ideas into production websites. I did that myself a while ago, because it not only saves a lot of time – but I also like it because I can write the backend directly in Python code. Django is getting more and more attention and it has a large user base.

People which are new to Python have to decide first whether they want to use Python 2.x or 3.x for their projects. While on the one hand its better to go straight with 3.x because its actively developed and offers a lot of cool new features, many people are forced to use 2.x as many important Libraries have not been ported to Python 3.x yet on the other. This includes Django as well as the Twisted networking Library. All these projects have one in common: They are maintained for several years now and they have got a large user base. Turning 2.x code into code that runs on 3.x is a long term process which may take several months to years for projects of that size. Porting the code is definitely required: Python 2.x is not developed anymore. Python 2.7  is the latest release of the 2.x branch and is only updated with bug fixes and security patches. That’s why some Linux distributions, such as Ubuntu, have decided to port all their tools to use Python 3 in the future.

However, Django is on a good way. The upcoming 1.5 release will support experimental Python 3 support using the six compability layer. The other day I cloned the development code of Django on Github and tried it to run with Python 3.2.3, which worked like a charm. I have not tested everything yet, but at least it feels to be faster. The Django development team encourages everyone to test whether their Django projects work with a latest version of Django’s development snapshot and help to fix issues that are found by doing so.

I would recommend to start using the development snapshot along with Python 3 for new (large-scale) projects, because it will save you a lot of time if you have to port the code later.

The final release of Django 1.5 is scheduled for 24th of December 2012 (or even a few days before). Its release schedule was posted today in the django-developers mailing list.

Useful resources: