Even tiny, single-use open source tools are worthy of our attention. If you have the need to programmatically configure your Nginx servers, look no further than nginxparser by Fatih Erikli.

Weighing in at less than 100 lines of code, nginxparser provides two features.

loading:

from nginxparser import load
load(open("/etc/nginx/sites-enabled/foo.conf"))

    [['server'], [
        ['listen', '80'],
        ['server_name', 'foo.com'],
        ['root', '/home/ubuntu/sites/foo/']]]]

and dumping:

from nginxparser import dumps
dumps([['server'], [
    ['listen', '80'],
    ['server_name', 'foo.com'],
    ['root', '/home/ubuntu/sites/foo/']]])

    'server {
        listen   80;
        server_name foo.com;
        root /home/ubuntu/sites/foo/;
    }'    

I was impressed with how simple it is to define a parser using Pyparsing, which nginxparser does to great effect.

It’s definitely worth checking out!


Have comments? Send a tweet to @TheChangelog on Twitter.

Subscribe to The Changelog Weekly – our weekly email covering everything that hits our open source radar.