Git repository:

cfget is a simple yet featureful tool to read values from configuration files. It is useful, for example, to create configurable shellscripts or makefiles.

Besides retrieving values, it can dump the information in several convenient ways, like a set of sh exports commands that can be conveniently passed to eval. It can also use the configuration values to expand template files.

It can also be configured to support virtual configuration values that, if not present in the config file, are automatically computed from the existing values. This makes it convenient, for example, to get a "duration" value from a configuration file that only contains a "start date" and an "end date".

It is also easy to create plugins to provide custom templating systems, export styles, dynamic values and even custom configuration file parsers. If you have a system made by various shellscripts that need to use the same configuration, or if some of those shellscripts use sed to replace values inside a template file, then cfget can make your life easier.


Released cfget 0.18

I have released version 0.18 of cfget.


  • Allow empty comment lines
  • Added Cfget.load_from_env to allow to easily load a working Cfget object from other python code
  • Fixed some exception handling and error reporting during parsing of expressions
Posted Fri 04 Feb 2011 17:58:09 CET Tags: sw/cfget

Released cfget 0.17

I have released version 0.17 of cfget.


  • Fixed a DeprecationWarning with python 2.6
  • Allow empty values in configuration files
  • The round() function now returns an int, not a float
Posted Thu 26 Aug 2010 00:00:00 CEST Tags: sw/cfget

Released cfget 0.16

I have released version 0.16 of cfget.

It is just a little bugfix release as I found a bug in the new expression parser, and while I was at it I simplified its code quite a bit.

Posted Fri 16 Jul 2010 11:00:41 CEST Tags: sw/cfget

Released cfget 0.15

I have released version 0.15 of cfget.

cfget is a tool to extract values from ini-style config files. A trivial thing, really.

It is also simple to install: it is a single python executable and it has no dependencies besides the python standard library.

It is trivial and simple, but because of the complex requirements (and sponsorship) of ISAC - CNR it has recently accumulated quite a set of features, and it manages to get a remarkable lot of things done.

There are several news since 0.8, worth a rather major announcement:

Added --dump=pickle

Now all the contents of the configuration files, plus all the contents generated by cfget plugins, can be dumped in pickle format.

This provides a quick and dirty way to load all cfget-generated data into a python dict:

data = pickle.loads(
        ["cfget", "--dump=pickle"],

It sounds like a rather complicated way to read a configuration file, but if you have various plugins that compute nontrivial derived configuration values, that quick&dirty hack could be quite useful.

Curly brace expansion

Suppose that you have a config file like this:

mode = show

command = display

command = gimp

And you want to get the command from the section indicated by general/mode.

Now you can, very easily: cfget '{general/mode}/command'

When it notices curly braces, cfget will literally replace them with the result of querying their contents, then parse the expression again.

Simple expression support

ISAC - CNR are using cfget to configure the run of a rather complicated physical model, and use plugins to derive all sorts of values form the base configuration.

This works, but there are times when adding a function to a plugin sounds like overkill: for example, sometimes one needs foo/bar + 1, or just the hour of a timestamp.

For those simple cases, I've added support for simple expressions:

  • operators: +, -, *, /, **
  • grouping with parentesis
  • function calls (int(), round()), with the possibility to define new functions via plugins.

So to compute a middle point one can now do this:

cfget "round((pos/start + pos/end) / 2)"

It needs a space around arithmetic operators to avoid conflicts with characters used to refer to configuration values, but with the space the expressions look nicer, so the result is that it generally does the right thing.

Just as a scary thought, curly braces work with and in expressions:

cfget "values/val{round((pos/end - pos/start) / 2)} + 1"

Although if someone ends up having a hairy thing like that, it is worth considering to replace it with a dynamic value computed using a plugin.

Posted Thu 15 Jul 2010 20:21:18 CEST Tags: sw/cfget

Released cfget 0.8

I have released version 0.8 of cfget.

I worked on 3 things:

  • A big cleanup with the excuse of uploading to Debian
  • --root=path to limit queries and dumps to all keys under a given path
  • when used in template mode with an output file name, it will write it atomically.
Posted Thu 29 Oct 2009 15:13:29 CET Tags: sw/cfget

Released cfget 0.7

I have released version 0.7 of cfget.

It adds support for custom configuration file parsers, and some commented example plugins.

Posted Wed 28 Oct 2009 22:57:04 CET Tags: sw/cfget

Released cfget 0.6

I have released version 0.6 of cfget.

This is the first public release.

Posted Wed 28 Oct 2009 13:25:31 CET Tags: sw/cfget

Development of cfget is sponsored by the BOLCHEM project.